#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);
int promptOperation();
int promptValue(char *);
int main() {
  int operation = promptOperation();
  if (operation == 4) {
    return 0;
  }
  int initialValue = promptValue("Initial value");
  do {
    int nextValue = promptValue("Next value");
    if (nextValue == 0) {
      break;
    }
    switch (operation) {
    case 1:
      initialValue += nextValue;
      break;
    case 2:
      initialValue -= nextValue;
      break;
    case 3:
      initialValue *= nextValue;
      break;
    }
    printf("Result: %d\n", initialValue);
  } while (true);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <promptOperation@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    115f <main+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1208 <main+0xd8>
lea    0xe9a(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,-0xc(%rbp)
lea    0xe99(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    118c <main+0x5c>
jmp    1208 <main+0xd8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     11c2 <main+0x92>
jmp    11a0 <main+0x70>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11d0 <main+0xa0>
jmp    11b1 <main+0x81>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
je     11e0 <main+0xb0>
jmp    11ea <main+0xba>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11ea <main+0xba>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11ea <main+0xba>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    116e <main+0x3e>
jmp    1208 <main+0xd8>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <promptOperation@plt>
cmp    $0x4,%eax
je     11b5 <main+0x85>
mov    %eax,%ebx
lea    0xeb4(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,%ebp
lea    0xeb4(%rip),%rdi
call   1050 <promptValue@plt>
test   %eax,%eax
je     11b5 <main+0x85>
lea    0xeaf(%rip),%r14
lea    0xe9d(%rip),%r15
jmp    1198 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sub    %eax,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <promptValue@plt>
test   %eax,%eax
je     11b5 <main+0x85>
cmp    $0x3,%ebx
je     11b0 <main+0x80>
cmp    $0x2,%ebx
je     1180 <main+0x50>
cmp    $0x1,%ebx
jne    1182 <main+0x52>
add    %eax,%ebp
jmp    1182 <main+0x52>
nopl   0x0(%rax,%rax,1)
imul   %eax,%ebp
jmp    1182 <main+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Initial value\00"
@.str.1 = [11 x i8] c"Next value\00"
@.str.2 = [12 x i8] c"Result: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @promptOperation()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 4
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %34
9: ; preds = %0
%10 = call i32 @promptValue(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %3
br label %11
11: ; preds = %33, %9
%12 = call i32 @promptValue(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %34
16: ; preds = %11
%17 = load i32, i32* %2
switch i32 %17, label %30 [
i32 1, label %18
i32 2, label %22
i32 3, label %26
]
18: ; preds = %16
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
br label %30
22: ; preds = %16
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = sub nsw i32 %24, %23
store i32 %25, i32* %3
br label %30
26: ; preds = %16
%27 = load i32, i32* %4
%28 = load i32, i32* %3
%29 = mul nsw i32 %28, %27
store i32 %29, i32* %3
br label %30
30: ; preds = %16, %26, %22, %18
%31 = load i32, i32* %3
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30
br i1 true, label %11, label %34
34: ; preds = %8, %33, %15
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [14 x i8] c"Initial value\00"
@.str.1 = [11 x i8] c"Next value\00"
@.str.2 = [12 x i8] c"Result: %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @promptOperation()
%2 = icmp eq i32 %1, 4
br i1 %2, label %21, label %3
3: ; preds = %0
%4 = tail call i32 @promptValue(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @promptValue(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %3, %16
%8 = phi i32 [ %19, %16 ], [ %5, %3 ]
%9 = phi i32 [ %17, %16 ], [ %4, %3 ]
switch i32 %1, label %16 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
]
10: ; preds = %7
%11 = add nsw i32 %8, %9
br label %16
12: ; preds = %7
%13 = sub nsw i32 %9, %8
br label %16
14: ; preds = %7
%15 = mul nsw i32 %8, %9
br label %16
16: ; preds = %10, %12, %14, %7
%17 = phi i32 [ %9, %7 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ]
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 @promptValue(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %16, %3, %0
ret i32 0
}