I was observing assembly generated for an equal program in Rust and C in the Compiler Explorer, in "binary" mode to look at the whole linked executable, not just compiler generated assembly for specific functions.
Rust program (on Godbolt)
pub fn square(num: i32) -> i32 {
num * num
}
fn main () {
let n = 4;
let _x = square(n);
}
C program (on Godbolt)
int square(int num) {
return num * num;
}
int main() {
int n = 4;
int x = square(n);
}
But the disassembly generated for these two are very different. I can partially understand the assembly generated for the C program, that is much shorter and more understandable for me. But I can't understand anything from assembly generated for Rust program.
So my question is why there is so much difference in length of these assembly programs? Am I using compiler explorer in a wrong way?