Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created April 4, 2019 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Silva97/5420e75a3539e90c55612961a75b5444 to your computer and use it in GitHub Desktop.
Save Silva97/5420e75a3539e90c55612961a75b5444 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
int x, y;
scanf("%d", &x);
switch(x){
case 1: y = 7; break;
case 2: y = 1; break;
case 3: y = 3; break;
default: y = 0;
}
printf("y = %d\n", y);
if(x == 1){
y = 7;
} else if(x == 2){
y = 1;
} else if(x == 3){
y = 3;
} else {
y = 0;
}
printf("y = %d\n", y);
return 0;
}
// gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
/* gcc tst.c -O2 -o tst.s -S
.file "tst.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d"
.LC1:
.string "y = %d\n"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
leaq .LC0(%rip), %rdi
xorl %eax, %eax
leaq 12(%rsp), %rsi
call __isoc99_scanf@PLT
movl 12(%rsp), %eax
xorl %esi, %esi
subl $1, %eax
cmpl $2, %eax
ja .L2
leaq CSWTCH.2(%rip), %rdx
movl (%rdx,%rax,4), %esi
.L2:
leaq .LC1(%rip), %rdi
xorl %eax, %eax
call printf@PLT
movl 12(%rsp), %esi
cmpl $1, %esi
je .L5
cmpl $2, %esi
je .L6
cmpl $3, %esi
movl $0, %eax
cmovne %eax, %esi
.L3:
leaq .LC1(%rip), %rdi
xorl %eax, %eax
call printf@PLT
xorl %eax, %eax
addq $24, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.L5:
.cfi_restore_state
movl $7, %esi
jmp .L3
.L6:
movl $1, %esi
jmp .L3
.cfi_endproc
.LFE11:
.size main, .-main
.section .rodata
.align 8
.type CSWTCH.2, @object
.size CSWTCH.2, 12
CSWTCH.2:
.long 7
.long 1
.long 3
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",@progbits
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment