#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct hsearch_data {
  int dummy;
};
typedef int /*<<< orphan*/ l;
struct TYPE_4__ {
  void *data;
  void *key;
};
typedef int /*<<< orphan*/ FILE;
typedef TYPE_1__ ENTRY;

/* Variables and functions */
int /*<<< orphan*/ ENTER;
int LINE_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fd_warn_permissions(char const *, int /*<<< orphan*/);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_key_value(char *, char **, char **);
int /*<<< orphan*/ handle_error(char *, char const *);
int /*<<< orphan*/ hsearch_r(TYPE_1__, int /*<<< orphan*/, TYPE_1__ **,
                             struct hsearch_data *);
char *parse_line(char *);
void *strdup(char *);
int /*<<< orphan*/ truncate_nl(char *);
int parse_config(struct hsearch_data *store, const char *filename) {
  FILE *f = NULL;
  f = fopen(filename, "re");
  if (!f) {
    handle_error("Failed to open configuration file '%s': %m", filename);
  }
  fd_warn_permissions(filename, fileno(f));
  while (!feof(f)) {
    char l[LINE_MAX];
    if (!fgets(l, sizeof(l), f)) {
      if (feof(f))
        break;
      handle_error("Failed to read configuration file '%s'", filename);
    }
    truncate_nl(l);
    char *line = parse_line(l);
    if (line) {
      char *key;
      char *value;
      get_key_value(line, &key, &value);
      ENTRY new_entry;
      ENTRY *return_val;
      new_entry.key = strdup(key);
      new_entry.data = strdup(value);
      hsearch_r(new_entry, ENTER, &return_val, store);
      free(key);
      free(value);
    }
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<parse_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1217 <parse_config+0x47>
mov    -0x10(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   10f0 <handle_error@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <fileno@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   1060 <fd_warn_permissions@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1252 <parse_config+0x82>
jmp    1365 <parse_config+0x195>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    12c1 <parse_config+0xf1>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12b1 <parse_config+0xe1>
movl   $0x3,-0x2c(%rbp)
jmp    1344 <parse_config+0x174>
mov    -0x10(%rbp),%rsi
lea    0xd72(%rip),%rdi
call   10f0 <handle_error@plt>
mov    -0x70(%rbp),%rdi
call   10b0 <truncate_nl@plt>
mov    -0x70(%rbp),%rdi
call   10a0 <parse_line@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     133d <parse_config+0x16d>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <get_key_value@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x58(%rbp)
mov    0x2cd4(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%r8
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
lea    -0x60(%rbp),%rcx
call   10c0 <hsearch_r@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     1360 <parse_config+0x190>
jmp    135b <parse_config+0x18b>
jmp    1365 <parse_config+0x195>
jmp    1233 <parse_config+0x63>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_config>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %rdi,-0x40(%rbp)
lea    0xe11(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    120e <parse_config+0x3e>
lea    0xdfd(%rip),%rdi
mov    %r15,%rsi
call   10f0 <handle_error@plt>
mov    %r13,%rdi
call   1090 <fileno@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <fd_warn_permissions@plt>
jmp    1233 <parse_config+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rsp
mov    %r13,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    12ff <parse_config+0x12f>
mov    %rsp,%r14
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %eax,%eax
jne    128f <parse_config+0xbf>
mov    %r13,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    12fc <parse_config+0x12c>
lea    0xda7(%rip),%rdi
mov    %r15,%rsi
call   10f0 <handle_error@plt>
mov    %r12,%rdi
call   10b0 <truncate_nl@plt>
mov    %r12,%rdi
call   10a0 <parse_line@plt>
test   %rax,%rax
je     1230 <parse_config+0x60>
mov    %rax,%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <get_key_value@plt>
mov    -0x38(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,%rbx
mov    -0x30(%rbp),%rdi
call   10e0 <strdup@plt>
mov    0x2d18(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,%rdi
mov    %rbx,%rsi
lea    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   10c0 <hsearch_r@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1230 <parse_config+0x60>
mov    %r14,%rsp
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hsearch_data = type { i32 }
%struct.TYPE_4__ = type { i8*, i8* }
@.str = [3 x i8] c"re\00"
@.str.1 = [43 x i8] c"Failed to open configuration file '%s': %m\00"
@LINE_MAX = global i32 0
@.str.2 = [39 x i8] c"Failed to read configuration file '%s'\00"
@ENTER = global i32 0
define i32 @parse_config(%struct.hsearch_data* %0, i8* %1) {
%3 = alloca %struct.hsearch_data*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca %struct.TYPE_4__
%13 = alloca %struct.TYPE_4__*
store %struct.hsearch_data* %0, %struct.hsearch_data** %3
store i8* %1, i8** %4
store i32* null, i32** %5
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @handle_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %2
%22 = load i8*, i8** %4
%23 = load i32*, i32** %5
%24 = call i32 @fileno(i32* %23)
%25 = call i32 @fd_warn_permissions(i8* %22, i32 %24)
br label %26
26: ; preds = %78, %21
%27 = load i32*, i32** %5
%28 = call i64 @feof(i32* %27)
%29 = icmp ne i64 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %79
31: ; preds = %26
%32 = load i32, i32* @LINE_MAX
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %6
%35 = alloca i8, i64 %33
store i64 %33, i64* %7
%36 = trunc i64 %33 to i32
%37 = load i32*, i32** %5
%38 = call i32 @fgets(i8* %35, i32 %36, i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %48, label %40
40: ; preds = %31
%41 = load i32*, i32** %5
%42 = call i64 @feof(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 3, i32* %8
br label %75
45: ; preds = %40
%46 = load i8*, i8** %4
%47 = call i32 @handle_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %31
%49 = call i32 @truncate_nl(i8* %35)
%50 = call i8* @parse_line(i8* %35)
store i8* %50, i8** %9
%51 = load i8*, i8** %9
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %74
53: ; preds = %48
%54 = load i8*, i8** %9
%55 = call i32 @get_key_value(i8* %54, i8** %10, i8** %11)
%56 = load i8*, i8** %10
%57 = call i8* @strdup(i8* %56)
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 1
store i8* %57, i8** %58
%59 = load i8*, i8** %11
%60 = call i8* @strdup(i8* %59)
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
store i8* %60, i8** %61
%62 = load i32, i32* @ENTER
%63 = load %struct.hsearch_data*, %struct.hsearch_data** %3
%64 = bitcast %struct.TYPE_4__* %12 to { i8*, i8* }*
%65 = getelementptr inbounds { i8*, i8* }, { i8*, i8* }* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = getelementptr inbounds { i8*, i8* }, { i8*, i8* }* %64, i32 0, i32 1
%68 = load i8*, i8** %67
%69 = call i32 @hsearch_r(i8* %66, i8* %68, i32 %62, %struct.TYPE_4__** %13, %struct.hsearch_data* %63)
%70 = load i8*, i8** %10
%71 = call i32 @free(i8* %70)
%72 = load i8*, i8** %11
%73 = call i32 @free(i8* %72)
br label %74
74: ; preds = %53, %48
store i32 0, i32* %8
br label %75
75: ; preds = %74, %44
%76 = load i8*, i8** %6
%77 = load i32, i32* %8
switch i32 %77, label %82 [
i32 0, label %78
i32 3, label %79
]
78: ; preds = %75
br label %26
79: ; preds = %75, %26
%80 = load i32*, i32** %5
%81 = call i32 @fclose(i32* %80)
ret i32 0
82: ; preds = %75
unreachable
}

LLVM IR (-O2):
%struct.hsearch_data = type { i32 }
%struct.TYPE_4__ = type { i8*, i8* }
@.str = [3 x i8] c"re\00"
@.str.1 = [43 x i8] c"Failed to open configuration file '%s': %m\00"
@LINE_MAX = global i32 0
@.str.2 = [39 x i8] c"Failed to read configuration file '%s'\00"
@ENTER = global i32 0
define i32 @parse_config(%struct.hsearch_data* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.TYPE_4__*
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @handle_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %2
%11 = tail call i32 @fileno(i32* %6)
%12 = tail call i32 @fd_warn_permissions(i8* %1, i32 %11)
%13 = call i64 @feof(i32* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %51
15: ; preds = %10
%16 = bitcast i8** %3 to i8*
%17 = bitcast i8** %4 to i8*
%18 = bitcast %struct.TYPE_4__** %5 to i8*
br label %19
19: ; preds = %15, %48
%20 = load i32, i32* @LINE_MAX
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
%24 = call i32 @fgets(i8* %23, i32 %20, i32* %6)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = call i64 @feof(i32* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %26
br label %51
30: ; preds = %26
%31 = call i32 @handle_error(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %32
32: ; preds = %30, %19
%33 = call i32 @truncate_nl(i8* %23)
%34 = call i8* @parse_line(i8* %23)
%35 = icmp eq i8* %34, null
br i1 %35, label %48, label %36
36: ; preds = %32
%37 = call i32 @get_key_value(i8* %34, i8** %3, i8** %4)
%38 = load i8*, i8** %3
%39 = call i8* @strdup(i8* %38)
%40 = load i8*, i8** %4
%41 = call i8* @strdup(i8* %40)
%42 = load i32, i32* @ENTER
%43 = call i32 @hsearch_r(i8* %41, i8* %39, i32 %42, %struct.TYPE_4__** %5, %struct.hsearch_data* %0)
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %4
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %32, %36
%49 = call i64 @feof(i32* %6)
%50 = icmp eq i64 %49, 0
br i1 %50, label %19, label %51
51: ; preds = %48, %10, %29
%52 = call i32 @fclose(i32* %6)
ret i32 0
}