#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*/ add(int, int);
int /*<<< orphan*/ divide(int, int);
int /*<<< orphan*/ multiply(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ subtract(int, int);
void main() {
  int a, b, option;
  printf("enter two numbers \n");
  scanf("%d", &a);
  scanf("%d", &b);
  printf("Select your option \n");
  printf("1. add the numbers \n");
  printf("2. multiply the numbers \n");
  printf("3. divide the numbers \n");
  printf("4. subtract the numbers \n");
  scanf("%d", &option);
  switch (option) {
  case 1:
    add(a, b);
    break;
  case 2:
    multiply(a, b);
    break;
  case 3:
    divide(a, b);
    break;
  case 4:
    subtract(a, b);
    break;
  default:
    printf("invalid");
    break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1060 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %rdi,-0x20(%rbp)
lea    -0x4(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xe8b(%rip),%rdi
call   1060 <printf@plt>
lea    0xe94(%rip),%rdi
call   1060 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1060 <printf@plt>
lea    0xeab(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb7(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     1247 <main+0xe7>
mov    -0x18(%rbp),%rax
lea    0xe02(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <add@plt>
jmp    1253 <main+0xf3>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <multiply@plt>
jmp    1253 <main+0xf3>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <divide@plt>
jmp    1253 <main+0xf3>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <subtract@plt>
jmp    1253 <main+0xf3>
lea    0xe4f(%rip),%rdi
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe9f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe88(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0xe85(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe95(%rip),%rdi
call   1050 <puts@plt>
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
lea    0xead(%rip),%rdi
call   1050 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1216 <main+0xa6>
lea    0xe02(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1030 <add@plt>
jmp    124f <main+0xdf>
lea    0xdf6(%rip),%rdi
call   1070 <printf@plt>
jmp    124f <main+0xdf>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <multiply@plt>
jmp    124f <main+0xdf>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1060 <divide@plt>
jmp    124f <main+0xdf>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
call   1090 <subtract@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"enter two numbers \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Select your option \0A\00"
@.str.3 = [21 x i8] c"1. add the numbers \0A\00"
@.str.4 = [26 x i8] c"2. multiply the numbers \0A\00"
@.str.5 = [24 x i8] c"3. divide the numbers \0A\00"
@.str.6 = [26 x i8] c"4. subtract the numbers \0A\00"
@.str.7 = [8 x i8] c"invalid\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, 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 = call i32 @add(i32 %15, i32 %16)
br label %32
18: ; preds = %0
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = call i32 @multiply(i32 %19, i32 %20)
br label %32
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = call i32 @divide(i32 %23, i32 %24)
br label %32
26: ; preds = %0
%27 = load i32, i32* %1
%28 = load i32, i32* %2
%29 = call i32 @subtract(i32 %27, i32 %28)
br label %32
30: ; preds = %0
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %26, %22, %18, %14
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.7 = [8 x i8] c"invalid\00"
@str = [19 x i8] c"enter two numbers \00"
@str.8 = [20 x i8] c"Select your option \00"
@str.9 = [20 x i8] c"1. add the numbers \00"
@str.10 = [25 x i8] c"2. multiply the numbers \00"
@str.11 = [23 x i8] c"3. divide the numbers \00"
@str.12 = [25 x i8] c"4. subtract the numbers \00"
define void @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 ([19 x i8], [19 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 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
switch i32 %16, label %33 [
i32 1, label %17
i32 2, label %21
i32 3, label %25
i32 4, label %29
]
17: ; preds = %0
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = call i32 @add(i32 %18, i32 %19)
br label %35
21: ; preds = %0
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = call i32 @multiply(i32 %22, i32 %23)
br label %35
25: ; preds = %0
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @divide(i32 %26, i32 %27)
br label %35
29: ; preds = %0
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = call i32 @subtract(i32 %30, i32 %31)
br label %35
33: ; preds = %0
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %35
35: ; preds = %33, %29, %25, %21, %17
ret void
}