#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 atoi(char *);
int coinChange(int *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: ./test 11 1 2 5");
    exit(-1);
  }
  int amount = atoi(argv[1]);
  int i, size = argc - 2;
  int *coins = malloc(size * sizeof(int));
  for (i = 0; i < size; i++) {
    coins[i] = atoi(argv[i + 2]);
  }
  printf("%d\n", coinChange(coins, size, amount));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d2 <main+0x72>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <coinChange@plt>
mov    %eax,%esi
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jle    11dd <main+0x7d>
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    %ebx,%r12d
add    $0xfffffffe,%r12d
lea    -0x8(,%rbx,4),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%r15,%rbp,8),%rdi
call   1070 <atoi@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11a0 <main+0x40>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1030 <coinChange@plt>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: ./test 11 1 2 5\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 2
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 4
%26 = trunc i64 %25 to i32
%27 = call i32* @malloc(i32 %26)
store i32* %27, i32** %9
store i32 0, i32* %7
br label %28
28: ; preds = %44, %16
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = load i32*, i32** %9
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
store i32 %39, i32* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %28
47: ; preds = %28
%48 = load i32*, i32** %9
%49 = load i32, i32* %8
%50 = load i32, i32* %6
%51 = call i32 @coinChange(i32* %48, i32 %49, i32 %50)
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: ./test 11 1 2 5\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = add nsw i32 %0, -2
%13 = shl i32 %12, 2
%14 = tail call i32* @malloc(i32 %13)
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %8, %16
%17 = phi i64 [ 0, %8 ], [ %23, %16 ]
%18 = add nuw nsw i64 %17, 2
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = getelementptr inbounds i32, i32* %14, i64 %17
store i32 %21, i32* %22
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %16
25: ; preds = %16
%26 = tail call i32 @coinChange(i32* %14, i32 %12, i32 %11)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
}