#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ knapSack(long, long, int *, int *);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  FILE *test_file;
  int *val, *wt;
  long int Nitems;
  long int Width;
  long int cont;
  double tpivot1 = 0, tpivot2 = 0, tpivot3 = 0;
  struct timeval tim;
  if (argc != 2) {
    printf("\n\nError, mising parameters:\n");
    printf("format: test_file \n");
    return 1;
  }
  gettimeofday(&tim, NULL);
  tpivot1 = tim.tv_sec + (tim.tv_usec / 1000000.0);
  if (!(test_file = fopen(argv[1], "r"))) {
    printf("Error opening Value file: %s\n", argv[1]);
    return 1;
  }
  fscanf(test_file, "%ld %ld\n", &Nitems, &Width);
  val = (int *)malloc(Nitems * sizeof(int));
  wt = (int *)malloc(Nitems * sizeof(int));
  for (cont = 0; cont < Nitems; cont++) {
    fscanf(test_file, "%d,%d\n", &val[cont], &wt[cont]);
  }
  gettimeofday(&tim, NULL);
  tpivot2 = (tim.tv_sec + (tim.tv_usec / 1000000.0));
  printf("%ld:%ld:%d", Width, Nitems, knapSack(Width, Nitems, wt, val));
  gettimeofday(&tim, NULL);
  tpivot3 = (tim.tv_sec + (tim.tv_usec / 1000000.0));
  printf(":%.6lf:%.6lf\n", tpivot3 - tpivot2, tpivot3 - tpivot1);
  free(val);
  free(wt);
  fclose(test_file);
  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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e3 <main+0x63>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x23f>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  0xdfe(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1253 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13bf <main+0x23f>
mov    -0x18(%rbp),%rdi
lea    0xdfb(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x30(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
shl    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    12e6 <main+0x166>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x28(%rbp),%rcx
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1297 <main+0x117>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  0xcfb(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1090 <knapSack@plt>
mov    -0x78(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    %eax,%ecx
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  0xc92(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
lea    0xcde(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x2,%edi
jne    1340 <main+0x1b0>
mov    %rsi,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movsd  0x18(%rsp),%xmm0
divsd  0xe3c(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
mov    0x8(%r14),%rdi
lea    0xe45(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     135a <main+0x1ca>
mov    %rax,%r13
lea    0xe4d(%rip),%rsi
xor    %r14d,%r14d
lea    0x8(%rsp),%rdx
lea    0x38(%rsp),%rcx
mov    %rax,%rdi
xor    %eax,%eax
call   1080 <fscanf@plt>
mov    0x8(%rsp),%rdi
shl    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,0x28(%rsp)
mov    0x8(%rsp),%rdi
shl    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,0x20(%rsp)
cmpq   $0x0,0x8(%rsp)
jle    1276 <main+0xe6>
lea    0xe0a(%rip),%rbx
mov    0x28(%rsp),%rbp
mov    0x20(%rsp),%r12
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fscanf@plt>
add    $0x1,%r15
add    $0x4,%r12
add    $0x4,%rbp
cmp    0x8(%rsp),%r15
jl     1250 <main+0xc0>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0x38(%rsp),%rbp
mov    0x8(%rsp),%rbx
movsd  0x10(%rsp),%xmm0
movaps %xmm0,0x50(%rsp)
movsd  0x18(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x20(%rsp),%r12
mov    %r12,%rdx
mov    0x28(%rsp),%r15
mov    %r15,%rcx
call   10a0 <knapSack@plt>
lea    0xd8c(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movapd 0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
shufpd $0x1,0x40(%rsp),%xmm0
divpd  0xd18(%rip),%xmm0
unpcklpd 0x50(%rsp),%xmm1
addpd  %xmm0,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
subsd  0x30(%rsp),%xmm1
lea    0xd3c(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
jmp    1372 <main+0x1e2>
lea    0xd22(%rip),%rdi
call   1040 <puts@plt>
lea    0xd32(%rip),%rdi
call   1040 <puts@plt>
jmp    136c <main+0x1dc>
mov    0x8(%r14),%rsi
lea    0xcbd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [29 x i8] c"\0A\0AError, mising parameters:\0A\00"
@.str.1 = [20 x i8] c"format: test_file \0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [30 x i8] c"Error opening Value file: %s\0A\00"
@.str.4 = [9 x i8] c"%ld %ld\0A\00"
@.str.5 = [7 x i8] c"%d,%d\0A\00"
@.str.6 = [11 x i8] c"%ld:%ld:%d\00"
@.str.7 = [14 x i8] c":%.6lf:%.6lf\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 i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %102
21: ; preds = %2
%22 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%24 = load double, double* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%26 = load double, double* %25
%27 = fdiv double %26, 1.000000e+06
%28 = fadd double %24, %27
store double %28, double* %12
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %6
%33 = icmp ne i32* %32, null
br i1 %33, label %39, label %34
34: ; preds = %21
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 1, i32* %3
br label %102
39: ; preds = %21
%40 = load i32*, i32** %6
%41 = call i32 (i32*, i8*, ...) @fscanf(i32* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64* %9, i64* %10)
%42 = load i64, i64* %9
%43 = mul i64 %42, 4
%44 = call i64 @malloc(i64 %43)
%45 = inttoptr i64 %44 to i32*
store i32* %45, i32** %7
%46 = load i64, i64* %9
%47 = mul i64 %46, 4
%48 = call i64 @malloc(i64 %47)
%49 = inttoptr i64 %48 to i32*
store i32* %49, i32** %8
store i64 0, i64* %11
br label %50
50: ; preds = %63, %39
%51 = load i64, i64* %11
%52 = load i64, i64* %9
%53 = icmp slt i64 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load i32*, i32** %6
%56 = load i32*, i32** %7
%57 = load i64, i64* %11
%58 = getelementptr inbounds i32, i32* %56, i64 %57
%59 = load i32*, i32** %8
%60 = load i64, i64* %11
%61 = getelementptr inbounds i32, i32* %59, i64 %60
%62 = call i32 (i32*, i8*, ...) @fscanf(i32* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %58, i32* %61)
br label %63
63: ; preds = %54
%64 = load i64, i64* %11
%65 = add nsw i64 %64, 1
store i64 %65, i64* %11
br label %50
66: ; preds = %50
%67 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%68 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%69 = load double, double* %68
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%71 = load double, double* %70
%72 = fdiv double %71, 1.000000e+06
%73 = fadd double %69, %72
store double %73, double* %13
%74 = load i64, i64* %10
%75 = load i64, i64* %9
%76 = load i64, i64* %10
%77 = load i64, i64* %9
%78 = load i32*, i32** %8
%79 = load i32*, i32** %7
%80 = call i32 @knapSack(i64 %76, i64 %77, i32* %78, i32* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i64 %74, i64 %75, i32 %80)
%82 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%84 = load double, double* %83
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%86 = load double, double* %85
%87 = fdiv double %86, 1.000000e+06
%88 = fadd double %84, %87
store double %88, double* %14
%89 = load double, double* %14
%90 = load double, double* %13
%91 = fsub double %89, %90
%92 = load double, double* %14
%93 = load double, double* %12
%94 = fsub double %92, %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %91, double %94)
%96 = load i32*, i32** %7
%97 = call i32 @free(i32* %96)
%98 = load i32*, i32** %8
%99 = call i32 @free(i32* %98)
%100 = load i32*, i32** %6
%101 = call i32 @fclose(i32* %100)
store i32 0, i32* %3
br label %102
102: ; preds = %66, %34, %18
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [30 x i8] c"Error opening Value file: %s\0A\00"
@.str.4 = [9 x i8] c"%ld %ld\0A\00"
@.str.5 = [7 x i8] c"%d,%d\0A\00"
@.str.6 = [11 x i8] c"%ld:%ld:%d\00"
@.str.7 = [14 x i8] c":%.6lf:%.6lf\0A\00"
@str = [28 x i8] c"\0A\0AError, mising parameters:\00"
@str.8 = [19 x i8] c"format: test_file \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timeval*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = bitcast <2 x double>* %5 to i8*
%10 = icmp eq i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
br label %73
14: ; preds = %2
%15 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%16 = getelementptr inbounds <2 x double>, <2 x double>* %5, i64 0, i64 0
%17 = load double, double* %16
%18 = getelementptr inbounds <2 x double>, <2 x double>* %5, i64 0, i64 1
%19 = load double, double* %18
%20 = fdiv double %19, 1.000000e+06
%21 = fadd double %17, %20
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %14
%27 = load i8*, i8** %22
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %73
29: ; preds = %14
%30 = call i32 (i32*, i8*, ...) @fscanf(i32* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64* %3, i64* %4)
%31 = load i64, i64* %3
%32 = shl i64 %31, 2
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i32*
%35 = load i64, i64* %3
%36 = shl i64 %35, 2
%37 = call i64 @malloc(i64 %36)
%38 = inttoptr i64 %37 to i32*
%39 = load i64, i64* %3
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %29, %41
%42 = phi i64 [ %46, %41 ], [ 0, %29 ]
%43 = getelementptr inbounds i32, i32* %34, i64 %42
%44 = getelementptr inbounds i32, i32* %38, i64 %42
%45 = call i32 (i32*, i8*, ...) @fscanf(i32* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %43, i32* %44)
%46 = add nuw nsw i64 %42, 1
%47 = load i64, i64* %3
%48 = icmp slt i64 %46, %47
br i1 %48, label %41, label %49
49: ; preds = %41, %29
%50 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%51 = load double, double* %16
%52 = load double, double* %18
%53 = load i64, i64* %4
%54 = load i64, i64* %3
%55 = call i32 @knapSack(i64 %53, i64 %54, i32* %38, i32* %34)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i64 %53, i64 %54, i32 %55)
%57 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%58 = load <2 x double>, <2 x double>* %5
%59 = shufflevector <2 x double> %58, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%60 = insertelement <2 x double> %59, double %52, i64 1
%61 = fdiv <2 x double> %60, <double 1.000000e+06, double 1.000000e+06>
%62 = insertelement <2 x double> %58, double %51, i64 1
%63 = fadd <2 x double> %62, %61
%64 = extractelement <2 x double> %63, i64 0
%65 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%66 = fsub <2 x double> %63, %65
%67 = extractelement <2 x double> %66, i64 0
%68 = fsub double %64, %21
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), double %67, double %68)
%70 = call i32 @free(i32* %34)
%71 = call i32 @free(i32* %38)
%72 = call i32 @fclose(i32* %24)
br label %73
73: ; preds = %49, %26, %11
%74 = phi i32 [ 1, %11 ], [ 0, %49 ], [ 1, %26 ]
ret i32 %74
}