#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 res_model_list {
  int dummy;
};
struct ind_model_list {
  int dummy;
};
struct com_model_list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
struct com_model_list *read_commodel_list(int);
struct ind_model_list *read_indmodel_list(int);
struct res_model_list *read_resmodel_list(int);
void init_models_lists(struct res_model_list **r_models,
                       struct com_model_list **c_models,
                       struct ind_model_list **i_models) {
  if (*r_models == NULL) {
    int fd = open("resid.bin", O_RDONLY);
    if (fd < 0) {
      printf("Error %d opening file\n", errno, "resid.bin");
      abort();
    }
    *r_models = read_resmodel_list(fd);
    close(fd);
  }
  if (*c_models == NULL) {
    int fd = open("comm.bin", O_RDONLY);
    if (fd < 0) {
      printf("Error %d opening file\n", errno, "comm.bin");
      abort();
    }
    *c_models = read_commodel_list(fd);
    close(fd);
  }
  if (*i_models == NULL) {
    int fd = open("indus.bin", O_RDONLY);
    if (fd < 0) {
      printf("Error %d opening file\n", errno, "indus.bin");
      abort();
    }
    *i_models = read_indmodel_list(fd);
    close(fd);
  }
}


x86 assembly (clang, -O0):
<init_models_lists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11f1 <init_models_lists+0x81>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d7 <init_models_lists+0x67>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
lea    0xe35(%rip),%rdx
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x1c(%rbp),%edi
call   1070 <read_resmodel_list@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    125e <init_models_lists+0xee>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1244 <init_models_lists+0xd4>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    0xdd9(%rip),%rdi
lea    0xde9(%rip),%rdx
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%edi
call   1090 <read_commodel_list@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12cb <init_models_lists+0x15b>
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
lea    0xdae(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12b1 <init_models_lists+0x141>
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
lea    0xd6c(%rip),%rdi
lea    0xd85(%rip),%rdx
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x24(%rbp),%edi
call   1030 <read_indmodel_list@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_models_lists>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
cmpq   $0x0,(%rdi)
je     119a <init_models_lists+0x2a>
cmpq   $0x0,(%r15)
je     11d3 <init_models_lists+0x63>
cmpq   $0x0,(%r14)
je     1205 <init_models_lists+0x95>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdi,%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     123b <init_models_lists+0xcb>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <read_resmodel_list@plt>
mov    %rax,(%rbx)
mov    %ebp,%edi
call   1060 <close@plt>
cmpq   $0x0,(%r15)
jne    1189 <init_models_lists+0x19>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1254 <init_models_lists+0xe4>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <read_commodel_list@plt>
mov    %rax,(%r15)
mov    %ebx,%edi
call   1060 <close@plt>
cmpq   $0x0,(%r14)
jne    118f <init_models_lists+0x1f>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xe15(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     126d <init_models_lists+0xfd>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <read_indmodel_list@plt>
mov    %rax,(%r14)
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
lea    0xdbf(%rip),%rdi
lea    0xdae(%rip),%rdx
jmp    1284 <init_models_lists+0x114>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
lea    0xda6(%rip),%rdi
lea    0xdb6(%rip),%rdx
jmp    1284 <init_models_lists+0x114>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xd8d(%rip),%rdi
lea    0xda6(%rip),%rdx
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.res_model_list = type { i32 }
%struct.com_model_list = type { i32 }
%struct.ind_model_list = type { i32 }
@.str = [10 x i8] c"resid.bin\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error %d opening file\0A\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"comm.bin\00"
@.str.3 = [10 x i8] c"indus.bin\00"
define void @init_models_lists(%struct.res_model_list** %0, %struct.com_model_list** %1, %struct.ind_model_list** %2) {
%4 = alloca %struct.res_model_list**
%5 = alloca %struct.com_model_list**
%6 = alloca %struct.ind_model_list**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.res_model_list** %0, %struct.res_model_list*** %4
store %struct.com_model_list** %1, %struct.com_model_list*** %5
store %struct.ind_model_list** %2, %struct.ind_model_list*** %6
%10 = load %struct.res_model_list**, %struct.res_model_list*** %4
%11 = load %struct.res_model_list*, %struct.res_model_list** %10
%12 = icmp eq %struct.res_model_list* %11, null
br i1 %12, label %13, label %28
13: ; preds = %3
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* @errno
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %13
%23 = load i32, i32* %7
%24 = call %struct.res_model_list* @read_resmodel_list(i32 %23)
%25 = load %struct.res_model_list**, %struct.res_model_list*** %4
store %struct.res_model_list* %24, %struct.res_model_list** %25
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %22, %3
%29 = load %struct.com_model_list**, %struct.com_model_list*** %5
%30 = load %struct.com_model_list*, %struct.com_model_list** %29
%31 = icmp eq %struct.com_model_list* %30, null
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @errno
%39 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %32
%42 = load i32, i32* %8
%43 = call %struct.com_model_list* @read_commodel_list(i32 %42)
%44 = load %struct.com_model_list**, %struct.com_model_list*** %5
store %struct.com_model_list* %43, %struct.com_model_list** %44
%45 = load i32, i32* %8
%46 = call i32 @close(i32 %45)
br label %47
47: ; preds = %41, %28
%48 = load %struct.ind_model_list**, %struct.ind_model_list*** %6
%49 = load %struct.ind_model_list*, %struct.ind_model_list** %48
%50 = icmp eq %struct.ind_model_list* %49, null
br i1 %50, label %51, label %66
51: ; preds = %47
%52 = load i32, i32* @O_RDONLY
%53 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %51
%57 = load i32, i32* @errno
%58 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %57, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 (...) @abort()
unreachable
60: ; preds = %51
%61 = load i32, i32* %9
%62 = call %struct.ind_model_list* @read_indmodel_list(i32 %61)
%63 = load %struct.ind_model_list**, %struct.ind_model_list*** %6
store %struct.ind_model_list* %62, %struct.ind_model_list** %63
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
br label %66
66: ; preds = %60, %47
ret void
}

LLVM IR (-O2):
%struct.res_model_list = type { i32 }
%struct.com_model_list = type { i32 }
%struct.ind_model_list = type { i32 }
@.str = [10 x i8] c"resid.bin\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error %d opening file\0A\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"comm.bin\00"
@.str.3 = [10 x i8] c"indus.bin\00"
define void @init_models_lists(%struct.res_model_list** nocapture %0, %struct.com_model_list** nocapture %1, %struct.ind_model_list** nocapture %2) {
%4 = load %struct.res_model_list*, %struct.res_model_list** %0
%5 = icmp eq %struct.res_model_list* %4, null
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %6
%15 = tail call %struct.res_model_list* @read_resmodel_list(i32 %8)
store %struct.res_model_list* %15, %struct.res_model_list** %0
%16 = tail call i32 @close(i32 %8)
br label %17
17: ; preds = %14, %3
%18 = load %struct.com_model_list*, %struct.com_model_list** %1
%19 = icmp eq %struct.com_model_list* %18, null
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @errno
%26 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%27 = tail call i32 (...) @abort()
unreachable
28: ; preds = %20
%29 = tail call %struct.com_model_list* @read_commodel_list(i32 %22)
store %struct.com_model_list* %29, %struct.com_model_list** %1
%30 = tail call i32 @close(i32 %22)
br label %31
31: ; preds = %28, %17
%32 = load %struct.ind_model_list*, %struct.ind_model_list** %2
%33 = icmp eq %struct.ind_model_list* %32, null
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i32, i32* @O_RDONLY
%36 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @errno
%40 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%41 = tail call i32 (...) @abort()
unreachable
42: ; preds = %34
%43 = tail call %struct.ind_model_list* @read_indmodel_list(i32 %36)
store %struct.ind_model_list* %43, %struct.ind_model_list** %2
%44 = tail call i32 @close(i32 %36)
br label %45
45: ; preds = %42, %31
ret void
}