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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
scalar_t__ init_generator(int, int, int /*<<< orphan*/ *, struct generator **);
scalar_t__ malloc(int);
int init_generators(struct generator ***generators, int *ngenerators,
                    const char *arrivalPatterns) {
  FILE *fp;
  fp = fopen(arrivalPatterns, "r");
  if (!fp) {
    return -1;
  }
  int ncols, nrows;
  if (fscanf(fp, "%d, %d\n", &nrows, &ncols) != 2)
    return -1;
  *generators = (struct generator **)malloc(ncols * sizeof(int));
  *ngenerators = nrows;
  int gen_id;
  for (gen_id = 0; gen_id < nrows; gen_id++) {
    if (init_generator(gen_id, ncols, fp, &((*generators)[gen_id])) != 0)
      return -1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<init_generators>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118f <init_generators+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <init_generators+0xfb>
mov    -0x28(%rbp),%rdi
lea    0xe68(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
je     11bc <init_generators+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <init_generators+0xfb>
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    123b <init_generators+0xeb>
mov    -0x34(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rcx
call   1050 <init_generator@plt>
cmp    $0x0,%rax
je     1228 <init_generators+0xd8>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <init_generators+0xfb>
jmp    122d <init_generators+0xdd>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e5 <init_generators+0x95>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_generators>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe98(%rip),%rsi
mov    %rdx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     120d <init_generators+0xbd>
mov    %rax,%r13
lea    0xe7f(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    $0xffffffff,%r14d
cmp    $0x2,%eax
jne    1220 <init_generators+0xd0>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12)
mov    0x4(%rsp),%ecx
mov    %ecx,(%r15)
test   %ecx,%ecx
jle    1215 <init_generators+0xc5>
mov    (%rsp),%esi
xor    %edi,%edi
mov    %r13,%rdx
mov    %rax,%rcx
call   1050 <init_generator@plt>
test   %rax,%rax
jne    1220 <init_generators+0xd0>
mov    $0x1,%ebx
mov    $0x8,%ebp
nopl   0x0(%rax,%rax,1)
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jge    1215 <init_generators+0xc5>
mov    (%rsp),%esi
mov    (%r12),%rcx
add    %rbp,%rcx
mov    %ebx,%edi
mov    %r13,%rdx
call   1050 <init_generator@plt>
add    $0x1,%rbx
add    $0x8,%rbp
test   %rax,%rax
je     11e0 <init_generators+0x90>
jmp    1220 <init_generators+0xd0>
mov    $0xffffffff,%r14d
jmp    1220 <init_generators+0xd0>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.generator = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"%d, %d\0A\00"
define i32 @init_generators(%struct.generator*** nocapture %0, i32* nocapture writeonly %1, i8* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %3
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %4)
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %39
13: ; preds = %8
%14 = load i32, i32* %4
%15 = shl i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to %struct.generator**
store %struct.generator** %17, %struct.generator*** %0
%18 = load i32, i32* %5
store i32 %18, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %13
%21 = load i32, i32* %4
%22 = call i64 @init_generator(i32 0, i32 %21, i32* %6, %struct.generator** %17)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %20, %29
%25 = phi i64 [ %36, %29 ], [ 1, %20 ]
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load %struct.generator**, %struct.generator*** %0
%31 = load i32, i32* %4
%32 = getelementptr inbounds %struct.generator*, %struct.generator** %30, i64 %25
%33 = trunc i64 %25 to i32
%34 = call i64 @init_generator(i32 %33, i32 %31, i32* %6, %struct.generator** %32)
%35 = icmp eq i64 %34, 0
%36 = add nuw nsw i64 %25, 1
br i1 %35, label %24, label %39
37: ; preds = %24, %13
%38 = call i32 @fclose(i32* %6)
br label %39
39: ; preds = %29, %20, %37, %8
%40 = phi i32 [ -1, %8 ], [ 0, %37 ], [ -1, %20 ], [ -1, %29 ]
br label %41
41: ; preds = %3, %39
%42 = phi i32 [ %40, %39 ], [ -1, %3 ]
ret i32 %42
}