#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 knapSack(int, int *, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int wt[] = {11, 7, 5, 4, 3, 3, 2, 2, 2, 2, 1};
  int v[] = {20, 10, 11, 5, 25, 50, 12, 6, 4, 5, 30};
  int W = 20;
  int n = 11;
  printf("Optimal value => %d\n", knapSack(W, wt, v, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x2c,%edx
call   1040 <memcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xed1(%rip),%rsi
mov    $0x2c,%edx
call   1040 <memcpy@plt>
movl   $0x14,-0x64(%rbp)
movl   $0xb,-0x68(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%ecx
call   1050 <knapSack@plt>
mov    %eax,%esi
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
movups 0xef1(%rip),%xmm0
movups %xmm0,0x4c(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xefd(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x30(%rsp),%rsi
mov    %rsp,%rdx
mov    $0x14,%edi
mov    $0xb,%ecx
call   1040 <knapSack@plt>
lea    0xed3(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@__const.main.wt = [11 x i32] [i32 11, i32 7, i32 5, i32 4, i32 3, i32 3, i32 2, i32 2, i32 2, i32 2, i32 1]
@__const.main.v = [11 x i32] [i32 20, i32 10, i32 11, i32 5, i32 25, i32 50, i32 12, i32 6, i32 4, i32 5, i32 30]
@.str = [21 x i8] c"Optimal value => %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i32]
%3 = alloca [11 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [11 x i32]* %2 to i8*
%7 = bitcast [11 x i32]* %3 to i8*
store i32 20, i32* %4
store i32 11, i32* %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [11 x i32], [11 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 0
%11 = load i32, i32* %5
%12 = call i32 @knapSack(i32 %8, i32* %9, i32* %10, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %12)
ret i32 0
}

LLVM IR (-O2):
@__const.main.wt = [11 x i32] [i32 11, i32 7, i32 5, i32 4, i32 3, i32 3, i32 2, i32 2, i32 2, i32 2, i32 1]
@__const.main.v = [11 x i32] [i32 20, i32 10, i32 11, i32 5, i32 25, i32 50, i32 12, i32 6, i32 4, i32 5, i32 30]
@.str = [21 x i8] c"Optimal value => %d\0A\00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = alloca [11 x i32]
%3 = bitcast [11 x i32]* %1 to i8*
%4 = bitcast [11 x i32]* %2 to i8*
%5 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %2, i64 0, i64 0
%7 = call i32 @knapSack(i32 20, i32* %5, i32* %6, i32 11)
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
ret i32 0
}