#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*/ puts(char *);
int spendThisMuch(int);
int initialPurchase(int a[]) {
  int moneySpent;
  int money = 700;
  for (int supply = 0; supply <= 4; supply++) {
    switch (supply) {
    case 0:
      puts("HOW MUCH DO YOU WANT TO SPEND ON YOUR OXEN TEAM");
      do {
        moneySpent = spendThisMuch(0);
      } while (moneySpent < 200 || moneySpent > 300);
      a[0] = moneySpent;
      money -= moneySpent;
      break;
    case 1:
      puts("HOW MUCH DO YOU WANT TO SPEND ON AMMUNITION");
      do {
        moneySpent = spendThisMuch(1);
      } while (moneySpent < 0);
      a[1] = moneySpent;
      money -= moneySpent;
      break;
    case 2:
      puts("HOW MUCH DO YOU WANT TO SPEND ON CLOTHING");
      do {
        moneySpent = spendThisMuch(2);
      } while (moneySpent < 0);
      a[2] = moneySpent;
      money -= moneySpent;
      break;
    case 3:
      puts("HOW MUCH DO YOU WANT TO SPEND ON FOOD");
      do {
        moneySpent = spendThisMuch(3);
      } while (moneySpent < 0);
      a[3] = moneySpent;
      money -= moneySpent;
      break;
    case 4:
      puts("HOW MUCH DO YOU WANT TO SPEND ON MISCELANEOUS SUPPLIES");
      do {
        moneySpent = spendThisMuch(4);
      } while (moneySpent < 0);
      a[4] = moneySpent;
      money -= moneySpent;
      break;
    }
  }
  return money;
}


