#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 compute_max_val(int *, int *, int, int);
int /*<<< orphan*/ print_optimal(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(int argc, char *argv[]) {
  int i, no_items, max_weight, max_val;
  int weight[10], value[10];
  scanf("%d %d", &no_items, &max_weight);
  for (i = 1; i <= no_items; i++) {
    scanf("%d %d", &weight[i], &value[i]);
  }
  max_val = compute_max_val(weight, value, no_items, max_weight);
  printf("The maximum value is: %d\n", max_val);
  print_optimal(weight, no_items, max_weight);
}


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    0xea0(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <scanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11b8 <main+0x78>
movslq -0x14(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x14(%rbp),%rax
lea    -0x80(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe5b(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <main+0x34>
lea    -0x50(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <compute_max_val@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <print_optimal@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xeae(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <scanf@plt>
mov    0x8(%rsp),%edx
test   %edx,%edx
jle    11a4 <main+0x64>
lea    0x14(%rsp),%r14
lea    0x44(%rsp),%r12
xor    %ebx,%ebx
lea    0xe84(%rip),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <scanf@plt>
movslq 0x8(%rsp),%rdx
add    $0x1,%rbx
add    $0x4,%r14
add    $0x4,%r12
cmp    %rdx,%rbx
jl     1180 <main+0x40>
mov    0xc(%rsp),%ecx
lea    0x40(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <compute_max_val@plt>
lea    0xe45(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1060 <print_optimal@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [26 x i8] c"The maximum value is: %d\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 i32
%10 = alloca [10 x i32]
%11 = alloca [10 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8)
store i32 1, i32* %6
br label %13
13: ; preds = %25, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %10, i64 0, i64 %19
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %20, i32* %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %13
28: ; preds = %13
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %10, i64 0, i64 0
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 0
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 @compute_max_val(i32* %29, i32* %30, i32 %31, i32 %32)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %10, i64 0, i64 0
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 @print_optimal(i32* %36, i32 %37, i32 %38)
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [26 x i8] c"The maximum value is: %d\0A\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 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1
br i1 %13, label %23, label %14
14: ; preds = %2, %14
%15 = phi i64 [ %19, %14 ], [ 1, %2 ]
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %15
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %15
%18 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %16, i32* %17)
%19 = add nuw nsw i64 %15, 1
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %15, %21
br i1 %22, label %14, label %23
23: ; preds = %14, %2
%24 = phi i32 [ %12, %2 ], [ %20, %14 ]
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%27 = load i32, i32* %4
%28 = call i32 @compute_max_val(i32* %25, i32* %26, i32 %24, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @print_optimal(i32* %25, i32 %30, i32 %31)
ret i32 0
}