#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*/ printf(char *, int);
int solveKnapsack(int, int *, int *, int);
int main() {
  int weights[8] = {2, 3, 5, 2, 4, 6, 3, 1};
  int values[8] = {5, 8, 14, 6, 13, 17, 10, 4};
  printf("Maximal value: %d\n", solveKnapsack(8, weights, values, 12));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x8,%edi
mov    $0xc,%ecx
call   1040 <solveKnapsack@plt>
mov    %eax,%esi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%rsi
mov    %rsp,%rdx
mov    $0x8,%edi
mov    $0xc,%ecx
call   1040 <solveKnapsack@plt>
lea    0xecf(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@__const.main.weights = [8 x i32] [i32 2, i32 3, i32 5, i32 2, i32 4, i32 6, i32 3, i32 1]
@__const.main.values = [8 x i32] [i32 5, i32 8, i32 14, i32 6, i32 13, i32 17, i32 10, i32 4]
@.str = [19 x i8] c"Maximal value: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i32]
%3 = alloca [8 x i32]
store i32 0, i32* %1
%4 = bitcast [8 x i32]* %2 to i8*
%5 = bitcast [8 x i32]* %3 to i8*
%6 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
%8 = call i32 @solveKnapsack(i32 8, i32* %6, i32* %7, i32 12)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
ret i32 0
}

LLVM IR (-O2):
@__const.main.weights = [8 x i32] [i32 2, i32 3, i32 5, i32 2, i32 4, i32 6, i32 3, i32 1]
@__const.main.values = [8 x i32] [i32 5, i32 8, i32 14, i32 6, i32 13, i32 17, i32 10, i32 4]
@.str = [19 x i8] c"Maximal value: %d\0A\00"
define i32 @main() {
%1 = alloca [8 x i32]
%2 = alloca [8 x i32]
%3 = bitcast [8 x i32]* %1 to i8*
%4 = bitcast [8 x i32]* %2 to i8*
%5 = getelementptr inbounds [8 x i32], [8 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%7 = call i32 @solveKnapsack(i32 8, i32* %5, i32* %6, i32 12)
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %7)
ret i32 0
}