Skip to content

Instantly share code, notes, and snippets.

@travisby
Created April 17, 2014 22:24
Show Gist options
  • Save travisby/11014943 to your computer and use it in GitHub Desktop.
Save travisby/11014943 to your computer and use it in GitHub Desktop.
switch vs. if statement
[~]$ pr -m -t test1.c test2.c
int main() { int main() {
int x; int x;
if (x == 0) { switch (x) {
// case 0:
} else if (x == 1) { break;
// case 1:
} break;
return 0; }
} }
[~]$ gcc test1.c -O0 -S && gcc test2.c -O0 -S
[~]$ pr -m -t test1.s test2.s
.file "test1.c" .file "test2.c"
.text .text
.globl main .globl main
.type main, @function .type main, @function
main: main:
.LFB0: .LFB0:
.cfi_startproc .cfi_startproc
pushq %rbp pushq %rbp
.cfi_def_cfa_offset 16 .cfi_def_cfa_offset 16
.cfi_offset 6, -16 .cfi_offset 6, -16
movq %rsp, %rbp movq %rsp, %rbp
.cfi_def_cfa_register 6 .cfi_def_cfa_register 6
leaq -4144(%rsp), %rsp leaq -4144(%rsp), %rsp
orq $0, (%rsp) orq $0, (%rsp)
leaq 4128(%rsp), %rsp leaq 4128(%rsp), %rsp
movq %fs:40, %rax movq %fs:40, %rax
movq %rax, -8(%rbp) movq %rax, -8(%rbp)
xorl %eax, %eax xorl %eax, %eax
movl $0, %eax movl -12(%rbp), %eax
movq -8(%rbp), %rdx testl %eax, %eax
xorq %fs:40, %rdx je .L7
je .L3 cmpl $1, %eax
call __stack_chk_fail@PL jmp .L6
.L3: .L7:
leave nop
.cfi_def_cfa 7, 8 .L6:
ret movq -8(%rbp), %rdx
.cfi_endproc xorq %fs:40, %rdx
.LFE0: je .L5
.size main, .-main call __stack_chk_fail@PL
.ident "GCC: (Funtoo Harde .L5:
.section .note.GNU-s leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Funtoo Harde
.section .note.GNU-s
[~]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment