#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ stderr;
void init_resources(unsigned int *numTypes, unsigned int **available) {
  unsigned int i;
  FILE *file;
  file = fopen("initial.data", "r");
  if (file == NULL) {
    perror("fopen");
    exit(1);
  }
  fscanf(file, "%u", numTypes);
  *available = (unsigned int *)malloc(sizeof(unsigned int) * (*numTypes));
  if (*available == NULL) {
    fprintf(stderr, "Error allocating available resource vector of size %d.\n",
            *numTypes);
    fclose(file);
    exit(1);
  }
  for (i = 0; i < *numTypes; i++) {
    fscanf(file, "%u", *available + i);
  }
  fclose(file);
  printf("Number of resource types = %d\n", *numTypes);
}


x86 assembly (clang, -O0):
<init_resources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe69(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <init_resources+0x48>
lea    0xe56(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1233 <init_resources+0xb3>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jae    1278 <init_resources+0xf8>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x14(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xdb0(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <init_resources+0xba>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_resources>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe68(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1258 <init_resources+0xd8>
mov    %rax,%r14
lea    0xe5e(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1050 <fscanf@plt>
mov    0x0(%r13),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     126e <init_resources+0xee>
cmpl   $0x0,0x0(%r13)
je     1232 <init_resources+0xb2>
lea    0xe2d(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1050 <fscanf@plt>
cmpl   $0x2,0x0(%r13)
jb     1232 <init_resources+0xb2>
mov    $0x1,%ebx
mov    $0x4,%ebp
lea    0xe0a(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rdx
add    %rbp,%rdx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <fscanf@plt>
add    $0x1,%rbx
mov    0x0(%r13),%eax
add    $0x4,%rbp
cmp    %rax,%rbx
jb     1210 <init_resources+0x90>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x0(%r13),%esi
lea    0xe0b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xdb0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%edx
lea    0xd96(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"initial.data\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.4 = [56 x i8] c"Error allocating available resource vector of size %d.\0A\00"
@.str.5 = [31 x i8] c"Number of resource types = %d\0A\00"
define void @init_resources(i32* %0, i32** nocapture %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %0)
%10 = load i32, i32* %0
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %1
%14 = icmp eq i64 %12, 0
br i1 %14, label %22, label %15
15: ; preds = %8
%16 = load i32, i32* %0
%17 = icmp eq i32 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %15
%19 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %13)
%20 = load i32, i32* %0
%21 = icmp ugt i32 %20, 1
br i1 %21, label %28, label %37
22: ; preds = %8
%23 = load i32, i32* @stderr
%24 = load i32, i32* %0
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = tail call i32 @fclose(i32* %3)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %18, %28
%29 = phi i64 [ %33, %28 ], [ 1, %18 ]
%30 = load i32*, i32** %1
%31 = getelementptr inbounds i32, i32* %30, i64 %29
%32 = tail call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %31)
%33 = add nuw nsw i64 %29, 1
%34 = load i32, i32* %0
%35 = zext i32 %34 to i64
%36 = icmp ult i64 %33, %35
br i1 %36, label %28, label %37
37: ; preds = %28, %18, %15
%38 = tail call i32 @fclose(i32* %3)
%39 = load i32, i32* %0
%40 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %39)
ret void
}