#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(unsigned int);
void readFile(const char *file_name, int **weights, unsigned int **values,
              unsigned int *num_items, int *capacity) {
  FILE *fptr;
  unsigned int i;
  fptr = fopen(file_name, "r");
  fscanf(fptr, "%d", capacity);
  fscanf(fptr, "%d", num_items);
  *weights = (int *)malloc(*num_items * sizeof(int));
  *values = (unsigned int *)malloc(*num_items * sizeof(unsigned int));
  for (i = 0; i < *num_items; i++) {
    fscanf(fptr, "%d", *weights + i);
    fscanf(fptr, "%u", *values + i);
  }
  fclose(fptr);
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jae    123c <readFile+0xfc>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x34(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x34(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d9 <readFile+0x99>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%r12),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
mov    (%r12),%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
cmpl   $0x0,(%r12)
je     11ff <readFile+0xbf>
xor    %r13d,%r13d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r15),%rdx
add    %r13,%rdx
mov    %rbx,%rdi
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    (%r14),%rdx
add    %r13,%rdx
mov    %rbx,%rdi
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%rbp
mov    (%r12),%eax
add    $0x4,%r13
cmp    %rax,%rbp
jb     11c0 <readFile+0x80>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%u\00"
define void @readFile(i8* %0, i32** %1, i32** %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %6
store i32** %1, i32*** %7
store i32** %2, i32*** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %11
%15 = load i32*, i32** %11
%16 = load i32*, i32** %10
%17 = call i32 (i32*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** %11
%19 = load i32*, i32** %9
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = load i32*, i32** %9
%22 = load i32, i32* %21
%23 = zext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
%28 = load i32**, i32*** %7
store i32* %27, i32** %28
%29 = load i32*, i32** %9
%30 = load i32, i32* %29
%31 = zext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i32*
%36 = load i32**, i32*** %8
store i32* %35, i32** %36
store i32 0, i32* %12
br label %37
37: ; preds = %57, %5
%38 = load i32, i32* %12
%39 = load i32*, i32** %9
%40 = load i32, i32* %39
%41 = icmp ult i32 %38, %40
br i1 %41, label %42, label %60
42: ; preds = %37
%43 = load i32*, i32** %11
%44 = load i32**, i32*** %7
%45 = load i32*, i32** %44
%46 = load i32, i32* %12
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = call i32 (i32*, i8*, ...) @fscanf(i32* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %48)
%50 = load i32*, i32** %11
%51 = load i32**, i32*** %8
%52 = load i32*, i32** %51
%53 = load i32, i32* %12
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = call i32 (i32*, i8*, ...) @fscanf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %55)
br label %57
57: ; preds = %42
%58 = load i32, i32* %12
%59 = add i32 %58, 1
store i32 %59, i32* %12
br label %37
60: ; preds = %37
%61 = load i32*, i32** %11
%62 = call i32 @fclose(i32* %61)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"%u\00"
define void @readFile(i8* nocapture %0, i32** nocapture %1, i32** nocapture %2, i32* %3, i32* %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%8 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = shl i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %1
%13 = load i32, i32* %3
%14 = shl i32 %13, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %2
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %5, %19
%20 = phi i64 [ %27, %19 ], [ 0, %5 ]
%21 = load i32*, i32** %1
%22 = getelementptr inbounds i32, i32* %21, i64 %20
%23 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = load i32*, i32** %2
%25 = getelementptr inbounds i32, i32* %24, i64 %20
%26 = tail call i32 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %25)
%27 = add nuw nsw i64 %20, 1
%28 = load i32, i32* %3
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %27, %29
br i1 %30, label %19, label %31
31: ; preds = %19, %5
%32 = tail call i32 @fclose(i32* %6)
ret void
}