#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 */
typedef int /*<<< orphan*/ wt;

/* Variables and functions */
int knapsack(int *, int *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void main() {
  int wt[] = {10, 20, 30};
  int val[] = {60, 100, 120};
  int cap = 50;
  int len = sizeof(wt) / sizeof(wt[0]);
  int res = knapsack(wt, val, len - 1, cap, 0);
  printf("Max value is %d", res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    0xec9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec7(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x32,-0x1c(%rbp)
movl   $0x3,-0x20(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
xor    %r8d,%r8d
call   1040 <knapsack@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xede(%rip),%eax
mov    %eax,0x20(%rsp)
mov    0xecb(%rip),%rax
mov    %rax,0x18(%rsp)
mov    0xed4(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xec1(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x2,%edx
mov    $0x32,%ecx
xor    %r8d,%r8d
call   1040 <knapsack@plt>
lea    0xea5(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.wt = [3 x i32] [i32 10, i32 20, i32 30]
@__const.main.val = [3 x i32] [i32 60, i32 100, i32 120]
@.str = [16 x i8] c"Max value is %d\00"
define void @main() {
%1 = alloca [3 x i32]
%2 = alloca [3 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [3 x i32]* %1 to i8*
%7 = bitcast [3 x i32]* %2 to i8*
store i32 50, i32* %3
store i32 3, i32* %4
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = load i32, i32* %3
%13 = call i32 @knapsack(i32* %8, i32* %9, i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
ret void
}

LLVM IR (-O2):
@__const.main.wt = [3 x i32] [i32 10, i32 20, i32 30]
@__const.main.val = [3 x i32] [i32 60, i32 100, i32 120]
@.str = [16 x i8] c"Max value is %d\00"
define void @main() {
%1 = alloca [3 x i32]
%2 = alloca [3 x i32]
%3 = bitcast [3 x i32]* %1 to i8*
%4 = bitcast [3 x i32]* %2 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%7 = call i32 @knapsack(i32* %5, i32* %6, i32 2, i32 50, i32 0)
%8 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
ret void
}