#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 i;
  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,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11f9 <main+0xb9>
movslq -0x74(%rbp),%rax
lea    -0x70(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe35(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11c4 <main+0x84>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1241 <main+0x101>
movslq -0x74(%rbp),%rax
lea    -0x40(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xded(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [10 x i32]* %8 to i8*
%12 = bitcast [10 x i32]* %9 to i8*
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %10
br label %18
18: ; preds = %27, %2
%19 = load i32, i32* %10
%20 = load i32, i32* %6
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %22
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %18
30: ; preds = %18
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %10
br label %32
32: ; preds = %41, %30
%33 = load i32, i32* %10
%34 = load i32, i32* %6
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %38
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %39)
br label %41
41: ; preds = %36
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %32
44: ; preds = %32
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 0
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %9, i64 0, i64 0
%49 = call i32 @Knapsack(i32 %45, i32 %46, i32* %47, i32* %48)
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
}