#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*/ *open_default(char const *);
int /*<<< orphan*/ parse(int /*<<< orphan*/ *, int);
int env_load(const char *path, bool overwrite) {
  FILE *file = open_default(path);
  if (!file) {
    file = fopen(path, "rb");
    if (!file) {
      return -1;
    }
  }
  parse(file, overwrite);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<env_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <open_default@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <env_load+0x57>
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1192 <env_load+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <env_load+0x73>
jmp    1197 <env_load+0x57>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <parse@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_load>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1040 <open_default@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116e <env_load+0x2e>
lea    0xea2(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1188 <env_load+0x48>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <parse@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    1183 <env_load+0x43>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @env_load(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32* @open_default(i8* %7)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
store i32 -1, i32* %3
br label %24
17: ; preds = %11
br label %18
18: ; preds = %17, %2
%19 = load i32*, i32** %6
%20 = load i32, i32* %5
%21 = call i32 @parse(i32* %19, i32 %20)
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %3
br label %24
24: ; preds = %18, %16
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @env_load(i8* %0, i32 %1) {
%3 = tail call i32* @open_default(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5, %2
%9 = phi i32* [ %3, %2 ], [ %6, %5 ]
%10 = tail call i32 @parse(i32* %9, i32 %1)
%11 = tail call i32 @fclose(i32* %9)
br label %12
12: ; preds = %5, %8
%13 = phi i32 [ 0, %8 ], [ -1, %5 ]
ret i32 %13
}