#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int iChoice, iVal1, iVal2, iResult;
  printf("\nEnter two values\n");
  scanf("%d%d", &iVal1, &iVal2);
  printf("\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n");
  printf("\nEnter your Choice\n");
  scanf("%d", &iChoice);
  switch (iChoice) {
  case 1:
    iResult = iVal1 + iVal2;
    break;
  case 2:
    iResult = iVal1 - iVal2;
    break;
  case 3:
    iResult = iVal1 * iVal2;
    break;
  case 4:
    if (iVal2 == 0) {
      printf("\nCannot divide by zero\n");
      exit(0);
    }
    iResult = iVal1 / iVal2;
    break;
  default:
    printf("\nInvalid Input\n");
    exit(0);
  }
  printf("\nResult of the operation is : %d\n", iResult);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xec9(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x21(%rbp),%al
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xe96(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     121a <main+0xea>
mov    -0x20(%rbp),%rax
lea    0xe48(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122f <main+0xff>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122f <main+0xff>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122f <main+0xff>
cmpl   $0x0,-0x10(%rbp)
jne    120b <main+0xdb>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
jmp    122f <main+0xff>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     11f4 <main+0xb4>
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0xc(%rsp),%esi
add    0x10(%rsp),%esi
jmp    11df <main+0x9f>
mov    0xc(%rsp),%esi
imul   0x10(%rsp),%esi
jmp    11df <main+0x9f>
mov    0x10(%rsp),%esi
sub    0xc(%rsp),%esi
jmp    11df <main+0x9f>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     11fd <main+0xbd>
mov    0x10(%rsp),%eax
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xeae(%rip),%rdi
jmp    1204 <main+0xc4>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"\0AEnter two values\0A\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [55 x i8] c"\0A1.Addition\0A2.Subtraction\0A3.Multiplication\0A4.Division\0A\00"
@.str.3 = [20 x i8] c"\0AEnter your Choice\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [24 x i8] c"\0ACannot divide by zero\0A\00"
@.str.6 = [16 x i8] c"\0AInvalid Input\0A\00"
@.str.7 = [34 x i8] c"\0AResult of the operation is : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %34 [
i32 1, label %12
i32 2, label %16
i32 3, label %20
i32 4, label %24
]
12: ; preds = %0
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %13, %14
store i32 %15, i32* %5
br label %37
16: ; preds = %0
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %5
br label %37
20: ; preds = %0
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = mul nsw i32 %21, %22
store i32 %23, i32* %5
br label %37
24: ; preds = %0
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %24
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = sdiv i32 %31, %32
store i32 %33, i32* %5
br label %37
34: ; preds = %0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %30, %20, %16, %12
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d%d\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.7 = [34 x i8] c"\0AResult of the operation is : %d\0A\00"
@str = [18 x i8] c"\0AEnter two values\00"
@str.8 = [54 x i8] c"\0A1.Addition\0A2.Subtraction\0A3.Multiplication\0A4.Division\00"
@str.9 = [19 x i8] c"\0AEnter your Choice\00"
@str.10 = [23 x i8] c"\0ACannot divide by zero\00"
@str.11 = [15 x i8] c"\0AInvalid Input\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.8, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
switch i32 %12, label %34 [
i32 1, label %13
i32 2, label %17
i32 3, label %21
i32 4, label %25
]
13: ; preds = %0
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %15, %14
br label %37
17: ; preds = %0
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = sub nsw i32 %18, %19
br label %37
21: ; preds = %0
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = mul nsw i32 %23, %22
br label %37
25: ; preds = %0
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %25
%32 = load i32, i32* %2
%33 = sdiv i32 %32, %26
br label %37
34: ; preds = %0
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %31, %21, %17, %13
%38 = phi i32 [ %33, %31 ], [ %24, %21 ], [ %20, %17 ], [ %16, %13 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i32 %38)
ret i32 0
}