#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 slist {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int _sconfig_parse_line(char *, int, char **, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int slist_insert(struct slist *, char *, int, char *);
char *strdup(char *);
int strlen(char *);
int _sconfig_load(const char *filename, struct slist *items) {
  FILE *fp = fopen(filename, "r");
  if (!fp)
    return -1;
  char *name, *value;
  char buffer[4096];
  while (fgets(buffer, sizeof(buffer), fp)) {
    int len = strlen(buffer);
    if (buffer[len - 1] != '\n')
      break;
    buffer[--len] = '\0';
    int ret = _sconfig_parse_line(buffer, len, &name, &value);
    if (ret == -1)
      break;
    else if (ret == 0)
      continue;
    char *dup_value = strdup(value);
    if (slist_insert(items, name, strlen(name) + 1, dup_value) == -1) {
      free(dup_value);
      break;
    }
  }
  int eof = feof(fp);
  fclose(fp);
  return eof ? 0 : -1;
}


x86 assembly (clang, -O0):
<_sconfig_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ce <_sconfig_load+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1322 <_sconfig_load+0x192>
jmp    11d3 <_sconfig_load+0x43>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12f4 <_sconfig_load+0x164>
lea    -0x1030(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1030(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1225 <_sconfig_load+0x95>
jmp    12f4 <_sconfig_load+0x164>
mov    -0x1034(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1034(%rbp)
cltq
movb   $0x0,-0x1030(%rbp,%rax,1)
lea    -0x1030(%rbp),%rdi
mov    -0x1034(%rbp),%esi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <_sconfig_parse_line@plt>
mov    %eax,-0x1038(%rbp)
cmpl   $0xffffffff,-0x1038(%rbp)
jne    1270 <_sconfig_load+0xe0>
jmp    12f4 <_sconfig_load+0x164>
cmpl   $0x0,-0x1038(%rbp)
jne    1282 <_sconfig_load+0xf2>
jmp    11d3 <_sconfig_load+0x43>
jmp    1287 <_sconfig_load+0xf7>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x1058(%rbp),%rdi
mov    -0x1050(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
mov    -0x1040(%rbp),%rcx
call   1090 <slist_insert@plt>
cmp    $0xffffffff,%eax
jne    12ef <_sconfig_load+0x15f>
mov    -0x1040(%rbp),%rdi
call   1030 <free@plt>
jmp    12f4 <_sconfig_load+0x164>
jmp    11d3 <_sconfig_load+0x43>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,-0x1044(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1044(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sconfig_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,0x8(%rsp)
lea    0xe53(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128a <_sconfig_load+0xfa>
mov    %rax,%r15
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1271 <_sconfig_load+0xe1>
lea    0x20(%rsp),%r13
lea    0x18(%rsp),%rbx
lea    0x10(%rsp),%r14
jmp    1205 <_sconfig_load+0x75>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1271 <_sconfig_load+0xe1>
mov    %r13,%rdi
call   1060 <strlen@plt>
movslq %eax,%rsi
cmpb   $0xa,0x1f(%rsp,%rsi,1)
jne    1271 <_sconfig_load+0xe1>
add    $0xffffffffffffffff,%rsi
movb   $0x0,0x20(%rsp,%rsi,1)
mov    %r13,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <_sconfig_parse_line@plt>
test   %eax,%eax
je     11f0 <_sconfig_load+0x60>
cmp    $0xffffffff,%eax
je     1271 <_sconfig_load+0xe1>
mov    0x10(%rsp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbp
mov    0x18(%rsp),%r12
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rcx
call   1090 <slist_insert@plt>
cmp    $0xffffffff,%eax
jne    11f0 <_sconfig_load+0x60>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1080 <feof@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <fclose@plt>
cmp    $0x1,%ebx
sbb    %eax,%eax
jmp    128f <_sconfig_load+0xff>
mov    $0xffffffff,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.slist = type { i32 }
@.str = [2 x i8] c"r\00"
define i32 @_sconfig_load(i8* %0, %struct.slist* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.slist*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4096 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %4
store %struct.slist* %1, %struct.slist** %5
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %2
store i32 -1, i32* %3
br label %76
19: ; preds = %2
br label %20
20: ; preds = %66, %50, %19
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i64 @fgets(i8* %21, i32 4096, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %67
25: ; preds = %20
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 10
br i1 %34, label %35, label %36
35: ; preds = %25
br label %67
36: ; preds = %25
%37 = load i32, i32* %10
%38 = add nsw i32 %37, -1
store i32 %38, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%42 = load i32, i32* %10
%43 = call i32 @_sconfig_parse_line(i8* %41, i32 %42, i8** %7, i8** %8)
store i32 %43, i32* %11
%44 = load i32, i32* %11
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %36
br label %67
47: ; preds = %36
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
br label %20
51: ; preds = %47
br label %52
52: ; preds = %51
%53 = load i8*, i8** %8
%54 = call i8* @strdup(i8* %53)
store i8* %54, i8** %12
%55 = load %struct.slist*, %struct.slist** %5
%56 = load i8*, i8** %7
%57 = load i8*, i8** %7
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %58, 1
%60 = load i8*, i8** %12
%61 = call i32 @slist_insert(%struct.slist* %55, i8* %56, i32 %59, i8* %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %66
63: ; preds = %52
%64 = load i8*, i8** %12
%65 = call i32 @free(i8* %64)
br label %67
66: ; preds = %52
br label %20
67: ; preds = %63, %46, %35, %20
%68 = load i32*, i32** %6
%69 = call i32 @feof(i32* %68)
store i32 %69, i32* %13
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %13
%73 = icmp ne i32 %72, 0
%74 = zext i1 %73 to i64
%75 = select i1 %73, i32 0, i32 -1
store i32 %75, i32* %3
br label %76
76: ; preds = %67, %18
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
%struct.slist = type { i32 }
@.str = [2 x i8] c"r\00"
define i32 @_sconfig_load(i8* nocapture %0, %struct.slist* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %2
%9 = bitcast i8** %3 to i8*
%10 = bitcast i8** %4 to i8*
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%12 = call i64 @fgets(i8* %11, i32 4096, i32* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %36, label %14
14: ; preds = %8, %33
%15 = call i32 @strlen(i8* %11)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %36
21: ; preds = %14
store i8 0, i8* %18
%22 = call i32 @_sconfig_parse_line(i8* %11, i32 %16, i8** %3, i8** %4)
switch i32 %22, label %23 [
i32 -1, label %36
i32 0, label %33
]
23: ; preds = %21
%24 = load i8*, i8** %4
%25 = call i8* @strdup(i8* %24)
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = call i32 @slist_insert(%struct.slist* %1, i8* %26, i32 %28, i8* %25)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @free(i8* %25)
br label %36
33: ; preds = %21, %23
%34 = call i64 @fgets(i8* %11, i32 4096, i32* %6)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %14
36: ; preds = %33, %14, %21, %8, %31
%37 = call i32 @feof(i32* %6)
%38 = call i32 @fclose(i32* %6)
%39 = icmp eq i32 %37, 0
%40 = sext i1 %39 to i32
br label %41
41: ; preds = %2, %36
%42 = phi i32 [ %40, %36 ], [ -1, %2 ]
ret i32 %42
}