#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, char *);
int main(int argc, char *argv[]) {
  int i = -1;
  char c = 'c';
  printf("input a num:");
  scanf("%d%c", &i, &c);
  if (c != '\n') {
    printf("error\n");
    return 0;
  }
  switch (i) {
  case 1:
    printf("hello\n");
    break;
  case 2:
    printf("good job\n");
    break;
  case 3:
    printf("byebye\n");
    break;
  default:
    printf("error\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movb   $0x63,-0x15(%rbp)
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x15(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     1186 <main+0x66>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1202 <main+0xe2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     11bc <main+0x9c>
jmp    119a <main+0x7a>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11cd <main+0xad>
jmp    11ab <main+0x8b>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     11de <main+0xbe>
jmp    11ef <main+0xcf>
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xdb>
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xdb>
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xdb>
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
movb   $0x63,0x3(%rsp)
lea    0xebb(%rip),%rdi
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x3(%rsp),%rdx
call   1050 <scanf@plt>
lea    0xec1(%rip),%rdi
cmpb   $0xa,0x3(%rsp)
jne    118a <main+0x5a>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x2,%eax
ja     118a <main+0x5a>
cltq
lea    0xead(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"input a num:\00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [7 x i8] c"error\0A\00"
@.str.3 = [7 x i8] c"hello\0A\00"
@.str.4 = [10 x i8] c"good job\0A\00"
@.str.5 = [8 x i8] c"byebye\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i8 99, i8* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %7)
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %26
15: ; preds = %2
%16 = load i32, i32* %6
switch i32 %16, label %23 [
i32 1, label %17
i32 2, label %19
i32 3, label %21
]
17: ; preds = %15
%18 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %25
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %25
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %25
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21, %19, %17
store i32 0, i32* %3
br label %26
26: ; preds = %25, %13
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"input a num:\00"
@.str.1 = [5 x i8] c"%d%c\00"
@str = [7 x i8] c"byebye\00"
@str.6 = [9 x i8] c"good job\00"
@str.7 = [6 x i8] c"hello\00"
@str.9 = [6 x i8] c"error\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @str.7 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @str.6 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @str to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
store i8 99, i8* %4
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %4)
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, 10
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* %3
%12 = add i32 %11, -1
%13 = icmp ult i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = sext i32 %12 to i64
%16 = shl i64 %15, 2
%17 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %16)
br label %18
18: ; preds = %10, %14, %2
%19 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0), %2 ], [ %17, %14 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0), %10 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
ret i32 0
}