#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 /*<<< orphan*/ CloseDev();
int Div(int, int);
int Mul(int, int);
int OpenDev();
int Sub(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int data1, data2;
  int opt;
  int err = 0;
  err = OpenDev();
  if (err < 0) {
    printf("\n open: Error in file open... ");
    return -1;
  }
  while (1) {
    printf("\n 1.Add\n2.Sub\n3.Mul\n4.Div\n 				"
           "5.ExitApp\nChoose Operation:");
    scanf("%d", &opt);
    if (opt == 5)
      break;
    if (opt < 1 || opt > 4) {
      printf("\n Invalid Option... ");
      continue;
    }
    printf("\n Enter Data1:");
    scanf("%d", &data1);
    printf("\n Enter Data2:");
    scanf("%d", &data2);
    switch (opt) {
    case 1:
      err = Add(data1, data2);
      break;
    case 2:
      err = Sub(data1, data2);
      break;
    case 3:
      err = Mul(data1, data2);
      break;
    case 4:
      err = Div(data1, data2);
      break;
    }
    printf("\n Result is :%d", err);
  }
  CloseDev();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1070 <OpenDev@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c4 <main+0x44>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f2 <main+0x172>
jmp    11c9 <main+0x49>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x5,-0x10(%rbp)
jne    11f6 <main+0x76>
jmp    12e4 <main+0x164>
cmpl   $0x1,-0x10(%rbp)
jl     120a <main+0x8a>
cmpl   $0x4,-0x10(%rbp)
jle    121d <main+0x9d>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c9 <main+0x49>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
mov    %rdi,-0x28(%rbp)
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x29(%rbp),%al
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     12ce <main+0x14e>
mov    -0x20(%rbp),%rax
lea    0xd82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <Add@plt>
mov    %eax,-0x14(%rbp)
jmp    12ce <main+0x14e>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <Sub@plt>
mov    %eax,-0x14(%rbp)
jmp    12ce <main+0x14e>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <Mul@plt>
mov    %eax,-0x14(%rbp)
jmp    12ce <main+0x14e>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <Div@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c9 <main+0x49>
mov    $0x0,%al
call   10a0 <CloseDev@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <OpenDev@plt>
test   %eax,%eax
js     11d0 <main+0x50>
mov    %eax,%r13d
lea    0xe8c(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%eax
jne    11f6 <main+0x76>
xor    %eax,%eax
call   10a0 <CloseDev@plt>
jmp    11e4 <main+0x64>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6d(%rip),%r15
lea    0xe2b(%rip),%r12
lea    0xe9f(%rip),%rbx
lea    0xc(%rsp),%rbp
add    $0xfffffffb,%eax
cmp    $0xfffffffb,%eax
ja     1242 <main+0xc2>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x5,%eax
jne    1210 <main+0x90>
jmp    11c7 <main+0x47>
lea    0xe36(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x14(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     12d1 <main+0x151>
lea    0xd75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1090 <Add@plt>
jmp    12ce <main+0x14e>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1080 <Sub@plt>
jmp    12ce <main+0x14e>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1060 <Mul@plt>
jmp    12ce <main+0x14e>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
call   1030 <Div@plt>
mov    %eax,%r13d
lea    0xdc5(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1222 <main+0xa2>

LLVM IR (-O0):
@.str = [31 x i8] c"\0A open: Error in file open... \00"
@.str.1 = [59 x i8] c"\0A 1.Add\0A2.Sub\0A3.Mul\0A4.Div\0A \09\09\09\095.ExitApp\0AChoose Operation:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [21 x i8] c"\0A Invalid Option... \00"
@.str.4 = [15 x i8] c"\0A Enter Data1:\00"
@.str.5 = [15 x i8] c"\0A Enter Data2:\00"
@.str.6 = [16 x i8] c"\0A Result 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
store i32 0, i32* %5
%6 = call i32 (...) @OpenDev()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
11: ; preds = %0
br label %12
12: ; preds = %11, %24, %48
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 5
br i1 %16, label %17, label %18
17: ; preds = %12
br label %51
18: ; preds = %12
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 4
br i1 %23, label %24, label %26
24: ; preds = %21, %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %12
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%31 = load i32, i32* %4
switch i32 %31, label %48 [
i32 1, label %32
i32 2, label %36
i32 3, label %40
i32 4, label %44
]
32: ; preds = %26
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @Add(i32 %33, i32 %34)
store i32 %35, i32* %5
br label %48
36: ; preds = %26
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = call i32 @Sub(i32 %37, i32 %38)
store i32 %39, i32* %5
br label %48
40: ; preds = %26
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = call i32 @Mul(i32 %41, i32 %42)
store i32 %43, i32* %5
br label %48
44: ; preds = %26
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = call i32 @Div(i32 %45, i32 %46)
store i32 %47, i32* %5
br label %48
48: ; preds = %26, %44, %40, %36, %32
%49 = load i32, i32* %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %49)
br label %12
51: ; preds = %17
%52 = call i32 (...) @CloseDev()
store i32 0, i32* %1
br label %53
53: ; preds = %51, %9
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0A open: Error in file open... \00"
@.str.1 = [59 x i8] c"\0A 1.Add\0A2.Sub\0A3.Mul\0A4.Div\0A \09\09\09\095.ExitApp\0AChoose Operation:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [21 x i8] c"\0A Invalid Option... \00"
@.str.4 = [15 x i8] c"\0A Enter Data1:\00"
@.str.5 = [15 x i8] c"\0A Enter Data2:\00"
@.str.6 = [16 x i8] c"\0A Result is :%d\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 (...) @OpenDev()
%8 = icmp slt i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 5
br i1 %13, label %58, label %55
14: ; preds = %0
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %60
16: ; preds = %55, %20
%17 = phi i32 [ %56, %55 ], [ %24, %20 ]
%18 = add i32 %17, -5
%19 = icmp ult i32 %18, -4
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 5
br i1 %25, label %58, label %16
26: ; preds = %16
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%31 = load i32, i32* %3
switch i32 %31, label %48 [
i32 1, label %32
i32 2, label %36
i32 3, label %40
i32 4, label %44
]
32: ; preds = %26
%33 = load i32, i32* %1
%34 = load i32, i32* %2
%35 = call i32 @Add(i32 %33, i32 %34)
br label %48
36: ; preds = %26
%37 = load i32, i32* %1
%38 = load i32, i32* %2
%39 = call i32 @Sub(i32 %37, i32 %38)
br label %48
40: ; preds = %26
%41 = load i32, i32* %1
%42 = load i32, i32* %2
%43 = call i32 @Mul(i32 %41, i32 %42)
br label %48
44: ; preds = %26
%45 = load i32, i32* %1
%46 = load i32, i32* %2
%47 = call i32 @Div(i32 %45, i32 %46)
br label %48
48: ; preds = %26, %44, %40, %36, %32
%49 = phi i32 [ %57, %26 ], [ %47, %44 ], [ %43, %40 ], [ %39, %36 ], [ %35, %32 ]
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%52 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%53 = load i32, i32* %3
%54 = icmp eq i32 %53, 5
br i1 %54, label %58, label %55
55: ; preds = %9, %48
%56 = phi i32 [ %53, %48 ], [ %12, %9 ]
%57 = phi i32 [ %49, %48 ], [ %7, %9 ]
br label %16
58: ; preds = %48, %20, %9
%59 = call i32 (...) @CloseDev()
br label %60
60: ; preds = %58, %14
%61 = phi i32 [ -1, %14 ], [ 0, %58 ]
ret i32 %61
}