#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);
  switch (op) {
  case '+':
    result = add(op1, op2);
    break;
  case '-':
    result = subtract(op1, op2);
    break;
  case '*':
    result = multiply(op1, op2);
    break;
  case '/':
    result = divide(op1, op2);
    break;
  default:
    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    0xe82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe99(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0xd(%rbp),%rcx
call   1080 <scanf@plt>
movsbl -0xd(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     122b <main+0xab>
mov    -0x20(%rbp),%rax
lea    0xe2a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <add@plt>
mov    %eax,-0x14(%rbp)
jmp    124e <main+0xce>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <subtract@plt>
mov    %eax,-0x14(%rbp)
jmp    124e <main+0xce>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <multiply@plt>
mov    %eax,-0x14(%rbp)
jmp    124e <main+0xce>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <divide@plt>
mov    %eax,-0x14(%rbp)
jmp    124e <main+0xce>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
movsbl -0xd(%rbp),%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%esi
movsbl -0xd(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdfa(%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>
movsbl 0xf(%rsp),%eax
lea    -0x2a(%rax),%ecx
cmp    $0x5,%ecx
ja     1229 <main+0xa9>
lea    0xe3f(%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    1204 <main+0x84>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1090 <subtract@plt>
jmp    1204 <main+0x84>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1050 <divide@plt>
jmp    1204 <main+0x84>
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    0xe42(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2db0(%rip),%rcx
mov    (%rcx),%edi
movsbl %al,%edx
lea    0xe0a(%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
switch i32 %9, label %26 [
i32 43, label %10
i32 45, label %14
i32 42, label %18
i32 47, label %22
]
10: ; preds = %0
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 @add(i32 %11, i32 %12)
store i32 %13, i32* %5
br label %31
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 @subtract(i32 %15, i32 %16)
store i32 %17, i32* %5
br label %31
18: ; preds = %0
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = call i32 @multiply(i32 %19, i32 %20)
store i32 %21, i32* %5
br label %31
22: ; preds = %0
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = call i32 @divide(i32 %23, i32 %24)
store i32 %25, i32* %5
br label %31
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = load i8, i8* %4
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22, %18, %14, %10
%32 = load i32, i32* %2
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = load i32, i32* %3
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %34, i32 %35, i32 %36)
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
%9 = sext i8 %8 to i32
switch i32 %9, label %26 [
i32 43, label %10
i32 45, label %14
i32 42, label %18
i32 47, label %22
]
10: ; preds = %0
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = call i32 @add(i32 %11, i32 %12)
br label %30
14: ; preds = %0
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 @subtract(i32 %15, i32 %16)
br label %30
18: ; preds = %0
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = call i32 @multiply(i32 %19, i32 %20)
br label %30
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = call i32 @divide(i32 %23, i32 %24)
br label %30
26: ; preds = %0
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %8)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22, %18, %14, %10
%31 = phi i32 [ %25, %22 ], [ %21, %18 ], [ %17, %14 ], [ %13, %10 ]
%32 = load i32, i32* %1
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = load i32, i32* %2
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %34, i32 %35, i32 %31)
ret i32 0
}