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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
char *malloc(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ parse_config_file(char *);
int /*<<< orphan*/ perror(char const *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void do_config_file(const char *filename) {
  struct stat st;
  int fd;
  char *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 = malloc(st.st_size + 1);
  if (!map) {
    perror("fixdep: malloc");
    close(fd);
    return;
  }
  if (read(fd, map, st.st_size) != st.st_size) {
    perror("fixdep: read");
    close(fd);
    return;
  }
  map[st.st_size] = '\0';
  close(fd);
  parse_config_file(map);
  free(map);
}


x86 assembly (clang, -O0):
<do_config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f3 <do_config_file+0x53>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
jge    1231 <do_config_file+0x91>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1248 <do_config_file+0xa8>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    12d2 <do_config_file+0x132>
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127b <do_config_file+0xdb>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    12d2 <do_config_file+0x132>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <read@plt>
cmp    -0x10(%rbp),%eax
je     12ac <do_config_file+0x10c>
lea    0xdbf(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    12d2 <do_config_file+0x132>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <parse_config_file@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@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    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     124e <do_config_file+0xae>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
js     1260 <do_config_file+0xc0>
movslq (%rsp),%rbx
test   %rbx,%rbx
je     123c <do_config_file+0x9c>
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1227 <do_config_file+0x87>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1050 <read@plt>
cmp    %ebx,%eax
jne    1230 <do_config_file+0x90>
movb   $0x0,0x0(%rbp,%rbx,1)
mov    %r15d,%edi
call   1040 <close@plt>
mov    %rbp,%rdi
call   10c0 <parse_config_file@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xe1c(%rip),%rdi
jmp    1237 <do_config_file+0x97>
lea    0xe22(%rip),%rdi
call   1090 <perror@plt>
mov    %r15d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
jmp    1270 <do_config_file+0xd0>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@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"
@.str.2 = [15 x i8] c"fixdep: malloc\00"
@.str.3 = [13 x i8] c"fixdep: read\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 i32, i32* %28
%30 = icmp eq i32 %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 %70
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = icmp ne i8* %39, null
br i1 %40, label %45, label %41
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
br label %70
45: ; preds = %34
%46 = load i32, i32* %4
%47 = load i8*, i8** %5
%48 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @read(i32 %46, i8* %47, i32 %49)
%51 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%52 = load i32, i32* %51
%53 = icmp ne i32 %50, %52
br i1 %53, label %54, label %58
54: ; preds = %45
%55 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* %4
%57 = call i32 @close(i32 %56)
br label %70
58: ; preds = %45
%59 = load i8*, i8** %5
%60 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%61 = load i32, i32* %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* %4
%65 = call i32 @close(i32 %64)
%66 = load i8*, i8** %5
%67 = call i32 @parse_config_file(i8* %66)
%68 = load i8*, i8** %5
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %58, %54, %41, %31
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@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"
@.str.2 = [15 x i8] c"fixdep: malloc\00"
@.str.3 = [13 x i8] c"fixdep: read\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 i32, i32* %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @close(i32 %5)
br label %45
26: ; preds = %20
%27 = add nsw i32 %22, 1
%28 = tail call i8* @malloc(i32 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @close(i32 %5)
br label %45
33: ; preds = %26
%34 = tail call i32 @read(i32 %5, i8* %28, i32 %22)
%35 = icmp eq i32 %34, %22
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%38 = tail call i32 @close(i32 %5)
br label %45
39: ; preds = %33
%40 = sext i32 %22 to i64
%41 = getelementptr inbounds i8, i8* %28, i64 %40
store i8 0, i8* %41
%42 = tail call i32 @close(i32 %5)
%43 = tail call i32 @parse_config_file(i8* %28)
%44 = tail call i32 @free(i8* %28)
br label %45
45: ; preds = %39, %36, %30, %24
ret void
}