#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 /*<<< orphan*/ scanf(char *, ...);
int main() {
  int cmd;
  float balance = 0.0f, credit, debit;
  printf("*** ACME checkbook-balancing program ***\n");
  printf("Commands: 0=clear, 1=creadit, 2=debit, 3=balance, 4=exit\n\n");
  for (;;) {
    printf("Enter command: ");
    scanf("%d", &cmd);
    switch (cmd) {
    case 0:
      balance = 0.0f;
      break;
    case 1:
      printf("Enter amount of credit: ");
      scanf("%f", &credit);
      balance += credit;
      break;
    case 2:
      printf("Enter amount of debit: ");
      scanf("%f", &debit);
      balance -= debit;
      break;
    case 3:
      printf("Current balance: $%.2f\n", balance);
      break;
    case 4:
      return 0;
    default:
      printf("Commands: 0=clear, 1=creadit, 2=debit, 3=balance, 4=exit\n\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1f(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
lea    0xf1b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x4,%rax
ja     1239 <main+0x119>
mov    -0x20(%rbp),%rax
lea    0xe6d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1247 <main+0x127>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1247 <main+0x127>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movss  -0x14(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1247 <main+0x127>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe9b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1247 <main+0x127>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1153 <main+0x33>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xf2e(%rip),%rdi
call   1030 <puts@plt>
lea    0xf4b(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
lea    0xeb1(%rip),%r15
lea    0xeba(%rip),%r12
lea    0xc(%rsp),%rbx
lea    0xe8a(%rip),%rbp
lea    0xede(%rip),%r13
movss  %xmm0,(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    1198 <main+0x68>
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x4,%rax
ja     1190 <main+0x60>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    %r13,%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1198 <main+0x68>
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
jmp    117d <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe3b(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  (%rsp),%xmm0
addss  0x8(%rsp),%xmm0
jmp    117d <main+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movss  (%rsp),%xmm0
subss  0x4(%rsp),%xmm0
jmp    117d <main+0x4d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"*** ACME checkbook-balancing program ***\0A\00"
@.str.1 = [59 x i8] c"Commands: 0=clear, 1=creadit, 2=debit, 3=balance, 4=exit\0A\0A\00"
@.str.2 = [16 x i8] c"Enter command: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [25 x i8] c"Enter amount of credit: \00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [24 x i8] c"Enter amount of debit: \00"
@.str.7 = [24 x i8] c"Current balance: $%.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
store i32 0, i32* %1
store float 0.000000e+00, float* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %32, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %30 [
i32 0, label %12
i32 1, label %13
i32 2, label %19
i32 3, label %25
i32 4, label %29
]
12: ; preds = %8
store float 0.000000e+00, float* %3
br label %32
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %4)
%16 = load float, float* %4
%17 = load float, float* %3
%18 = fadd float %17, %16
store float %18, float* %3
br label %32
19: ; preds = %8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %5)
%22 = load float, float* %5
%23 = load float, float* %3
%24 = fsub float %23, %22
store float %24, float* %3
br label %32
25: ; preds = %8
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %27)
br label %32
29: ; preds = %8
ret i32 0
30: ; preds = %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %25, %19, %13, %12
br label %8
}

LLVM IR (-O2):
@.str.2 = [16 x i8] c"Enter command: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [25 x i8] c"Enter amount of credit: \00"
@.str.5 = [3 x i8] c"%f\00"
@.str.6 = [24 x i8] c"Enter amount of debit: \00"
@.str.7 = [24 x i8] c"Current balance: $%.2f\0A\00"
@str = [41 x i8] c"*** ACME checkbook-balancing program ***\00"
@str.9 = [58 x i8] c"Commands: 0=clear, 1=creadit, 2=debit, 3=balance, 4=exit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = bitcast i32* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast float* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.9, i64 0, i64 0))
br label %9
9: ; preds = %26, %0
%10 = phi float [ 0.000000e+00, %0 ], [ %27, %26 ]
%11 = fpext float %10 to double
br label %12
12: ; preds = %33, %9
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%15 = load i32, i32* %1
switch i32 %15, label %31 [
i32 0, label %26
i32 1, label %16
i32 2, label %21
i32 3, label %28
i32 4, label %30
]
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %2)
%19 = load float, float* %2
%20 = fadd float %10, %19
br label %26
21: ; preds = %12
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), float* %3)
%24 = load float, float* %3
%25 = fsub float %10, %24
br label %26
26: ; preds = %12, %21, %16
%27 = phi float [ %20, %16 ], [ %25, %21 ], [ 0.000000e+00, %12 ]
br label %9
28: ; preds = %12
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), double %11)
br label %33
30: ; preds = %12
ret i32 0
31: ; preds = %12
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.9, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
br label %12
}