#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 *);
scalar_t__ strcmp(char *, char *);
int main() {
  int a, b, c, r;
  char op[3];
  printf("Calculator\n\n");
  scanf("%d %s %d", &a, op, &b);
  if (strcmp(op, "add") == 0) {
    c = a + b;
  } else if (strcmp(op, "sub") == 0) {
    c = a - b;
  } else if (strcmp(op, "mul") == 0) {
    c = a * b;
  } else if (strcmp(op, "div") == 0) {
    c = a / b;
    if (b == 0) {
      printf("Do not divide by 0.\n");
      r = 1;
    }
  } else if (strcmp(op, "mod") == 0) {
    c = a % b;
    if (b == 0) {
      printf("Do not divide by 0.\n");
      r = 1;
    }
  } else {
    printf("error\n");
    r = 1;
  }
  if (r == 0) {
    printf("%d\n", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x17(%rbp),%rdx
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rcx
call   1050 <scanf@plt>
lea    -0x17(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    118d <main+0x5d>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1297 <main+0x167>
lea    -0x17(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b5 <main+0x85>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1292 <main+0x162>
lea    -0x17(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11de <main+0xae>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    128d <main+0x15d>
lea    -0x17(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1226 <main+0xf6>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1221 <main+0xf1>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1288 <main+0x158>
lea    -0x17(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    126e <main+0x13e>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1269 <main+0x139>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1283 <main+0x153>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1288 <main+0x158>
jmp    128d <main+0x15d>
jmp    1292 <main+0x162>
jmp    1297 <main+0x167>
cmpl   $0x0,-0x14(%rbp)
jne    12b2 <main+0x182>
mov    -0x10(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x5(%rsp),%rbx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdx
call   1050 <scanf@plt>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0xb7>
lea    0xe93(%rip),%rsi
lea    0x5(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0xb7>
lea    0xe81(%rip),%rsi
lea    0x5(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0xb7>
lea    0xe6f(%rip),%rsi
lea    0x5(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d4 <main+0xa4>
lea    0xe5d(%rip),%rsi
lea    0x5(%rsp),%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d4 <main+0xa4>
lea    0xe57(%rip),%rdi
jmp    11e2 <main+0xb2>
cmpl   $0x0,0x8(%rsp)
jne    11e7 <main+0xb7>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Calculator\0A\0A\00"
@.str.1 = [9 x i8] c"%d %s %d\00"
@.str.2 = [4 x i8] c"add\00"
@.str.3 = [4 x i8] c"sub\00"
@.str.4 = [4 x i8] c"mul\00"
@.str.5 = [4 x i8] c"div\00"
@.str.6 = [21 x i8] c"Do not divide by 0.\0A\00"
@.str.7 = [4 x i8] c"mod\00"
@.str.8 = [7 x i8] c"error\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [3 x i8]
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i8* %8, i32* %3)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %14, %15
store i32 %16, i32* %4
br label %65
17: ; preds = %0
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %4
br label %64
25: ; preds = %17
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = mul nsw i32 %30, %31
store i32 %32, i32* %4
br label %63
33: ; preds = %25
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = sdiv i32 %38, %39
store i32 %40, i32* %4
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %5
br label %45
45: ; preds = %43, %37
br label %62
46: ; preds = %33
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %46
%51 = load i32, i32* %2
%52 = load i32, i32* %3
%53 = srem i32 %51, %52
store i32 %53, i32* %4
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %5
br label %58
58: ; preds = %56, %50
br label %61
59: ; preds = %46
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %5
br label %61
61: ; preds = %59, %58
br label %62
62: ; preds = %61, %45
br label %63
63: ; preds = %62, %29
br label %64
64: ; preds = %63, %21
br label %65
65: ; preds = %64, %13
%66 = load i32, i32* %5
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %4
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %68, %65
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%d %s %d\00"
@.str.2 = [4 x i8] c"add\00"
@.str.3 = [4 x i8] c"sub\00"
@.str.4 = [4 x i8] c"mul\00"
@.str.5 = [4 x i8] c"div\00"
@.str.7 = [4 x i8] c"mod\00"
@str = [12 x i8] c"Calculator\0A\00"
@str.10 = [6 x i8] c"error\00"
@str.12 = [20 x i8] c"Do not divide by 0.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i8* %6, i32* %2)
%9 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %0
%12 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %32, label %14
14: ; preds = %11
%15 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %32
23: ; preds = %17
%24 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23, %26, %20
%30 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0), %20 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0), %26 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.10, i64 0, i64 0), %23 ]
%31 = call i32 @puts(i8* dereferenceable(1) %30)
br label %32
32: ; preds = %29, %26, %20, %0, %11, %14
ret i32 0
}