#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 *);
scalar_t__ 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);
  }
  if (fstat(fd, &st) < 0) {
    fprintf(stderr, "fixdep: error fstat'ing config file: ");
    perror(filename);
    exit(2);
  }
  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>
cmp    $0x0,%rax
jge    1221 <do_config_file+0x91>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1239 <do_config_file+0xa9>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    12ac <do_config_file+0x11c>
mov    -0x10(%rbp),%rsi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
mov    0x2d7b(%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    128a <do_config_file+0xfa>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    12ac <do_config_file+0x11c>
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   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1228 <do_config_file+0x98>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
test   %rax,%rax
js     123a <do_config_file+0xaa>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     1208 <do_config_file+0x78>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     121a <do_config_file+0x8a>
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    %r15d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
lea    0xe29(%rip),%rdi
call   1080 <perror@plt>
jmp    1208 <do_config_file+0x78>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
jmp    124a <do_config_file+0xba>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%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"
@.str.1 = [38 x i8] c"fixdep: error fstat'ing config file: \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [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 i64 @fstat(i32 %18, %struct.stat* %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %2
%25 = call i32 @perror(i8* %24)
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %17
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%29 = load i64, i64* %28
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %4
%33 = call i32 @close(i32 %32)
br label %59
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i32, i32* @PROT_READ
%38 = load i32, i32* @MAP_PRIVATE
%39 = load i32, i32* %4
%40 = call i8* @mmap(i32* null, i64 %36, i32 %37, i32 %38, i32 %39, i32 0)
store i8* %40, i8** %5
%41 = load i8*, i8** %5
%42 = ptrtoint i8* %41 to i64
%43 = icmp eq i64 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* %4
%47 = call i32 @close(i32 %46)
br label %59
48: ; preds = %34
%49 = load i8*, i8** %5
%50 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%51 = load i64, i64* %50
%52 = call i32 @parse_config_file(i8* %49, i64 %51)
%53 = load i8*, i8** %5
%54 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%55 = load i64, i64* %54
%56 = call i32 @munmap(i8* %53, i64 %55)
%57 = load i32, i32* %4
%58 = call i32 @close(i32 %57)
br label %59
59: ; preds = %48, %44, %31
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"
@.str.1 = [38 x i8] c"fixdep: error fstat'ing config file: \00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [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 i64 @fstat(i32 %5, %struct.stat* %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @perror(i8* %0)
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %12
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @MAP_PRIVATE
%27 = tail call i8* @mmap(i32* null, i64 %22, i32 %25, i32 %26, i32 %5, i32 0)
%28 = icmp eq i8* %27, inttoptr (i64 -1 to i8*)
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %34
31: ; preds = %24
%32 = tail call i32 @parse_config_file(i8* %27, i64 %22)
%33 = tail call i32 @munmap(i8* %27, i64 %22)
br label %34
34: ; preds = %20, %31, %29
%35 = tail call i32 @close(i32 %5)
ret void
}