int main(int argc, char **argv) {
  int *weights;
  unsigned int *values;
  unsigned int num_items;
  int capacity;
  unsigned int max_value;
  if (argc == 2) {
    readFile(argv[1], &weights, &values, &num_items, &capacity);
    max_value = knapsack(weights, values, num_items, capacity, 0);
    printf("%u\n", max_value);
    free(weights);
    free(values);
  } else {
    printf("Usage: knapsack.out arg_file\n");
  }
  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)
jne    11c2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
mov    $0x0,%al
call   1060 <readFile@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
xor    %r8d,%r8d
mov    $0x0,%al
call   1050 <knapsack@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11d0 <main+0x90>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11b7 <main+0x67>
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
xor    %eax,%eax
call   1070 <readFile@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <knapsack@plt>
lea    0xe68(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    11c3 <main+0x73>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%u\0A\00"
@.str.1 = [30 x i8] c"Usage: knapsack.out arg_file\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
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %29
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 (i8*, i32**, i32**, i32*, i32*, ...) bitcast (i32 (...)* @readFile to i32 (i8*, i32**, i32**, i32*, i32*, ...)*)(i8* %16, i32** %6, i32** %7, i32* %8, i32* %9)
%18 = load i32*, i32** %6
%19 = load i32*, i32** %7
%20 = load i32, i32* %8
%21 = load i32, i32* %9
%22 = call i32 (i32*, i32*, i32, i32, i32, ...) bitcast (i32 (...)* @knapsack to i32 (i32*, i32*, i32, i32, i32, ...)*)(i32* %18, i32* %19, i32 %20, i32 %21, i32 0)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %6
%26 = bitcast i32* %25 to i8*
%27 = load i32*, i32** %7
%28 = bitcast i32* %27 to i8*
br label %31
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u\0A\00"
@str = [29 x i8] c"Usage: knapsack.out arg_file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32** %3 to i8*
%8 = bitcast i32** %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %26
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i32**, i32**, i32*, i32*, ...) bitcast (i32 (...)* @readFile to i32 (i8*, i32**, i32**, i32*, i32*, ...)*)(i8* %14, i32** %3, i32** %4, i32* %5, i32* %6)
%16 = load i32*, i32** %3
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = call i32 (i32*, i32*, i32, i32, i32, ...) bitcast (i32 (...)* @knapsack to i32 (i32*, i32*, i32, i32, i32, ...)*)(i32* %16, i32* %17, i32 %18, i32 %19, i32 0)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = bitcast i32** %3 to i8**
%23 = load i8*, i8** %22
%24 = bitcast i32** %4 to i8**
%25 = load i8*, i8** %24
br label %28
26: ; preds = %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %26, %12
ret i32 0
}