#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*/ free(int *);
int /*<<< orphan*/ knapsack_greedy(int *, int *, int *, int, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int *weight, *value, *pick;
  int size_sack;
  int size_elem;
  int i, sum_w = 0, sum_v = 0;
  printf("Knapsack Greedy\n");
  printf("---------------\n\n");
  printf("Give max size of sack:");
  scanf("%d", &size_sack);
  printf("\nGive size of total elements:");
  scanf("%d", &size_elem);
  weight = malloc(size_elem * sizeof(int));
  if (weight == NULL)
    return 1;
  value = malloc(size_elem * sizeof(int));
  if (value == NULL)
    return 1;
  pick = malloc(size_elem * sizeof(int));
  if (pick == NULL)
    return 1;
  for (i = 0; i < size_elem; i++)
    pick[i] = 0;
  for (i = 0; i < size_elem; i++) {
    printf("Give weight for %d element:", i + 1);
    scanf("%d", &weight[i]);
    printf("\nGive value for %d element:", i + 1);
    scanf("%d", &value[i]);
  }
  printf("\n");
  knapsack_greedy(weight, pick, value, size_sack, size_elem);
  printf("Elements inside sack:");
  printf("\n\n");
  for (i = 0; i < size_elem; i++) {
    if (pick[i] == 1) {
      sum_w += weight[i];
      sum_v += value[i];
      printf("Element %d is inside with weight %d and value %d\n", i + 1,
             weight[i], value[i]);
    }
  }
  if (sum_w == 0)
    printf("There aren't elements indise sack!!\n");
  else
    printf("Finally our elements inside sack weight %d and we have earned %d\n",
           sum_w, sum_v);
  free(weight);
  free(pick);
  free(value);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <main+0x9f>
movl   $0x1,-0x4(%rbp)
jmp    140b <main+0x2bb>
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1219 <main+0xc9>
movl   $0x1,-0x4(%rbp)
jmp    140b <main+0x2bb>
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1243 <main+0xf3>
movl   $0x1,-0x4(%rbp)
jmp    140b <main+0x2bb>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1273 <main+0x123>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124a <main+0xfa>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12f2 <main+0x1a2>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd8a(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd5b(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    127a <main+0x12a>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1070 <knapsack_greedy@plt>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13b8 <main+0x268>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    13a5 <main+0x255>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13aa <main+0x25a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    133b <main+0x1eb>
cmpl   $0x0,-0x30(%rbp)
jne    13d5 <main+0x285>
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13e9 <main+0x299>
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xf65(%rip),%rdi
call   1050 <puts@plt>
lea    0xf69(%rip),%rdi
call   1050 <puts@plt>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5c(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
mov    0x8(%rsp),%r14d
lea    0x0(,%r14,4),%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     13a9 <main+0x229>
mov    %rax,%rbp
mov    %ebx,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     13a9 <main+0x229>
mov    %rax,%r12
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
je     13a9 <main+0x229>
mov    %r12,0x10(%rsp)
mov    %rbp,0x18(%rsp)
test   %r14d,%r14d
jle    12c6 <main+0x146>
shl    $0x2,%r14
mov    0x20(%rsp),%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1070 <memset@plt>
lea    0xdda(%rip),%r13
lea    0xdb2(%rip),%rbp
lea    0xde8(%rip),%rbx
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r14
xor    %r12d,%r12d
nopl   0x0(%rax)
add    $0x1,%r12
mov    %r13,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
movslq 0x8(%rsp),%rax
add    $0x4,%r14
add    $0x4,%r15
cmp    %rax,%r12
jl     1280 <main+0x100>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x18(%rsp),%r14
mov    %r14,%rdi
mov    0x20(%rsp),%r12
mov    %r12,%rsi
mov    0x10(%rsp),%r15
mov    %r15,%rdx
call   10a0 <knapsack_greedy@plt>
lea    0xd73(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0e(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    1382 <main+0x202>
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    135d <main+0x1dd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%r13,4),%edx
add    %edx,%ebx
mov    (%r15,%r13,4),%ecx
add    %ecx,%ebp
add    $0x1,%r13
lea    0xd3f(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%eax
movslq %eax,%rcx
cmp    %rcx,%r13
jge    136a <main+0x1ea>
cmpl   $0x1,(%r12,%r13,4)
je     1330 <main+0x1b0>
add    $0x1,%r13
jmp    1355 <main+0x1d5>
test   %ebx,%ebx
je     1382 <main+0x202>
lea    0xd43(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    138e <main+0x20e>
lea    0xd92(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Knapsack Greedy\0A\00"
@.str.1 = [18 x i8] c"---------------\0A\0A\00"
@.str.2 = [23 x i8] c"Give max size of sack:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [30 x i8] c"\0AGive size of total elements:\00"
@.str.5 = [28 x i8] c"Give weight for %d element:\00"
@.str.6 = [28 x i8] c"\0AGive value for %d element:\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [22 x i8] c"Elements inside sack:\00"
@.str.9 = [3 x i8] c"\0A\0A\00"
@.str.10 = [50 x i8] c"Element %d is inside with weight %d and value %d\0A\00"
@.str.11 = [37 x i8] c"There aren't elements indise sack!!\0A\00"
@.str.12 = [66 x i8] c"Finally our elements inside sack weight %d and we have earned %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
store i32 0, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i32* @malloc(i32 %19)
store i32* %20, i32** %2
%21 = load i32*, i32** %2
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %0
store i32 1, i32* %1
br label %149
24: ; preds = %0
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i32* @malloc(i32 %28)
store i32* %29, i32** %3
%30 = load i32*, i32** %3
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %24
store i32 1, i32* %1
br label %149
33: ; preds = %24
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i32* @malloc(i32 %37)
store i32* %38, i32** %4
%39 = load i32*, i32** %4
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %1
br label %149
42: ; preds = %33
store i32 0, i32* %7
br label %43
43: ; preds = %52, %42
%44 = load i32, i32* %7
%45 = load i32, i32* %6
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i32*, i32** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
store i32 0, i32* %51
br label %52
52: ; preds = %47
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %43
55: ; preds = %43
store i32 0, i32* %7
br label %56
56: ; preds = %77, %55
%57 = load i32, i32* %7
%58 = load i32, i32* %6
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %80
60: ; preds = %56
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %2
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %67)
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = load i32*, i32** %3
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %75)
br label %77
77: ; preds = %60
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %56
80: ; preds = %56
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%82 = load i32*, i32** %2
%83 = load i32*, i32** %4
%84 = load i32*, i32** %3
%85 = load i32, i32* %5
%86 = load i32, i32* %6
%87 = call i32 @knapsack_greedy(i32* %82, i32* %83, i32* %84, i32 %85, i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %7
br label %90
90: ; preds = %130, %80
%91 = load i32, i32* %7
%92 = load i32, i32* %6
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %133
94: ; preds = %90
%95 = load i32*, i32** %4
%96 = load i32, i32* %7
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %95, i64 %97
%99 = load i32, i32* %98
%100 = icmp eq i32 %99, 1
br i1 %100, label %101, label %129
101: ; preds = %94
%102 = load i32*, i32** %2
%103 = load i32, i32* %7
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %102, i64 %104
%106 = load i32, i32* %105
%107 = load i32, i32* %8
%108 = add nsw i32 %107, %106
store i32 %108, i32* %8
%109 = load i32*, i32** %3
%110 = load i32, i32* %7
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %109, i64 %111
%113 = load i32, i32* %112
%114 = load i32, i32* %9
%115 = add nsw i32 %114, %113
store i32 %115, i32* %9
%116 = load i32, i32* %7
%117 = add nsw i32 %116, 1
%118 = load i32*, i32** %2
%119 = load i32, i32* %7
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i32, i32* %118, i64 %120
%122 = load i32, i32* %121
%123 = load i32*, i32** %3
%124 = load i32, i32* %7
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i32, i32* %123, i64 %125
%127 = load i32, i32* %126
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %117, i32 %122, i32 %127)
br label %129
129: ; preds = %101, %94
br label %130
130: ; preds = %129
%131 = load i32, i32* %7
%132 = add nsw i32 %131, 1
store i32 %132, i32* %7
br label %90
133: ; preds = %90
%134 = load i32, i32* %8
%135 = icmp eq i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %133
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
br label %142
138: ; preds = %133
%139 = load i32, i32* %8
%140 = load i32, i32* %9
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.12, i64 0, i64 0), i32 %139, i32 %140)
br label %142
142: ; preds = %138, %136
%143 = load i32*, i32** %2
%144 = call i32 @free(i32* %143)
%145 = load i32*, i32** %4
%146 = call i32 @free(i32* %145)
%147 = load i32*, i32** %3
%148 = call i32 @free(i32* %147)
store i32 0, i32* %1
br label %149
149: ; preds = %142, %41, %32, %23
%150 = load i32, i32* %1
ret i32 %150
}

LLVM IR (-O2):
@.str.2 = [23 x i8] c"Give max size of sack:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [30 x i8] c"\0AGive size of total elements:\00"
@.str.5 = [28 x i8] c"Give weight for %d element:\00"
@.str.6 = [28 x i8] c"\0AGive value for %d element:\00"
@.str.8 = [22 x i8] c"Elements inside sack:\00"
@.str.10 = [50 x i8] c"Element %d is inside with weight %d and value %d\0A\00"
@.str.12 = [66 x i8] c"Finally our elements inside sack weight %d and we have earned %d\0A\00"
@str = [16 x i8] c"Knapsack Greedy\00"
@str.13 = [17 x i8] c"---------------\0A\00"
@str.14 = [2 x i8] c"\0A\00"
@str.15 = [36 x i8] c"There aren't elements indise sack!!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.13, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = shl i32 %11, 2
%13 = call i32* @malloc(i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %87, label %15
15: ; preds = %0
%16 = call i32* @malloc(i32 %12)
%17 = icmp eq i32* %16, null
br i1 %17, label %87, label %18
18: ; preds = %15
%19 = call i32* @malloc(i32 %12)
%20 = bitcast i32* %19 to i8*
%21 = icmp eq i32* %19, null
br i1 %21, label %87, label %22
22: ; preds = %18
%23 = icmp sgt i32 %11, 0
br i1 %23, label %24, label %40
24: ; preds = %22
%25 = zext i32 %11 to i64
%26 = shl nuw nsw i64 %25, 2
br label %27
27: ; preds = %24, %27
%28 = phi i64 [ 0, %24 ], [ %29, %27 ]
%29 = add nuw nsw i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i32, i32* %13, i64 %28
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%35 = getelementptr inbounds i32, i32* %16, i64 %28
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %35)
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %29, %38
br i1 %39, label %27, label %40
40: ; preds = %27, %22
%41 = call i32 @putchar(i32 10)
%42 = load i32, i32* %1
%43 = load i32, i32* %2
%44 = call i32 @knapsack_greedy(i32* %13, i32* %19, i32* %16, i32 %42, i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.14, i64 0, i64 0))
%47 = load i32, i32* %2
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %79
49: ; preds = %40, %70
%50 = phi i32 [ %72, %70 ], [ %47, %40 ]
%51 = phi i64 [ %71, %70 ], [ 0, %40 ]
%52 = phi i32 [ %74, %70 ], [ 0, %40 ]
%53 = phi i32 [ %73, %70 ], [ 0, %40 ]
%54 = getelementptr inbounds i32, i32* %19, i64 %51
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, 1
br i1 %56, label %59, label %57
57: ; preds = %49
%58 = add nuw nsw i64 %51, 1
br label %70
59: ; preds = %49
%60 = getelementptr inbounds i32, i32* %13, i64 %51
%61 = load i32, i32* %60
%62 = add nsw i32 %61, %53
%63 = getelementptr inbounds i32, i32* %16, i64 %51
%64 = load i32, i32* %63
%65 = add nsw i32 %64, %52
%66 = add nuw nsw i64 %51, 1
%67 = trunc i64 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %67, i32 %61, i32 %64)
%69 = load i32, i32* %2
br label %70
70: ; preds = %57, %59
%71 = phi i64 [ %58, %57 ], [ %66, %59 ]
%72 = phi i32 [ %50, %57 ], [ %69, %59 ]
%73 = phi i32 [ %53, %57 ], [ %62, %59 ]
%74 = phi i32 [ %52, %57 ], [ %65, %59 ]
%75 = sext i32 %72 to i64
%76 = icmp slt i64 %71, %75
br i1 %76, label %49, label %77
77: ; preds = %70
%78 = icmp eq i32 %73, 0
br i1 %78, label %79, label %81
79: ; preds = %40, %77
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.15, i64 0, i64 0))
br label %83
81: ; preds = %77
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.12, i64 0, i64 0), i32 %73, i32 %74)
br label %83
83: ; preds = %81, %79
%84 = call i32 @free(i32* %13)
%85 = call i32 @free(i32* %19)
%86 = call i32 @free(i32* %16)
br label %87
87: ; preds = %18, %15, %0, %83
%88 = phi i32 [ 0, %83 ], [ 1, %0 ], [ 1, %15 ], [ 1, %18 ]
ret i32 %88
}