#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) {
    close(fd);
    return;
  }
  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
je     1206 <do_config_file+0x76>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    1291 <do_config_file+0x101>
cmpq   $0x0,-0x10(%rbp)
jne    121e <do_config_file+0x8e>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    1291 <do_config_file+0x101>
mov    -0x10(%rbp),%rsi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    0x2d96(%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    126f <do_config_file+0xdf>
lea    0xdc7(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    1291 <do_config_file+0x101>
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   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     122a <do_config_file+0x9a>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
test   %rax,%rax
jne    120c <do_config_file+0x7c>
mov    0x8(%rsp),%r14
test   %r14,%r14
je     120c <do_config_file+0x7c>
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    0x2ded(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     121c <do_config_file+0x8c>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   10b0 <parse_config_file@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <munmap@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
jmp    120c <do_config_file+0x7c>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%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"
@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 i64 @fstat(i32 %18, %struct.stat* %3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
br label %56
24: ; preds = %17
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %4
%30 = call i32 @close(i32 %29)
br label %56
31: ; preds = %24
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%33 = load i64, i64* %32
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @MAP_PRIVATE
%36 = load i32, i32* %4
%37 = call i8* @mmap(i32* null, i64 %33, i32 %34, i32 %35, i32 %36, i32 0)
store i8* %37, i8** %5
%38 = load i8*, i8** %5
%39 = ptrtoint i8* %38 to i64
%40 = icmp eq i64 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %31
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
br label %56
45: ; preds = %31
%46 = load i8*, i8** %5
%47 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%48 = load i64, i64* %47
%49 = call i32 @parse_config_file(i8* %46, i64 %48)
%50 = load i8*, i8** %5
%51 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%52 = load i64, i64* %51
%53 = call i32 @munmap(i8* %50, i64 %52)
%54 = load i32, i32* %4
%55 = call i32 @close(i32 %54)
br label %56
56: ; preds = %45, %41, %28, %21
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 i64 @fstat(i32 %5, %struct.stat* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @MAP_PRIVATE
%22 = tail call i8* @mmap(i32* null, i64 %17, i32 %20, i32 %21, i32 %5, i32 0)
%23 = icmp eq i8* %22, inttoptr (i64 -1 to i8*)
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %29
26: ; preds = %19
%27 = tail call i32 @parse_config_file(i8* %22, i64 %17)
%28 = tail call i32 @munmap(i8* %22, i64 %17)
br label %29
29: ; preds = %15, %12, %26, %24
%30 = tail call i32 @close(i32 %5)
ret void
}