#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 stat {
  scalar_t__ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fstat(int, struct stat *);
void *mmap(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, scalar_t__);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ parse_config_file(void *, scalar_t__);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
void do_config_file(const char *filename) {
  struct stat st;
  int fd;
  void *map;
  fd = open(filename, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "fixdep: error opening config file: ");
    perror(filename);
    exit(2);
  }
  fstat(fd, &st);
  if (st.st_size == 0) {
    close(fd);
    return;
  }
  map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if ((long)map == -1) {
    perror("fixdep: mmap");
    close(fd);
    return;
  }
  parse_config_file(map, st.st_size);
  munmap(map, st.st_size);
  close(fd);
}


x86 assembly (clang, -O0):
<do_config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e3 <do_config_file+0x53>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10a0 <fstat@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1207 <do_config_file+0x77>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    127a <do_config_file+0xea>
mov    -0x10(%rbp),%rsi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    0x2dad(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    $0xffffffffffffffff,%rax
jne    1258 <do_config_file+0xc8>
lea    0xdde(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    127a <do_config_file+0xea>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <parse_config_file@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_config_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1225 <do_config_file+0x95>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     1207 <do_config_file+0x77>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    0x2df2(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1217 <do_config_file+0x87>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   10b0 <parse_config_file@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <munmap@plt>
mov    %r14d,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <close@plt>
lea    0xe06(%rip),%rdi
call   1080 <perror@plt>
jmp    1207 <do_config_file+0x77>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"fixdep: error opening config file: \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [13 x i8] c"fixdep: mmap\00"
define void @do_config_file(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
%19 = call i32 @fstat(i32 %18, %struct.stat* %3)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
br label %51
26: ; preds = %17
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%28 = load i64, i64* %27
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @MAP_PRIVATE
%31 = load i32, i32* %4
%32 = call i8* @mmap(i32* null, i64 %28, i32 %29, i32 %30, i32 %31, i32 0)
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = ptrtoint i8* %33 to i64
%35 = icmp eq i64 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = call i32 @close(i32 %38)
br label %51
40: ; preds = %26
%41 = load i8*, i8** %5
%42 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%43 = load i64, i64* %42
%44 = call i32 @parse_config_file(i8* %41, i64 %43)
%45 = load i8*, i8** %5
%46 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 @munmap(i8* %45, i64 %47)
%49 = load i32, i32* %4
%50 = call i32 @close(i32 %49)
br label %51
51: ; preds = %40, %36, %23
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"fixdep: error opening config file: \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.1 = [13 x i8] c"fixdep: mmap\00"
define void @do_config_file(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @perror(i8* %0)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %1
%13 = call i32 @fstat(i32 %5, %struct.stat* %2)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %12
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @MAP_PRIVATE
%20 = tail call i8* @mmap(i32* null, i64 %15, i32 %18, i32 %19, i32 %5, i32 0)
%21 = icmp eq i8* %20, inttoptr (i64 -1 to i8*)
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %27
24: ; preds = %17
%25 = tail call i32 @parse_config_file(i8* %20, i64 %15)
%26 = tail call i32 @munmap(i8* %20, i64 %15)
br label %27
27: ; preds = %12, %24, %22
%28 = tail call i32 @close(i32 %5)
ret void
}