#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 */

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
char *grab_file(char const *, size_t *);
int load_nl_args_buf(char *, size_t, int *, char ***);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int load_nl_args_file(const char *filename, int *argc, char ***argv,
                      char **buf) {
  size_t buf_sz;
  *buf = grab_file(filename, &buf_sz);
  if (!*buf) {
    if (errno == ENOENT)
      return 0;
    fprintf(stderr, "qemu-user-env: failed to grab cfg file '%s': %s\n",
            filename, strerror(errno));
    return -1;
  }
  return load_nl_args_buf(*buf, buf_sz, argc, argv);
}


x86 assembly (clang, -O0):
<load_nl_args_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <grab_file@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e8 <load_nl_args_file+0xa8>
mov    0x2e54(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    11a3 <load_nl_args_file+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1203 <load_nl_args_file+0xc3>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <load_nl_args_file+0xc3>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <load_nl_args_buf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_nl_args_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,%rsi
call   1030 <grab_file@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1178 <load_nl_args_file+0x38>
mov    (%rsp),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <load_nl_args_buf@plt>
jmp    11b7 <load_nl_args_file+0x77>
mov    0x2e59(%rip),%rax
mov    (%rax),%rdi
mov    0x2e3f(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%rdi
je     11b7 <load_nl_args_file+0x77>
mov    0x2e49(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe5b(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"qemu-user-env: failed to grab cfg file '%s': %s\0A\00"
define i32 @load_nl_args_file(i8* %0, i32* %1, i8*** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8***
%9 = alloca i8**
%10 = alloca i64
store i8* %0, i8** %6
store i32* %1, i32** %7
store i8*** %2, i8**** %8
store i8** %3, i8*** %9
%11 = load i8*, i8** %6
%12 = call i8* @grab_file(i8* %11, i64* %10)
%13 = load i8**, i8*** %9
store i8* %12, i8** %13
%14 = load i8**, i8*** %9
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %4
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 0, i32* %5
br label %35
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %6
%25 = load i64, i64* @errno
%26 = call i8* @strerror(i64 %25)
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %26)
store i32 -1, i32* %5
br label %35
28: ; preds = %4
%29 = load i8**, i8*** %9
%30 = load i8*, i8** %29
%31 = load i64, i64* %10
%32 = load i32*, i32** %7
%33 = load i8***, i8**** %8
%34 = call i32 @load_nl_args_buf(i8* %30, i64 %31, i32* %32, i8*** %33)
store i32 %34, i32* %5
br label %35
35: ; preds = %28, %22, %21
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [49 x i8] c"qemu-user-env: failed to grab cfg file '%s': %s\0A\00"
define i32 @load_nl_args_file(i8* %0, i32* %1, i8*** %2, i8** nocapture writeonly %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i8* @grab_file(i8* %0, i64* %5)
store i8* %7, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %17
9: ; preds = %4
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i8* @strerror(i64 %10)
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %15)
br label %20
17: ; preds = %4
%18 = load i64, i64* %5
%19 = call i32 @load_nl_args_buf(i8* %7, i64 %18, i32* %1, i8*** %2)
br label %20
20: ; preds = %9, %17, %13
%21 = phi i32 [ %19, %17 ], [ -1, %13 ], [ 0, %9 ]
ret i32 %21
}