#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ config_set(char *, char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ musicd_perror(int, char *, char *, char const *);
char *read_key(char *);
char *read_line(int /*<<< orphan*/ *);
char *read_value(char *);
int strlen(char *);
int config_load_file(const char *path) {
  FILE *file;
  char *line, *key, *value;
  int i;
  file = fopen(path, "r");
  if (!file) {
    musicd_perror(1, "config", "can't open config file '%s'", path);
    return -1;
  }
  while (1) {
    line = read_line(file);
    if (!line) {
      break;
    }
    for (i = 0;; ++i) {
      if (line[i] == '#' || line[i] == '\0') {
        goto next;
      }
      if (line[i] != ' ' && line[i] != '\t') {
        break;
      }
    }
    key = read_key(line);
    if (!key) {
      goto next;
    }
    value = read_value(line + strlen(key));
    config_set(key, value);
    free(key);
    free(value);
  next:
    free(line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<config_load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <config_load_file+0x53>
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe47(%rip),%rsi
lea    0xe47(%rip),%rdx
call   1060 <musicd_perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <config_load_file+0x161>
jmp    11d8 <config_load_file+0x58>
mov    -0x18(%rbp),%rdi
call   1070 <read_line@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f5 <config_load_file+0x75>
jmp    12da <config_load_file+0x15a>
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
je     1226 <config_load_file+0xa6>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    122b <config_load_file+0xab>
jmp    12cc <config_load_file+0x14c>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     125a <config_load_file+0xda>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     125a <config_load_file+0xda>
jmp    126d <config_load_file+0xed>
jmp    125f <config_load_file+0xdf>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11fc <config_load_file+0x7c>
mov    -0x20(%rbp),%rdi
call   1090 <read_key@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128a <config_load_file+0x10a>
jmp    12cc <config_load_file+0x14c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
cltq
add    %rax,%rdi
call   1040 <read_value@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <config_set@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11d8 <config_load_file+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_load_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xefb(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1256 <config_load_file+0xd6>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <read_line@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1277 <config_load_file+0xf7>
mov    %rax,%rbp
lea    0xe3c(%rip),%rbx
jmp    11ec <config_load_file+0x6c>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1070 <read_line@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1277 <config_load_file+0xf7>
mov    %rbp,%rax
nop
movzbl (%rax),%ecx
cmp    $0x23,%rcx
ja     1210 <config_load_file+0x90>
movslq (%rbx,%rcx,4),%rcx
add    %rbx,%rcx
jmp    *%rcx
add    $0x1,%rax
jmp    11f0 <config_load_file+0x70>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1090 <read_key@plt>
test   %rax,%rax
je     11d0 <config_load_file+0x50>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbp,%rdi
call   1040 <read_value@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rax,%rsi
call   10a0 <config_set@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    11d0 <config_load_file+0x50>
lea    0xe35(%rip),%rsi
lea    0xe35(%rip),%rdx
mov    $0x1,%edi
mov    %rbx,%rcx
call   1060 <musicd_perror@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"config\00"
@.str.2 = [28 x i8] c"can't open config file '%s'\00"
define i32 @config_load_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @musicd_perror(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32 -1, i32* %2
br label %86
16: ; preds = %1
br label %17
17: ; preds = %16, %82
%18 = load i32*, i32** %4
%19 = call i8* @read_line(i32* %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %17
br label %85
23: ; preds = %17
store i32 0, i32* %8
br label %24
24: ; preds = %59, %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 35
br i1 %31, label %40, label %32
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32, %24
br label %82
41: ; preds = %32
%42 = load i8*, i8** %5
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 32
br i1 %48, label %49, label %58
49: ; preds = %41
%50 = load i8*, i8** %5
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 9
br i1 %56, label %57, label %58
57: ; preds = %49
br label %62
58: ; preds = %49, %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %24
62: ; preds = %57
%63 = load i8*, i8** %5
%64 = call i8* @read_key(i8* %63)
store i8* %64, i8** %6
%65 = load i8*, i8** %6
%66 = icmp ne i8* %65, null
br i1 %66, label %68, label %67
67: ; preds = %62
br label %82
68: ; preds = %62
%69 = load i8*, i8** %5
%70 = load i8*, i8** %6
%71 = call i32 @strlen(i8* %70)
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = call i8* @read_value(i8* %73)
store i8* %74, i8** %7
%75 = load i8*, i8** %6
%76 = load i8*, i8** %7
%77 = call i32 @config_set(i8* %75, i8* %76)
%78 = load i8*, i8** %6
%79 = call i32 @free(i8* %78)
%80 = load i8*, i8** %7
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %68, %67, %40
%83 = load i8*, i8** %5
%84 = call i32 @free(i8* %83)
br label %17
85: ; preds = %22
store i32 0, i32* %2
br label %86
86: ; preds = %85, %13
%87 = load i32, i32* %2
ret i32 %87
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [7 x i8] c"config\00"
@.str.2 = [28 x i8] c"can't open config file '%s'\00"
define i32 @config_load_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i8* @read_line(i32* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %9
7: ; preds = %1
%8 = tail call i32 @musicd_perror(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %32
9: ; preds = %4, %28
%10 = phi i8* [ %30, %28 ], [ %5, %4 ]
br label %11
11: ; preds = %9, %15
%12 = phi i64 [ 0, %9 ], [ %16, %15 ]
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 35, label %28
i8 0, label %28
i8 32, label %15
i8 9, label %15
]
15: ; preds = %11, %11
%16 = add nuw i64 %12, 1
br label %11
17: ; preds = %11
%18 = tail call i8* @read_key(i8* %10)
%19 = icmp eq i8* %18, null
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = tail call i32 @strlen(i8* %18)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %10, i64 %22
%24 = tail call i8* @read_value(i8* %23)
%25 = tail call i32 @config_set(i8* %18, i8* %24)
%26 = tail call i32 @free(i8* %18)
%27 = tail call i32 @free(i8* %24)
br label %28
28: ; preds = %11, %11, %17, %20
%29 = tail call i32 @free(i8* %10)
%30 = tail call i8* @read_line(i32* %2)
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %9
32: ; preds = %28, %4, %7
%33 = phi i32 [ -1, %7 ], [ 0, %4 ], [ 0, %28 ]
ret i32 %33
}