#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 main(void) {
  int a;
  int b;
  char op;
  int result;
  printf("a: ");
  scanf("%d", &a);
  printf("op: ");
  scanf("%*c%c", &op);
  printf("b: ");
  scanf("%d", &b);
  switch (op) {
  case '+':
    result = a + b;
    break;
  case '-':
    result = a - b;
    break;
  case '*':
    result = a * b;
    break;
  case '/':
    if (b == 0) {
      printf("Error: Division by zero.\n");
      return -2;
    }
    result = a / b;
    break;
  default:
    printf("Error: op( = %c) is invalid.\n", op);
    return -1;
  }
  printf("result = %d\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xed2(%rip),%rdi
mov    %rdi,-0x30(%rbp)
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xeb4(%rip),%rdi
lea    -0xd(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x21(%rbp),%al
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     1220 <main+0x100>
mov    -0x20(%rbp),%rax
lea    0xe47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    123e <main+0x11e>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    123e <main+0x11e>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    123e <main+0x11e>
cmpl   $0x0,-0xc(%rbp)
jne    1211 <main+0xf1>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1256 <main+0x136>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x14(%rbp)
jmp    123e <main+0x11e>
movsbl -0xd(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <main+0x136>
mov    -0x14(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xedc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed2(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xea9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%esi
lea    -0x2a(%rsi),%eax
cmp    $0x5,%eax
ja     11c9 <main+0x99>
lea    0xe55(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%esi
imul   0xc(%rsp),%esi
jmp    11f9 <main+0xc9>
mov    0x8(%rsp),%esi
add    0xc(%rsp),%esi
jmp    11f9 <main+0xc9>
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1209 <main+0xd9>
mov    0xc(%rsp),%esi
sub    0x8(%rsp),%esi
jmp    11f9 <main+0xc9>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
je     1211 <main+0xe1>
mov    0xc(%rsp),%eax
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe4c(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    1209 <main+0xd9>

LLVM IR (-O0):
@.str = [4 x i8] c"a: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"op: \00"
@.str.3 = [6 x i8] c"%*c%c\00"
@.str.4 = [4 x i8] c"b: \00"
@.str.5 = [26 x i8] c"Error: Division by zero.\0A\00"
@.str.6 = [30 x i8] c"Error: op( = %c) is invalid.\0A\00"
@.str.7 = [13 x i8] c"result = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
switch i32 %13, label %35 [
i32 43, label %14
i32 45, label %18
i32 42, label %22
i32 47, label %26
]
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = add nsw i32 %15, %16
store i32 %17, i32* %5
br label %39
18: ; preds = %0
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = sub nsw i32 %19, %20
store i32 %21, i32* %5
br label %39
22: ; preds = %0
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = mul nsw i32 %23, %24
store i32 %25, i32* %5
br label %39
26: ; preds = %0
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 -2, i32* %1
br label %42
31: ; preds = %26
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = sdiv i32 %32, %33
store i32 %34, i32* %5
br label %39
35: ; preds = %0
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %37)
store i32 -1, i32* %1
br label %42
39: ; preds = %31, %22, %18, %14
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %40)
store i32 0, i32* %1
br label %42
42: ; preds = %39, %35, %29
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"a: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [5 x i8] c"op: \00"
@.str.3 = [6 x i8] c"%*c%c\00"
@.str.4 = [4 x i8] c"b: \00"
@.str.6 = [30 x i8] c"Error: op( = %c) is invalid.\0A\00"
@.str.7 = [13 x i8] c"result = %d\0A\00"
@str = [25 x i8] c"Error: Division by zero.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
switch i32 %13, label %34 [
i32 43, label %14
i32 45, label %18
i32 42, label %22
i32 47, label %26
]
14: ; preds = %0
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %15
br label %36
18: ; preds = %0
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = sub nsw i32 %19, %20
br label %36
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, %23
br label %36
26: ; preds = %0
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %39
31: ; preds = %26
%32 = load i32, i32* %1
%33 = sdiv i32 %32, %27
br label %36
34: ; preds = %0
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %13)
br label %39
36: ; preds = %31, %22, %18, %14
%37 = phi i32 [ %33, %31 ], [ %25, %22 ], [ %21, %18 ], [ %17, %14 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %34, %29
%40 = phi i32 [ -1, %34 ], [ -2, %29 ], [ 0, %36 ]
ret i32 %40
}