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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0xd(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x2b,%eax
je     11c1 <main+0xa1>
movsbl -0xd(%rbp),%eax
cmp    $0x2d,%eax
je     11c1 <main+0xa1>
movsbl -0xd(%rbp),%eax
cmp    $0x2a,%eax
je     11c1 <main+0xa1>
movsbl -0xd(%rbp),%eax
cmp    $0x2f,%eax
je     11c1 <main+0xa1>
movsbl -0xd(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <main+0x170>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2e(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x2f,%eax
jne    1212 <main+0xf2>
cmpl   $0x0,-0xc(%rbp)
jne    1212 <main+0xf2>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1290 <main+0x170>
movsbl -0xd(%rbp),%eax
cmp    $0x2b,%eax
jne    122d <main+0x10d>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1278 <main+0x158>
movsbl -0xd(%rbp),%eax
cmp    $0x2d,%eax
jne    1248 <main+0x128>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1273 <main+0x153>
movsbl -0xd(%rbp),%eax
cmp    $0x2a,%eax
jne    1264 <main+0x144>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    126e <main+0x14e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x14(%rbp)
jmp    1273 <main+0x153>
jmp    1278 <main+0x158>
mov    -0x14(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0x2f,%rax
ja     11e8 <main+0xb8>
movabs $0xac0000000000,%rcx
bt     %rax,%rcx
jae    11e8 <main+0xb8>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5d(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x7(%rsp),%al
mov    0xc(%rsp),%esi
cmp    $0x2f,%al
jne    11d6 <main+0xa6>
test   %esi,%esi
jne    11d6 <main+0xa6>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    1228 <main+0xf8>
cmp    $0x2a,%al
je     1200 <main+0xd0>
cmp    $0x2d,%al
je     1207 <main+0xd7>
cmp    $0x2b,%al
jne    120f <main+0xdf>
add    0x8(%rsp),%esi
jmp    1218 <main+0xe8>
movsbl %al,%esi
lea    0xe34(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1228 <main+0xf8>
imul   0x8(%rsp),%esi
jmp    1218 <main+0xe8>
mov    0x8(%rsp),%eax
sub    %esi,%eax
jmp    1216 <main+0xe6>
mov    0x8(%rsp),%eax
cltd
idiv   %esi
mov    %eax,%esi
lea    0xe29(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"a: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"op('+', '-', '*', '/'): \00"
@.str.3 = [6 x i8] c"%*c%c\00"
@.str.4 = [30 x i8] c"Error: op( = %c) is invalid.\0A\00"
@.str.5 = [4 x i8] c"b: \00"
@.str.6 = [26 x i8] c"Error: Division by zero.\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 ([25 x i8], [25 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 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 43
br i1 %12, label %13, label %29
13: ; preds = %0
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 45
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 42
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 47
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %27)
store i32 -1, i32* %1
br label %73
29: ; preds = %21, %17, %13, %0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* %3
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 -2, i32* %1
br label %73
40: ; preds = %35, %29
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 43
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = add nsw i32 %45, %46
store i32 %47, i32* %5
br label %70
48: ; preds = %40
%49 = load i8, i8* %4
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 45
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* %2
%54 = load i32, i32* %3
%55 = sub nsw i32 %53, %54
store i32 %55, i32* %5
br label %69
56: ; preds = %48
%57 = load i8, i8* %4
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 42
br i1 %59, label %60, label %64
60: ; preds = %56
%61 = load i32, i32* %2
%62 = load i32, i32* %3
%63 = mul nsw i32 %61, %62
store i32 %63, i32* %5
br label %68
64: ; preds = %56
%65 = load i32, i32* %2
%66 = load i32, i32* %3
%67 = sdiv i32 %65, %66
store i32 %67, i32* %5
br label %68
68: ; preds = %64, %60
br label %69
69: ; preds = %68, %52
br label %70
70: ; preds = %69, %44
%71 = load i32, i32* %5
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %71)
store i32 0, i32* %1
br label %73
73: ; preds = %70, %38, %25
%74 = load i32, i32* %1
ret i32 %74
}

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