#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 *);
int main(void) {
  int op1, op2, res;
  int n;
  printf("enter operand 1: ");
  scanf("%d", &op1);
  printf("enter operand 2: ");
  scanf("%d", &op2);
  printf("enter your choice: 1.ADD\n 2.SUBTRACT\n3.MULTIPLY \n4.DIVISION");
  res = 0;
  scanf("%d", &n);
  switch (n) {
  case 1:
    res = op1 + op2;
    break;
  case 2:
    res = op1 - op2;
    break;
  case 3:
    res = op1 * op2;
    break;
  case 4:
    res = op1 / op2;
    break;
  default:
    printf("invalid input try again\n");
    break;
  }
  printf("the result of operation is %d", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1030 <printf@plt>
lea    0xf5d(%rip),%rdi
mov    %rdi,-0x28(%rbp)
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x29(%rbp),%al
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x29(%rbp),%al
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
movl   $0x0,-0x10(%rbp)
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11f6 <main+0xd6>
mov    -0x20(%rbp),%rax
lea    0xe4d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1204 <main+0xe4>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1204 <main+0xe4>
mov    -0x8(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1204 <main+0xe4>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
jmp    1204 <main+0xe4>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf3d(%rip),%r14
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x14(%rsp),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     11b7 <main+0x87>
lea    0xe5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0xc(%rsp),%ebx
add    0x10(%rsp),%ebx
jmp    11e5 <main+0xb5>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <main+0xb5>
mov    0x10(%rsp),%ebx
sub    0xc(%rsp),%ebx
jmp    11e5 <main+0xb5>
mov    0xc(%rsp),%ebx
imul   0x10(%rsp),%ebx
jmp    11e5 <main+0xb5>
mov    0x10(%rsp),%eax
cltd
idivl  0xc(%rsp)
mov    %eax,%ebx
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"enter operand 1: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"enter operand 2: \00"
@.str.3 = [60 x i8] c"enter your choice: 1.ADD\0A 2.SUBTRACT\0A3.MULTIPLY \0A4.DIVISION\00"
@.str.4 = [25 x i8] c"invalid input try again\0A\00"
@.str.5 = [30 x i8] c"the result of operation is %d\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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @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 ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%12 = load i32, i32* %5
switch i32 %12, label %29 [
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 %14, %15
store i32 %16, i32* %4
br label %31
17: ; preds = %0
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %4
br label %31
21: ; preds = %0
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = mul nsw i32 %22, %23
store i32 %24, i32* %4
br label %31
25: ; preds = %0
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = sdiv i32 %26, %27
store i32 %28, i32* %4
br label %31
29: ; preds = %0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %25, %21, %17, %13
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"enter operand 1: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [18 x i8] c"enter operand 2: \00"
@.str.3 = [60 x i8] c"enter your choice: 1.ADD\0A 2.SUBTRACT\0A3.MULTIPLY \0A4.DIVISION\00"
@.str.5 = [30 x i8] c"the result of operation is %d\00"
@str = [24 x i8] c"invalid input try again\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
switch i32 %13, label %30 [
i32 1, label %14
i32 2, label %18
i32 3, label %22
i32 4, label %26
]
14: ; preds = %0
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %15
br label %32
18: ; preds = %0
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = sub nsw i32 %19, %20
br label %32
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, %23
br label %32
26: ; preds = %0
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = sdiv i32 %27, %28
br label %32
30: ; preds = %0
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %26, %22, %18, %14
%33 = phi i32 [ 0, %30 ], [ %29, %26 ], [ %25, %22 ], [ %21, %18 ], [ %17, %14 ]
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %33)
ret i32 0
}