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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ free(char *);
unsigned int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(unsigned int);
int open(char *, int /*<<< orphan*/);
unsigned int parse_config_file(char *, char *, unsigned int,
                               struct config_word **);
int /*<<< orphan*/ printf(char *, char *);
unsigned int read(int, char *, unsigned int);
int read_config_file(char *p_configname, struct config_word **pconfig_word,
                     unsigned int *p_config_num) {
  char *cfg_data_buf;
  int exitcode = 0;
  int h_config;
  unsigned int len;
  h_config = open(p_configname, O_RDONLY);
  if (h_config >= 0) {
    len = lseek(h_config, 0, SEEK_END);
    lseek(h_config, 0, SEEK_SET);
    cfg_data_buf = malloc(len + 1);
    if (cfg_data_buf) {
      cfg_data_buf[len] = 0;
      if (read(h_config, cfg_data_buf, len) == len) {
        *p_config_num =
            parse_config_file(p_configname, cfg_data_buf, len, pconfig_word);
      } else {
        exitcode = errno;
        printf("Failed to read file \"%s\". Please check whether it "
               "exists and verify your read permission.\n",
               p_configname);
      }
      free(cfg_data_buf);
    } else {
      exitcode = errno;
      printf("Failed to allocate memory for \"%s\"\n", p_configname);
    }
    close(h_config);
  } else {
    exitcode = errno;
    printf("Failed to open file \"%s\". Please check whether it "
           "exists and verify your permission.\n",
           p_configname);
  }
  return exitcode;
}


x86 assembly (clang, -O0):
<read_config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1294 <read_config_file+0x114>
mov    -0x28(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     126b <read_config_file+0xeb>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1070 <read@plt>
cmp    -0x2c(%rbp),%eax
jne    1241 <read_config_file+0xc1>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   10a0 <parse_config_file@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    125d <read_config_file+0xdd>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1287 <read_config_file+0x107>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
call   1060 <close@plt>
jmp    12b0 <read_config_file+0x130>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xdd4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1210 <read_config_file+0x90>
mov    %eax,%r13d
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%ebp
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0x1(%rbp),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     122b <read_config_file+0xab>
mov    %rax,%rbx
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <read@plt>
cmp    %ebp,%eax
jne    1246 <read_config_file+0xc6>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
call   10a0 <parse_config_file@plt>
mov    %eax,(%r15)
xor    %r15d,%r15d
jmp    125f <read_config_file+0xdf>
mov    0x2db9(%rip),%rax
mov    (%rax),%r15d
lea    0xe5e(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    126f <read_config_file+0xef>
mov    0x2d9e(%rip),%rax
mov    (%rax),%r15d
lea    0xe1f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    1267 <read_config_file+0xe7>
mov    0x2d83(%rip),%rax
mov    (%rax),%r15d
lea    0xda9(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%edi
call   1060 <close@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.config_word = type { i32 }
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@errno = global i32 0
@.str = [91 x i8] c"Failed to read file \22%s\22. Please check whether it exists and verify your read permission.\0A\00"
@.str.1 = [36 x i8] c"Failed to allocate memory for \22%s\22\0A\00"
@.str.2 = [86 x i8] c"Failed to open file \22%s\22. Please check whether it exists and verify your permission.\0A\00"
define i32 @read_config_file(i8* %0, %struct.config_word** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca %struct.config_word**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store %struct.config_word** %1, %struct.config_word*** %5
store i32* %2, i32** %6
store i32 0, i32* %8
%11 = load i8*, i8** %4
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %60
16: ; preds = %3
%17 = load i32, i32* %9
%18 = load i32, i32* @SEEK_END
%19 = call i32 @lseek(i32 %17, i32 0, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %9
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 0, i32 %21)
%23 = load i32, i32* %10
%24 = add i32 %23, 1
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %53
28: ; preds = %16
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %9
%34 = load i8*, i8** %7
%35 = load i32, i32* %10
%36 = call i32 @read(i32 %33, i8* %34, i32 %35)
%37 = load i32, i32* %10
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %28
%40 = load i8*, i8** %4
%41 = load i8*, i8** %7
%42 = load i32, i32* %10
%43 = load %struct.config_word**, %struct.config_word*** %5
%44 = call i32 @parse_config_file(i8* %40, i8* %41, i32 %42, %struct.config_word** %43)
%45 = load i32*, i32** %6
store i32 %44, i32* %45
br label %50
46: ; preds = %28
%47 = load i32, i32* @errno
store i32 %47, i32* %8
%48 = load i8*, i8** %4
%49 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46, %39
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
br label %57
53: ; preds = %16
%54 = load i32, i32* @errno
store i32 %54, i32* %8
%55 = load i8*, i8** %4
%56 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %53, %50
%58 = load i32, i32* %9
%59 = call i32 @close(i32 %58)
br label %64
60: ; preds = %3
%61 = load i32, i32* @errno
store i32 %61, i32* %8
%62 = load i8*, i8** %4
%63 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %60, %57
%65 = load i32, i32* %8
ret i32 %65
}

LLVM IR (-O2):
%struct.config_word = type { i32 }
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@errno = global i32 0
@.str = [91 x i8] c"Failed to read file \22%s\22. Please check whether it exists and verify your read permission.\0A\00"
@.str.1 = [36 x i8] c"Failed to allocate memory for \22%s\22\0A\00"
@.str.2 = [86 x i8] c"Failed to open file \22%s\22. Please check whether it exists and verify your permission.\0A\00"
define i32 @read_config_file(i8* %0, %struct.config_word** %1, i32* nocapture writeonly %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %34
7: ; preds = %3
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @lseek(i32 %5, i32 0, i32 %8)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %5, i32 0, i32 %10)
%12 = add i32 %9, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %28, label %15
15: ; preds = %7
%16 = zext i32 %9 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @read(i32 %5, i8* %13, i32 %9)
%19 = icmp eq i32 %18, %9
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @parse_config_file(i8* %0, i8* %13, i32 %9, %struct.config_word** %1)
store i32 %21, i32* %2
br label %25
22: ; preds = %15
%23 = load i32, i32* @errno
%24 = tail call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ 0, %20 ], [ %23, %22 ]
%27 = tail call i32 @free(i8* %13)
br label %31
28: ; preds = %7
%29 = load i32, i32* @errno
%30 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
31: ; preds = %28, %25
%32 = phi i32 [ %26, %25 ], [ %29, %28 ]
%33 = tail call i32 @close(i32 %5)
br label %37
34: ; preds = %3
%35 = load i32, i32* @errno
%36 = tail call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %37
37: ; preds = %34, %31
%38 = phi i32 [ %32, %31 ], [ %35, %34 ]
ret i32 %38
}