#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 == 5) {
    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;
    case 4:
      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   $0x5,-0x8(%rbp)
jne    115f <main+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1209 <main+0xd9>
lea    0xeaa(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,-0xc(%rbp)
lea    0xea9(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    118c <main+0x5c>
jmp    1209 <main+0xd9>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11eb <main+0xbb>
mov    -0x18(%rbp),%rax
lea    0xe54(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <main+0xbb>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <main+0xbb>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11eb <main+0xbb>
mov    -0x10(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    116e <main+0x3e>
jmp    1209 <main+0xd9>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1030 <promptOperation@plt>
cmp    $0x5,%eax
je     11e5 <main+0xb5>
mov    %eax,%ebx
lea    0xebf(%rip),%rdi
call   1050 <promptValue@plt>
mov    %eax,%ebp
lea    0xebf(%rip),%rdi
call   1050 <promptValue@plt>
test   %eax,%eax
je     11e5 <main+0xb5>
add    $0xffffffff,%ebx
lea    0xeb7(%rip),%r14
lea    0xea5(%rip),%r15
lea    0xe80(%rip),%r12
jmp    11b6 <main+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <promptValue@plt>
test   %eax,%eax
je     11e5 <main+0xb5>
cmp    $0x3,%ebx
ja     11a0 <main+0x70>
movslq (%r12,%rbx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
add    %eax,%ebp
jmp    11a0 <main+0x70>
nopl   0x0(%rax,%rax,1)
sub    %eax,%ebp
jmp    11a0 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
imul   %eax,%ebp
jmp    11a0 <main+0x70>
xor    %eax,%eax
pop    %rbx
pop    %r12
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, 5
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %38
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 = %37, %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 %38
16: ; preds = %11
%17 = load i32, i32* %2
switch i32 %17, label %34 [
i32 1, label %18
i32 2, label %22
i32 3, label %26
i32 4, label %30
]
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 %34
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 %34
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 %34
30: ; preds = %16
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = xor i32 %32, %31
store i32 %33, i32* %3
br label %34
34: ; preds = %16, %30, %26, %22, %18
%35 = load i32, i32* %3
%36 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34
br i1 true, label %11, label %38
38: ; preds = %8, %37, %15
%39 = load i32, i32* %1
ret i32 %39
}

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, 5
br i1 %2, label %23, 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 %23, label %7
7: ; preds = %3, %18
%8 = phi i32 [ %21, %18 ], [ %5, %3 ]
%9 = phi i32 [ %19, %18 ], [ %4, %3 ]
switch i32 %1, label %18 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
i32 4, label %16
]
10: ; preds = %7
%11 = add nsw i32 %8, %9
br label %18
12: ; preds = %7
%13 = sub nsw i32 %9, %8
br label %18
14: ; preds = %7
%15 = mul nsw i32 %8, %9
br label %18
16: ; preds = %7
%17 = xor i32 %8, %9
br label %18
18: ; preds = %10, %12, %14, %16, %7
%19 = phi i32 [ %9, %7 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ]
%20 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = tail call i32 @promptValue(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %7
23: ; preds = %18, %3, %0
ret i32 0
}