#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*/ Knapsack(int, int, int *, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int no, wt, pt[10] = {0}, weight[10] = {0};
  int max_profit, i, j;
  printf("Enter the no of objects :\n");
  scanf("%d", &no);
  printf("Enter the total weight :\n");
  scanf("%d", &wt);
  printf("Enter the weights\n");
  for (i = 1; i <= no; i++)
    scanf("%d", &weight[i]);
  printf("Enter the profits\n");
  for (i = 1; i <= no; i++)
    scanf("%d", &pt[i]);
  Knapsack(no, wt, pt, weight);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
lea    0xe73(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11f9 <main+0xb9>
movslq -0x78(%rbp),%rax
lea    -0x70(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe35(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    11c4 <main+0x84>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1241 <main+0x101>
movslq -0x78(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xded(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    120c <main+0xcc>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1040 <Knapsack@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movq   $0x0,0x60(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0x8(%rsp)
jle    11dd <main+0xad>
lea    0x14(%rsp),%r15
xor    %ebx,%ebx
lea    0xe44(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq 0x8(%rsp),%rax
add    $0x1,%rbx
add    $0x4,%r15
cmp    %rax,%rbx
jl     11c0 <main+0x90>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
jle    121d <main+0xed>
lea    0x44(%rsp),%r15
xor    %ebx,%ebx
lea    0xe01(%rip),%r14
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq 0x8(%rsp),%rdi
add    $0x1,%rbx
add    $0x4,%r15
cmp    %rdi,%rbx
jl     1200 <main+0xd0>
mov    0xc(%rsp),%esi
lea    0x40(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1040 <Knapsack@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter the no of objects :\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"Enter the total weight :\0A\00"
@.str.3 = [19 x i8] c"Enter the weights\0A\00"
@.str.4 = [19 x i8] c"Enter the profits\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 [10 x i32]
%9 = alloca [10 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [10 x i32]* %8 to i8*
%14 = bitcast [10 x i32]* %9 to i8*
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %11
br label %20
20: ; preds = %29, %2
%21 = load i32, i32* %11
%22 = load i32, i32* %6
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %24
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %20
32: ; preds = %20
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %11
br label %34
34: ; preds = %43, %32
%35 = load i32, i32* %11
%36 = load i32, i32* %6
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %40
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %41)
br label %43
43: ; preds = %38
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %34
46: ; preds = %34
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 0
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%51 = call i32 @Knapsack(i32 %47, i32 %48, i32* %49, i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [26 x i8] c"Enter the no of objects :\00"
@str.5 = [25 x i8] c"Enter the total weight :\00"
@str.6 = [18 x i8] c"Enter the weights\00"
@str.7 = [18 x i8] c"Enter the profits\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i32]
%6 = alloca [10 x i32]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast [10 x i32]* %5 to i8*
%10 = bitcast [10 x i32]* %6 to i8*
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 1
br i1 %17, label %26, label %18
18: ; preds = %2, %18
%19 = phi i64 [ %22, %18 ], [ 1, %2 ]
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %19, %24
br i1 %25, label %18, label %26
26: ; preds = %18, %2
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 1
br i1 %29, label %38, label %30
30: ; preds = %26, %30
%31 = phi i64 [ %34, %30 ], [ 1, %26 ]
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %32)
%34 = add nuw nsw i64 %31, 1
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %31, %36
br i1 %37, label %30, label %38
38: ; preds = %30, %26
%39 = phi i32 [ %28, %26 ], [ %35, %30 ]
%40 = load i32, i32* %4
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%42 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%43 = call i32 @Knapsack(i32 %39, i32 %40, i32* %41, i32* %42)
ret i32 0
}