#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 */
double fractionalKnapsack(double *, double *, double, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("Fractional knapsack example.\n\n");
  double value[] = {120.0, 10.0, 150.0, 30.0};
  double weight[] = {2.0, 2.0, 1.5, 3.0};
  double knapsackCapacity = 4.5;
  printf("Respective values: 120.0, 10.0, 150.0, 30.0\n");
  printf("Respective weights: 2.0, 2.0, 1.5, 3.0\n");
  printf("Knapsack capacity: 4.5\n\n");
  double maxValue = fractionalKnapsack(value, weight, knapsackCapacity, 4);
  printf("Maximum value: %.1f\n", maxValue);
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xf63(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf60(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xf5d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xf5a(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0xf57(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xf54(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xf51(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xf4e(%rip),%rax
mov    %rax,-0x28(%rbp)
movsd  0xe5a(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
mov    $0x4,%edx
call   1050 <fractionalKnapsack@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
lea    0xe98(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
lea    0xf1a(%rip),%rdi
call   1030 <puts@plt>
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xead(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
movsd  0xe4d(%rip),%xmm0
mov    $0x4,%edx
call   1060 <fractionalKnapsack@plt>
lea    0xe8c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Fractional knapsack example.\0A\0A\00"
@__const.main.value = [4 x double] [double 1.200000e+02, double 1.000000e+01, double 1.500000e+02, double 3.000000e+01]
@__const.main.weight = [4 x double] [double 2.000000e+00, double 2.000000e+00, double 1.500000e+00, double 3.000000e+00]
@.str.1 = [45 x i8] c"Respective values: 120.0, 10.0, 150.0, 30.0\0A\00"
@.str.2 = [40 x i8] c"Respective weights: 2.0, 2.0, 1.5, 3.0\0A\00"
@.str.3 = [25 x i8] c"Knapsack capacity: 4.5\0A\0A\00"
@.str.4 = [21 x i8] c"Maximum value: %.1f\0A\00"
define i32 @main() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = alloca double
%4 = alloca double
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = bitcast [4 x double]* %1 to i8*
%7 = bitcast [4 x double]* %2 to i8*
store double 4.500000e+00, double* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%12 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%13 = load double, double* %3
%14 = call double @fractionalKnapsack(double* %11, double* %12, double %13, i32 4)
store double %14, double* %4
%15 = load double, double* %4
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %15)
%17 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.value = [4 x double] [double 1.200000e+02, double 1.000000e+01, double 1.500000e+02, double 3.000000e+01]
@__const.main.weight = [4 x double] [double 2.000000e+00, double 2.000000e+00, double 1.500000e+00, double 3.000000e+00]
@.str.4 = [21 x i8] c"Maximum value: %.1f\0A\00"
@str = [30 x i8] c"Fractional knapsack example.\0A\00"
@str.5 = [44 x i8] c"Respective values: 120.0, 10.0, 150.0, 30.0\00"
@str.6 = [39 x i8] c"Respective weights: 2.0, 2.0, 1.5, 3.0\00"
@str.7 = [24 x i8] c"Knapsack capacity: 4.5\0A\00"
define i32 @main() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = bitcast [4 x double]* %1 to i8*
%5 = bitcast [4 x double]* %2 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
%9 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%10 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%11 = call double @fractionalKnapsack(double* %9, double* %10, double 4.500000e+00, i32 4)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), double %11)
%13 = call i32 (...) @getchar()
ret i32 0
}