#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 coinChange2(int *, int, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("changeCoins <amount> [coin1, coint2,...]\n");
    return 0;
  }
  int i;
  int amount = atoi(argv[1]);
  int *coins = (int *)malloc(sizeof(int) * (argc - 2));
  for (i = 0; i < argc - 2; i++) {
    coins[i] = atoi(argv[i + 2]);
  }
  printf("Result: %d\t%d\n", coinChange(coins, argc - 2, amount),
         coinChange2(coins, argc - 2, amount));
  free(coins);
  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   $0x2,-0x8(%rbp)
jge    119a <main+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1254 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    120a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <main+0x68>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x2,%esi
mov    -0x18(%rbp),%edx
call   1040 <coinChange@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x2,%esi
mov    -0x18(%rbp),%edx
call   1060 <coinChange2@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1191 <main+0x21>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
jmp    1222 <main+0xb2>
mov    %rsi,%r14
mov    %edi,%r12d
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,0x4(%rsp)
lea    -0x2(%r12),%r15d
lea    -0x8(,%r12,4),%edi
ff
call   1080 <malloc@plt>
mov    %rax,%r13
cmp    $0x2,%r12d
je     11e8 <main+0x78>
mov    %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%r14,%rbp,8),%rdi
call   1090 <atoi@plt>
mov    %eax,0x0(%r13,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <main+0x60>
mov    %r13,%rdi
mov    %r15d,%esi
mov    0x4(%rsp),%ebx
mov    %ebx,%edx
call   1050 <coinChange@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1070 <coinChange2@plt>
lea    0xdf1(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"changeCoins <amount> [coin1, coint2,...]\0A\00"
@.str.1 = [15 x i8] c"Result: %d\09%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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %59
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %8
store i32 0, i32* %6
br label %25
25: ; preds = %42, %13
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = sub nsw i32 %27, 2
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %45
30: ; preds = %25
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %31, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = load i32*, i32** %8
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %30
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %25
45: ; preds = %25
%46 = load i32*, i32** %8
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 2
%49 = load i32, i32* %7
%50 = call i32 @coinChange(i32* %46, i32 %48, i32 %49)
%51 = load i32*, i32** %8
%52 = load i32, i32* %4
%53 = sub nsw i32 %52, 2
%54 = load i32, i32* %7
%55 = call i32 @coinChange2(i32* %51, i32 %53, i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %55)
%57 = load i32*, i32** %8
%58 = call i32 @free(i32* %57)
store i32 0, i32* %3
br label %59
59: ; preds = %45, %11
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"Result: %d\09%d\0A\00"
@str = [41 x i8] c"changeCoins <amount> [coin1, coint2,...]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %31
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = add nsw i32 %0, -2
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
%14 = icmp eq i32 %0, 2
br i1 %14, label %26, label %15
15: ; preds = %6
%16 = zext i32 %10 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %24, %17 ]
%19 = add nuw nsw i64 %18, 2
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i32, i32* %13, i64 %18
store i32 %22, i32* %23
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %16
br i1 %25, label %26, label %17
26: ; preds = %17, %6
%27 = tail call i32 @coinChange(i32* %13, i32 %10, i32 %9)
%28 = tail call i32 @coinChange2(i32* %13, i32 %10, i32 %9)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
%30 = tail call i32 @free(i32* %13)
br label %31
31: ; preds = %26, %4
ret i32 0
}