x86 assembly (clang, -O0):
<initialPurchase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2bc,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jg     12c4 <initialPurchase+0x1a4>
mov    -0x14(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x4,%rax
ja     12b1 <initialPurchase+0x191>
mov    -0x20(%rbp),%rax
lea    0xea0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <spendThisMuch@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%al
cmpl   $0xc8,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jl     119e <initialPurchase+0x7e>
cmpl   $0x12c,-0xc(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1175 <initialPurchase+0x55>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    12b1 <initialPurchase+0x191>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <spendThisMuch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11ce <initialPurchase+0xae>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    12b1 <initialPurchase+0x191>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1040 <spendThisMuch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     120b <initialPurchase+0xeb>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    12b1 <initialPurchase+0x191>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1040 <spendThisMuch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1248 <initialPurchase+0x128>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    12b1 <initialPurchase+0x191>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   1040 <spendThisMuch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1285 <initialPurchase+0x165>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    12b6 <initialPurchase+0x196>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <initialPurchase+0x1a>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialPurchase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2bc,%ebx
xor    %r12d,%r12d
lea    0xec3(%rip),%r13
lea    0xf56(%rip),%rbp
lea    0xf75(%rip),%r15
jmp    1160 <initialPurchase+0x40>
nopl   (%rax)
sub    %eax,%ebx
add    $0x1,%r12d
cmp    $0x5,%r12d
je     1227 <initialPurchase+0x107>
cmp    $0x4,%r12d
ja     1152 <initialPurchase+0x32>
mov    %r12d,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
nop
xor    %edi,%edi
call   1040 <spendThisMuch@plt>
lea    -0x12d(%rax),%ecx
cmp    $0xffffff9b,%ecx
jb     1180 <initialPurchase+0x60>
mov    %eax,(%r14)
sub    %eax,%ebx
jmp    1152 <initialPurchase+0x32>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
call   1040 <spendThisMuch@plt>
test   %eax,%eax
js     11b0 <initialPurchase+0x90>
mov    %eax,0x4(%r14)
jmp    1150 <initialPurchase+0x30>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1040 <spendThisMuch@plt>
test   %eax,%eax
js     11d0 <initialPurchase+0xb0>
mov    %eax,0x8(%r14)
jmp    1150 <initialPurchase+0x30>
mov    %rbp,%rdi
call   1030 <puts@plt>
nop
mov    $0x3,%edi
call   1040 <spendThisMuch@plt>
test   %eax,%eax
js     11f0 <initialPurchase+0xd0>
mov    %eax,0xc(%r14)
jmp    1150 <initialPurchase+0x30>
mov    %r15,%rdi
call   1030 <puts@plt>
nop
mov    $0x4,%edi
call   1040 <spendThisMuch@plt>
test   %eax,%eax
js     1210 <initialPurchase+0xf0>
mov    %eax,0x10(%r14)
jmp    1150 <initialPurchase+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON YOUR OXEN TEAM\00"
@.str.1 = [44 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON AMMUNITION\00"
@.str.2 = [42 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON CLOTHING\00"
@.str.3 = [38 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON FOOD\00"
@.str.4 = [55 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON MISCELANEOUS SUPPLIES\00"
define i32 @initialPurchase(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 700, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %87, %1
%7 = load i32, i32* %5
%8 = icmp sle i32 %7, 4
br i1 %8, label %9, label %90
9: ; preds = %6
%10 = load i32, i32* %5
switch i32 %10, label %86 [
i32 0, label %11
i32 1, label %30
i32 2, label %44
i32 3, label %58
i32 4, label %72
]
11: ; preds = %9
%12 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %21, %11
%14 = call i32 @spendThisMuch(i32 0)
store i32 %14, i32* %3
br label %15
15: ; preds = %13
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 200
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 300
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ true, %15 ], [ %20, %18 ]
br i1 %22, label %13, label %23
23: ; preds = %21
%24 = load i32, i32* %3
%25 = load i32*, i32** %2
%26 = getelementptr inbounds i32, i32* %25, i64 0
store i32 %24, i32* %26
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, %27
store i32 %29, i32* %4
br label %86
30: ; preds = %9
%31 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %34, %30
%33 = call i32 @spendThisMuch(i32 1)
store i32 %33, i32* %3
br label %34
34: ; preds = %32
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %32, label %37
37: ; preds = %34
%38 = load i32, i32* %3
%39 = load i32*, i32** %2
%40 = getelementptr inbounds i32, i32* %39, i64 1
store i32 %38, i32* %40
%41 = load i32, i32* %3
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, %41
store i32 %43, i32* %4
br label %86
44: ; preds = %9
%45 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %48, %44
%47 = call i32 @spendThisMuch(i32 2)
store i32 %47, i32* %3
br label %48
48: ; preds = %46
%49 = load i32, i32* %3
%50 = icmp slt i32 %49, 0
br i1 %50, label %46, label %51
51: ; preds = %48
%52 = load i32, i32* %3
%53 = load i32*, i32** %2
%54 = getelementptr inbounds i32, i32* %53, i64 2
store i32 %52, i32* %54
%55 = load i32, i32* %3
%56 = load i32, i32* %4
%57 = sub nsw i32 %56, %55
store i32 %57, i32* %4
br label %86
58: ; preds = %9
%59 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %62, %58
%61 = call i32 @spendThisMuch(i32 3)
store i32 %61, i32* %3
br label %62
62: ; preds = %60
%63 = load i32, i32* %3
%64 = icmp slt i32 %63, 0
br i1 %64, label %60, label %65
65: ; preds = %62
%66 = load i32, i32* %3
%67 = load i32*, i32** %2
%68 = getelementptr inbounds i32, i32* %67, i64 3
store i32 %66, i32* %68
%69 = load i32, i32* %3
%70 = load i32, i32* %4
%71 = sub nsw i32 %70, %69
store i32 %71, i32* %4
br label %86
72: ; preds = %9
%73 = call i32 @puts(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %76, %72
%75 = call i32 @spendThisMuch(i32 4)
store i32 %75, i32* %3
br label %76
76: ; preds = %74
%77 = load i32, i32* %3
%78 = icmp slt i32 %77, 0
br i1 %78, label %74, label %79
79: ; preds = %76
%80 = load i32, i32* %3
%81 = load i32*, i32** %2
%82 = getelementptr inbounds i32, i32* %81, i64 4
store i32 %80, i32* %82
%83 = load i32, i32* %3
%84 = load i32, i32* %4
%85 = sub nsw i32 %84, %83
store i32 %85, i32* %4
br label %86
86: ; preds = %9, %79, %65, %51, %37, %23
br label %87
87: ; preds = %86
%88 = load i32, i32* %5
%89 = add nsw i32 %88, 1
store i32 %89, i32* %5
br label %6
90: ; preds = %6
%91 = load i32, i32* %4
ret i32 %91
}

LLVM IR (-O2):
@.str = [48 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON YOUR OXEN TEAM\00"
@.str.1 = [44 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON AMMUNITION\00"
@.str.2 = [42 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON CLOTHING\00"
@.str.3 = [38 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON FOOD\00"
@.str.4 = [55 x i8] c"HOW MUCH DO YOU WANT TO SPEND ON MISCELANEOUS SUPPLIES\00"
define i32 @initialPurchase(i32* nocapture writeonly %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 4
%3 = getelementptr inbounds i32, i32* %0, i64 3
%4 = getelementptr inbounds i32, i32* %0, i64 2
%5 = getelementptr inbounds i32, i32* %0, i64 1
br label %7
6: ; preds = %46
ret i32 %47
7: ; preds = %1, %46
%8 = phi i32 [ 0, %1 ], [ %48, %46 ]
%9 = phi i32 [ 700, %1 ], [ %47, %46 ]
switch i32 %8, label %46 [
i32 0, label %10
i32 1, label %18
i32 2, label %25
i32 3, label %32
i32 4, label %39
]
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %12, %10
%13 = tail call i32 @spendThisMuch(i32 0)
%14 = add i32 %13, -301
%15 = icmp ult i32 %14, -101
br i1 %15, label %12, label %16
16: ; preds = %12
store i32 %13, i32* %0
%17 = sub nsw i32 %9, %13
br label %46
18: ; preds = %7
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %20, %18
%21 = tail call i32 @spendThisMuch(i32 1)
%22 = icmp slt i32 %21, 0
br i1 %22, label %20, label %23
23: ; preds = %20
store i32 %21, i32* %5
%24 = sub nsw i32 %9, %21
br label %46
25: ; preds = %7
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %27, %25
%28 = tail call i32 @spendThisMuch(i32 2)
%29 = icmp slt i32 %28, 0
br i1 %29, label %27, label %30
30: ; preds = %27
store i32 %28, i32* %4
%31 = sub nsw i32 %9, %28
br label %46
32: ; preds = %7
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %34, %32
%35 = tail call i32 @spendThisMuch(i32 3)
%36 = icmp slt i32 %35, 0
br i1 %36, label %34, label %37
37: ; preds = %34
store i32 %35, i32* %3
%38 = sub nsw i32 %9, %35
br label %46
39: ; preds = %7
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %41, %39
%42 = tail call i32 @spendThisMuch(i32 4)
%43 = icmp slt i32 %42, 0
br i1 %43, label %41, label %44
44: ; preds = %41
store i32 %42, i32* %2
%45 = sub nsw i32 %9, %42
br label %46
46: ; preds = %16, %23, %30, %37, %44, %7
%47 = phi i32 [ %9, %7 ], [ %45, %44 ], [ %38, %37 ], [ %31, %30 ], [ %24, %23 ], [ %17, %16 ]
%48 = add nuw nsw i32 %8, 1
%49 = icmp eq i32 %48, 5
br i1 %49, label %6, label %7
}