#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 add(int, int);
int divide(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int multiply(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *, char *);
int /*<<< orphan*/ stderr;
int subtract(int, int);
int main() {
  int op1, op2;
  char op;
  int result;
  printf("Input two integers and a operator : ");
  scanf("%d %d %c", &op1, &op2, &op);
  if (op == '+') {
    result = add(op1, op2);
  } else if (op == '-') {
    result = subtract(op1, op2);
  } else if (op == '*') {
    result = multiply(op1, op2);
  } else if (op == '/') {
    result = divide(op1, op2);
  } else {
    fprintf(stderr, "Invalid operator '%c'\n", op);
    exit(1);
  }
  printf("%d %c %d = %d \n", op1, op, op2, result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe81(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1080 <scanf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x2b,%eax
jne    11d5 <main+0x55>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <add@plt>
mov    %eax,-0x14(%rbp)
jmp    1267 <main+0xe7>
movsbl -0xd(%rbp),%eax
cmp    $0x2d,%eax
jne    11f5 <main+0x75>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <subtract@plt>
mov    %eax,-0x14(%rbp)
jmp    1262 <main+0xe2>
movsbl -0xd(%rbp),%eax
cmp    $0x2a,%eax
jne    1215 <main+0x95>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <multiply@plt>
mov    %eax,-0x14(%rbp)
jmp    125d <main+0xdd>
movsbl -0xd(%rbp),%eax
cmp    $0x2f,%eax
jne    1235 <main+0xb5>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <divide@plt>
mov    %eax,-0x14(%rbp)
jmp    1258 <main+0xd8>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
movsbl -0xd(%rbp),%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    125d <main+0xdd>
jmp    1262 <main+0xe2>
jmp    1267 <main+0xe7>
mov    -0x8(%rbp),%esi
movsbl -0xd(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xea4(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
call   1080 <scanf@plt>
mov    0xf(%rsp),%al
lea    -0x2a(%rax),%ecx
cmp    $0x5,%cl
ja     122b <main+0xab>
movzbl %cl,%ecx
lea    0xe3d(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1040 <multiply@plt>
jmp    1206 <main+0x86>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1090 <subtract@plt>
jmp    1206 <main+0x86>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1050 <divide@plt>
jmp    1206 <main+0x86>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1030 <add@plt>
mov    %eax,%r8d
mov    0x14(%rsp),%esi
movsbl 0xf(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2dae(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xe08(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Input two integers and a operator : \00"
@.str.1 = [9 x i8] c"%d %d %c\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Invalid operator '%c'\0A\00"
@.str.3 = [16 x i8] c"%d %c %d = %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 ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i8* %4)
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 43
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @add(i32 %12, i32 %13)
store i32 %14, i32* %5
br label %47
15: ; preds = %0
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 45
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = call i32 @subtract(i32 %20, i32 %21)
store i32 %22, i32* %5
br label %46
23: ; preds = %15
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 42
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = call i32 @multiply(i32 %28, i32 %29)
store i32 %30, i32* %5
br label %45
31: ; preds = %23
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = call i32 @divide(i32 %36, i32 %37)
store i32 %38, i32* %5
br label %44
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = load i8, i8* %4
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
br label %45
45: ; preds = %44, %27
br label %46
46: ; preds = %45, %19
br label %47
47: ; preds = %46, %11
%48 = load i32, i32* %2
%49 = load i8, i8* %4
%50 = sext i8 %49 to i32
%51 = load i32, i32* %3
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %48, i32 %50, i32 %51, i32 %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Input two integers and a operator : \00"
@.str.1 = [9 x i8] c"%d %d %c\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Invalid operator '%c'\0A\00"
@.str.3 = [16 x i8] c"%d %c %d = %d \0A\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 ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i8* %3)
%8 = load i8, i8* %3
switch i8 %8, label %25 [
i8 43, label %9
i8 45, label %13
i8 42, label %17
i8 47, label %21
]
9: ; preds = %0
%10 = load i32, i32* %1
%11 = load i32, i32* %2
%12 = call i32 @add(i32 %10, i32 %11)
br label %29
13: ; preds = %0
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = call i32 @subtract(i32 %14, i32 %15)
br label %29
17: ; preds = %0
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = call i32 @multiply(i32 %18, i32 %19)
br label %29
21: ; preds = %0
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = call i32 @divide(i32 %22, i32 %23)
br label %29
25: ; preds = %0
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %8)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %13, %21, %17, %9
%30 = phi i32 [ %12, %9 ], [ %16, %13 ], [ %20, %17 ], [ %24, %21 ]
%31 = load i32, i32* %1
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = load i32, i32* %2
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %34, i32 %30)
ret i32 0
}