#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*/ print_list(int *, int);
int /*<<< orphan*/ printf(char *, int, int);
int purchased_toys(int, int *, int);
int rand();
int main() {
  int num_items = 15;
  int toys[15];
  int money;
  int i;
  for (i = 0; i < num_items; i++) {
    toys[i] = rand() % 1000;
  }
  print_list(toys, num_items);
  money = 0;
  printf("%d toys can be bought with %d credits\n",
         purchased_toys(num_items, toys, money), money);
  money = 100;
  printf("%d toys can be bought with %d credits\n",
         purchased_toys(num_items, toys, money), money);
  money = 2000;
  printf("%d toys can be bought with %d credits\n",
         purchased_toys(num_items, toys, money), money);
  money = 10000;
  printf("%d toys can be bought with %d credits\n",
         purchased_toys(num_items, toys, money), money);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf,-0x8(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    118e <main+0x4e>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq -0x58(%rbp),%rax
mov    %edx,-0x50(%rbp,%rax,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    115d <main+0x1d>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <print_list@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <purchased_toys@plt>
mov    %eax,%esi
mov    -0x54(%rbp),%edx
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
movl   $0x64,-0x54(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <purchased_toys@plt>
mov    %eax,%esi
mov    -0x54(%rbp),%edx
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x7d0,-0x54(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <purchased_toys@plt>
mov    %eax,%esi
mov    -0x54(%rbp),%edx
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2710,-0x54(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1030 <purchased_toys@plt>
mov    %eax,%esi
mov    -0x54(%rbp),%edx
lea    0xdcf(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x14(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x18(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x1c(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x20(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x24(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x28(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x2c(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x30(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x34(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x6,%ecx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x38(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
call   1040 <print_list@plt>
mov    $0xf,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <purchased_toys@plt>
lea    0xc00(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <printf@plt>
mov    $0xf,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1030 <purchased_toys@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x64,%edx
call   1050 <printf@plt>
mov    $0xf,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
call   1030 <purchased_toys@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x7d0,%edx
call   1050 <printf@plt>
mov    $0xf,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1030 <purchased_toys@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x2710,%edx
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [39 x i8] c"%d toys can be bought with %d credits\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [15 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 15, i32* %2
store i32 0, i32* %5
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 1000
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %6
19: ; preds = %6
%20 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 0
%21 = load i32, i32* %2
%22 = call i32 @print_list(i32* %20, i32 %21)
store i32 0, i32* %4
%23 = load i32, i32* %2
%24 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 0
%25 = load i32, i32* %4
%26 = call i32 @purchased_toys(i32 %23, i32* %24, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
store i32 100, i32* %4
%29 = load i32, i32* %2
%30 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 0
%31 = load i32, i32* %4
%32 = call i32 @purchased_toys(i32 %29, i32* %30, i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33)
store i32 2000, i32* %4
%35 = load i32, i32* %2
%36 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 0
%37 = load i32, i32* %4
%38 = call i32 @purchased_toys(i32 %35, i32* %36, i32 %37)
%39 = load i32, i32* %4
%40 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39)
store i32 10000, i32* %4
%41 = load i32, i32* %2
%42 = getelementptr inbounds [15 x i32], [15 x i32]* %3, i64 0, i64 0
%43 = load i32, i32* %4
%44 = call i32 @purchased_toys(i32 %41, i32* %42, i32 %43)
%45 = load i32, i32* %4
%46 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %44, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"%d toys can be bought with %d credits\0A\00"
define i32 @main() {
%1 = alloca [15 x i32]
%2 = bitcast [15 x i32]* %1 to i8*
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 1000
%5 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 0
store i32 %4, i32* %5
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 1000
%8 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 1
store i32 %7, i32* %8
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 1000
%11 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 2
store i32 %10, i32* %11
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 1000
%14 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 3
store i32 %13, i32* %14
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 1000
%17 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 4
store i32 %16, i32* %17
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 1000
%20 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 5
store i32 %19, i32* %20
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 1000
%23 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 6
store i32 %22, i32* %23
%24 = tail call i32 (...) @rand()
%25 = srem i32 %24, 1000
%26 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 7
store i32 %25, i32* %26
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 1000
%29 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 8
store i32 %28, i32* %29
%30 = tail call i32 (...) @rand()
%31 = srem i32 %30, 1000
%32 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 9
store i32 %31, i32* %32
%33 = tail call i32 (...) @rand()
%34 = srem i32 %33, 1000
%35 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 10
store i32 %34, i32* %35
%36 = tail call i32 (...) @rand()
%37 = srem i32 %36, 1000
%38 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 11
store i32 %37, i32* %38
%39 = tail call i32 (...) @rand()
%40 = srem i32 %39, 1000
%41 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 12
store i32 %40, i32* %41
%42 = tail call i32 (...) @rand()
%43 = srem i32 %42, 1000
%44 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 13
store i32 %43, i32* %44
%45 = tail call i32 (...) @rand()
%46 = srem i32 %45, 1000
%47 = getelementptr inbounds [15 x i32], [15 x i32]* %1, i64 0, i64 14
store i32 %46, i32* %47
%48 = call i32 @print_list(i32* %5, i32 15)
%49 = call i32 @purchased_toys(i32 15, i32* %5, i32 0)
%50 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %49, i32 0)
%51 = call i32 @purchased_toys(i32 15, i32* %5, i32 100)
%52 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %51, i32 100)
%53 = call i32 @purchased_toys(i32 15, i32* %5, i32 2000)
%54 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %53, i32 2000)
%55 = call i32 @purchased_toys(i32 15, i32* %5, i32 10000)
%56 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %55, i32 10000)
ret i32 0
}