#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*/ EXIT_FAILURE;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
                int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ parse_file(char *);
int /*<<< orphan*/ perror(char *);
int stat(char *, struct stat *);
int init_config(char *config_file) {
  int fd;
  char *buffer;
  struct stat buf;
  if (-1 == (fd = open(config_file, O_RDONLY))) {
    return 1;
  }
  if (-1 == stat(config_file, &buf)) {
    close(fd);
    exit(EXIT_FAILURE);
  }
  buffer = (char *)mmap(0, (int)buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
  if ((char *)-1 == buffer) {
    perror("Philsh: Impossible de mapper le fichier de configuration en "
           "mémoire\n");
    close(fd);
    exit(EXIT_FAILURE);
  }
  parse_file(buffer);
  munmap(buffer, (int)buf.st_size);
  return 0;
}


x86 assembly (clang, -O0):
<init_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11bc <init_config+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    126b <init_config+0xeb>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ee <init_config+0x6e>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    0x2de4(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x20(%rbp),%rax
jne    124c <init_config+0xcc>
lea    0xdcf(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1080 <parse_file@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %eax,%esi
call   1060 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_config>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11f6 <init_config+0x76>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1216 <init_config+0x96>
mov    (%rsp),%r14d
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
mov    0x2e25(%rip),%rax
mov    (%rax),%ecx
xor    %r15d,%r15d
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     120a <init_config+0x8a>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <parse_file@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <munmap@plt>
jmp    11fc <init_config+0x7c>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1090 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str = [70 x i8] c"Philsh: Impossible de mapper le fichier de configuration en m\C3\A9moire\0A\00"
define i32 @init_config(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %4
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %46
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @stat(i8* %13, %struct.stat* %6)
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = load i32, i32* @PROT_READ
%26 = load i32, i32* @MAP_SHARED
%27 = load i32, i32* %4
%28 = call i64 @mmap(i32 0, i32 %24, i32 %25, i32 %26, i32 %27, i32 0)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = icmp eq i8* inttoptr (i64 -1 to i8*), %30
br i1 %31, label %32, label %38
32: ; preds = %21
%33 = call i32 @perror(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %21
%39 = load i8*, i8** %5
%40 = call i32 @parse_file(i8* %39)
%41 = load i8*, i8** %5
%42 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%43 = load i64, i64* %42
%44 = trunc i64 %43 to i32
%45 = call i32 @munmap(i8* %41, i32 %44)
store i32 0, i32* %2
br label %46
46: ; preds = %38, %11
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str = [70 x i8] c"Philsh: Impossible de mapper le fichier de configuration en m\C3\A9moire\0A\00"
define i32 @init_config(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 eq i32 %5, -1
br i1 %6, label %31, label %7
7: ; preds = %1
%8 = call i32 @stat(i8* %0, %struct.stat* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @close(i32 %5)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @MAP_SHARED
%20 = tail call i64 @mmap(i32 0, i32 %17, i32 %18, i32 %19, i32 %5, i32 0)
%21 = inttoptr i64 %20 to i8*
%22 = icmp eq i8* %21, inttoptr (i64 -1 to i8*)
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = tail call i32 @perror(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @close(i32 %5)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
%29 = tail call i32 @parse_file(i8* %21)
%30 = tail call i32 @munmap(i8* %21, i32 %17)
br label %31
31: ; preds = %1, %28
%32 = phi i32 [ 0, %28 ], [ 1, %1 ]
ret i32 %32
}