#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*/ addition();
int /*<<< orphan*/ calculator_operations();
int /*<<< orphan*/ division();
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ factorial();
scalar_t__ fork();
char getch();
int /*<<< orphan*/ modulus();
int /*<<< orphan*/ multiplication();
int /*<<< orphan*/ power();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ subtraction();
int /*<<< orphan*/ system(char *);
int main() {
  int X = 1;
  char Calc_oprn;
  int pid, status;
  if (fork()) {
    printf("I'm the Father program.");
  } else {
    printf("I'm the Son program.");
    sleep(1);
    static char *argv[] = {"SimpleCalculator", ".", NULL};
    execv("./SimpleCalculator", argv);
  }
  calculator_operations();
  while (X) {
    printf("\n");
    printf("%s : ", "Enter the calculator Operation you want to do:");
    Calc_oprn = getch();
    switch (Calc_oprn) {
    case '+':
      addition();
      break;
    case '-':
      subtraction();
      break;
    case '*':
      multiplication();
      break;
    case '/':
      division();
      break;
    case '?':
      modulus();
      break;
    case '!':
      factorial();
      break;
    case '^':
      power();
      break;
    case 'H':
    case 'h':
      calculator_operations();
      break;
    case 'Q':
    case 'q':
      exit(0);
      break;
    case 'c':
    case 'C':
      system("cls");
      calculator_operations();
      break;
    default:
      system("cls");
      printf("\n**********You have entered unavailable option");
      printf("***********\n");
      printf("\n*****Please Enter any one of below available ");
      printf("options****\n");
      calculator_operations();
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
cmp    $0x0,%rax
je     122a <main+0x3a>
lea    0xf26(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1255 <main+0x65>
lea    0xf2b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
lea    0xf28(%rip),%rdi
lea    0x2e50(%rip),%rsi
call   1100 <execv@plt>
mov    $0x0,%al
call   1060 <calculator_operations@plt>
cmpl   $0x0,-0x8(%rbp)
je     1391 <main+0x1a1>
lea    0xf8a(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1090 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xf03(%rip),%rdi
lea    0xf02(%rip),%rsi
call   1090 <printf@plt>
mov    -0x21(%rbp),%al
call   10d0 <getch@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xffffffdf,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x50,%eax
ja     1341 <main+0x151>
mov    -0x20(%rbp),%rax
lea    0xd47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1030 <addition@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   10c0 <subtraction@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   1080 <multiplication@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   10b0 <division@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   10a0 <modulus@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   1050 <factorial@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   1040 <power@plt>
jmp    138c <main+0x19c>
mov    $0x0,%al
call   1060 <calculator_operations@plt>
jmp    138c <main+0x19c>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xe89(%rip),%rdi
call   1070 <system@plt>
mov    $0x0,%al
call   1060 <calculator_operations@plt>
jmp    138c <main+0x19c>
lea    0xe71(%rip),%rdi
call   1070 <system@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x0,%al
call   1060 <calculator_operations@plt>
jmp    125c <main+0x6c>
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
push   %rax
xor    %eax,%eax
call   1130 <fork@plt>
test   %rax,%rax
jne    1254 <main+0x44>
lea    0xf2e(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
lea    0xf2b(%rip),%rdi
lea    0x2e63(%rip),%rsi
call   1120 <execv@plt>
jmp    1262 <main+0x52>
lea    0xee9(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
xor    %eax,%eax
call   1080 <calculator_operations@plt>
lea    0xf14(%rip),%r14
lea    0xf13(%rip),%rbx
lea    0xf3b(%rip),%r15
lea    0xf67(%rip),%rbp
lea    0xf9b(%rip),%r12
lea    0xd6d(%rip),%r13
jmp    12a4 <main+0x94>
mov    %r15,%rdi
call   1090 <system@plt>
xor    %eax,%eax
call   1080 <calculator_operations@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
xor    %eax,%eax
call   10f0 <getch@plt>
movsbl %al,%eax
add    $0xffffffdf,%eax
cmp    $0x50,%eax
ja     12e0 <main+0xd0>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
xor    %eax,%eax
call   1070 <factorial@plt>
jmp    12a4 <main+0x94>
mov    %r15,%rdi
call   1090 <system@plt>
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0xf1e(%rip),%rdi
call   1060 <puts@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <printf@plt>
mov    %r12,%rdi
call   1060 <puts@plt>
jmp    129d <main+0x8d>
xor    %eax,%eax
call   10a0 <multiplication@plt>
jmp    12a4 <main+0x94>
xor    %eax,%eax
call   1040 <addition@plt>
jmp    12a4 <main+0x94>
xor    %eax,%eax
call   10e0 <subtraction@plt>
jmp    12a4 <main+0x94>
xor    %eax,%eax
call   10d0 <division@plt>
jmp    12a4 <main+0x94>
xor    %eax,%eax
call   10c0 <modulus@plt>
jmp    12a4 <main+0x94>
xor    %eax,%eax
call   1050 <power@plt>
jmp    12a4 <main+0x94>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"I'm the Father program.\00"
@.str.1 = [21 x i8] c"I'm the Son program.\00"
@main.argv = internal global [3 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.2 = [17 x i8] c"SimpleCalculator\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [19 x i8] c"./SimpleCalculator\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [6 x i8] c"%s : \00"
@.str.7 = [47 x i8] c"Enter the calculator Operation you want to do:\00"
@.str.8 = [4 x i8] c"cls\00"
@.str.9 = [47 x i8] c"\0A**********You have entered unavailable option\00"
@.str.10 = [13 x i8] c"***********\0A\00"
@.str.11 = [47 x i8] c"\0A*****Please Enter any one of below available \00"
@.str.12 = [13 x i8] c"options****\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%6 = call i64 (...) @fork()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @sleep(i32 1)
%13 = call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @main.argv, i64 0, i64 0))
br label %14
14: ; preds = %10, %8
%15 = call i32 (...) @calculator_operations()
br label %16
16: ; preds = %53, %14
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %54
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%22 = call signext i8 (...) @getch()
store i8 %22, i8* %3
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
switch i32 %24, label %46 [
i32 43, label %25
i32 45, label %27
i32 42, label %29
i32 47, label %31
i32 63, label %33
i32 33, label %35
i32 94, label %37
i32 72, label %39
i32 104, label %39
i32 81, label %41
i32 113, label %41
i32 99, label %43
i32 67, label %43
]
25: ; preds = %19
%26 = call i32 (...) @addition()
br label %53
27: ; preds = %19
%28 = call i32 (...) @subtraction()
br label %53
29: ; preds = %19
%30 = call i32 (...) @multiplication()
br label %53
31: ; preds = %19
%32 = call i32 (...) @division()
br label %53
33: ; preds = %19
%34 = call i32 (...) @modulus()
br label %53
35: ; preds = %19
%36 = call i32 (...) @factorial()
br label %53
37: ; preds = %19
%38 = call i32 (...) @power()
br label %53
39: ; preds = %19, %19
%40 = call i32 (...) @calculator_operations()
br label %53
41: ; preds = %19, %19
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %19, %19
%44 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%45 = call i32 (...) @calculator_operations()
br label %53
46: ; preds = %19
%47 = call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.11, i64 0, i64 0))
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
%52 = call i32 (...) @calculator_operations()
br label %53
53: ; preds = %46, %43, %39, %37, %35, %33, %31, %29, %27, %25
br label %16
54: ; preds = %16
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [24 x i8] c"I'm the Father program.\00"
@.str.1 = [21 x i8] c"I'm the Son program.\00"
@main.argv = internal global [3 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.2 = [17 x i8] c"SimpleCalculator\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [19 x i8] c"./SimpleCalculator\00"
@.str.6 = [6 x i8] c"%s : \00"
@.str.7 = [47 x i8] c"Enter the calculator Operation you want to do:\00"
@.str.8 = [4 x i8] c"cls\00"
@.str.9 = [47 x i8] c"\0A**********You have entered unavailable option\00"
@.str.11 = [47 x i8] c"\0A*****Please Enter any one of below available \00"
@str = [12 x i8] c"***********\00"
@str.13 = [12 x i8] c"options****\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %9
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i32 @execv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @main.argv, i64 0, i64 0))
br label %9
9: ; preds = %5, %3
%10 = tail call i32 (...) @calculator_operations()
br label %11
11: ; preds = %44, %9
%12 = tail call i32 @putchar(i32 10)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%14 = tail call signext i8 (...) @getch()
%15 = sext i8 %14 to i32
switch i32 %15, label %37 [
i32 43, label %16
i32 45, label %18
i32 42, label %20
i32 47, label %22
i32 63, label %24
i32 33, label %26
i32 94, label %28
i32 72, label %30
i32 104, label %30
i32 81, label %32
i32 113, label %32
i32 99, label %34
i32 67, label %34
]
16: ; preds = %11
%17 = tail call i32 (...) @addition()
br label %44
18: ; preds = %11
%19 = tail call i32 (...) @subtraction()
br label %44
20: ; preds = %11
%21 = tail call i32 (...) @multiplication()
br label %44
22: ; preds = %11
%23 = tail call i32 (...) @division()
br label %44
24: ; preds = %11
%25 = tail call i32 (...) @modulus()
br label %44
26: ; preds = %11
%27 = tail call i32 (...) @factorial()
br label %44
28: ; preds = %11
%29 = tail call i32 (...) @power()
br label %44
30: ; preds = %11, %11
%31 = tail call i32 (...) @calculator_operations()
br label %44
32: ; preds = %11, %11
%33 = tail call i32 @exit(i32 0)
unreachable
34: ; preds = %11, %11
%35 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%36 = tail call i32 (...) @calculator_operations()
br label %44
37: ; preds = %11
%38 = tail call i32 @system(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.9, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.11, i64 0, i64 0))
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%43 = tail call i32 (...) @calculator_operations()
br label %44
44: ; preds = %37, %34, %30, %28, %26, %24, %22, %20, %18, %16
br label %11
}