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

/* Variables and functions */
int /*<<< orphan*/ KeyValueaddparm(struct KeyValue *, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ isdigit(char);
struct KeyValue *newKeyValue();
int sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char const *, char *);
struct KeyValue *loadKeyValue(const char *filename) {
  struct KeyValue *p;
  FILE *in;
  int i;
  int eq;
  char str[1000], K[200], V[200];
  if (strcmp(filename, "-") == 0)
    in = stdin;
  else
    in = fopen(filename, "r");
  if (!in) {
    fprintf(stderr, "loadKeyValue: no file: %s\n", filename);
    return 0;
  }
  p = newKeyValue();
  while (1) {
    if (fgets(str, 999, in) == 0)
      break;
    if (feof(in))
      break;
    if (str[0] == 0)
      continue;
    eq = 0;
    for (i = 0; str[i] != 0; i++) {
      if (str[i] == '#')
        str[i] = 0;
      else if (str[i] == '=' && eq == 0) {
        str[i] = ' ';
        eq = 1;
      }
    }
    if (sscanf(str, "%s %s\n", K, V) != 2)
      continue;
    if (isdigit(K[0]))
      continue;
    KeyValueaddparm(p, K, V);
  }
  if (strcmp(filename, "-") != 0)
    fclose(in);
  return p;
}


x86 assembly (clang, -O0):
<loadKeyValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5b0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11dc <loadKeyValue+0x3c>
mov    0x2e18(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11f0 <loadKeyValue+0x50>
mov    -0x10(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <loadKeyValue+0x81>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13a1 <loadKeyValue+0x201>
mov    $0x0,%al
call   10a0 <newKeyValue@plt>
mov    %rax,-0x18(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x3e7,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1250 <loadKeyValue+0xb0>
jmp    1376 <loadKeyValue+0x1d6>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1268 <loadKeyValue+0xc8>
jmp    1376 <loadKeyValue+0x1d6>
movsbl -0x410(%rbp),%eax
cmp    $0x0,%eax
jne    127d <loadKeyValue+0xdd>
jmp    122c <loadKeyValue+0x8c>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1310 <loadKeyValue+0x170>
movslq -0x24(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x23,%eax
jne    12c6 <loadKeyValue+0x126>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
jmp    12fd <loadKeyValue+0x15d>
movslq -0x24(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x3d,%eax
jne    12f8 <loadKeyValue+0x158>
cmpl   $0x0,-0x28(%rbp)
jne    12f8 <loadKeyValue+0x158>
movslq -0x24(%rbp),%rax
movb   $0x20,-0x410(%rbp,%rax,1)
20
movl   $0x1,-0x28(%rbp)
jmp    12fd <loadKeyValue+0x15d>
jmp    1302 <loadKeyValue+0x162>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    128b <loadKeyValue+0xeb>
lea    -0x410(%rbp),%rdi
lea    -0x4e0(%rbp),%rdx
lea    -0x5b0(%rbp),%rcx
lea    0xcf3(%rip),%rsi
call   1090 <sscanf@plt>
cmp    $0x2,%eax
je     133f <loadKeyValue+0x19f>
jmp    122c <loadKeyValue+0x8c>
movsbl -0x4e0(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     135a <loadKeyValue+0x1ba>
jmp    122c <loadKeyValue+0x8c>
mov    -0x18(%rbp),%rdi
lea    -0x4e0(%rbp),%rsi
lea    -0x5b0(%rbp),%rdx
call   10c0 <KeyValueaddparm@plt>
jmp    122c <loadKeyValue+0x8c>
mov    -0x10(%rbp),%rdi
lea    0xc7f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1399 <loadKeyValue+0x1f9>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x5b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadKeyValue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x598,%rsp
mov    %rdi,%r14
lea    0xe45(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1315 <loadKeyValue+0x175>
lea    0xe32(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     1328 <loadKeyValue+0x188>
xor    %eax,%eax
call   10a0 <newKeyValue@plt>
mov    %rax,0x8(%rsp)
lea    0x1b0(%rsp),%rdi
mov    $0x3e7,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12f2 <loadKeyValue+0x152>
lea    0x1b0(%rsp),%r12
lea    0xe02(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xe0(%rsp),%r15
jmp    1249 <loadKeyValue+0xa9>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x3e7,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12f2 <loadKeyValue+0x152>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    12f2 <loadKeyValue+0x152>
mov    0x1b0(%rsp),%dl
test   %dl,%dl
je     1230 <loadKeyValue+0x90>
xor    %eax,%eax
lea    0x1b1(%rsp),%rcx
jmp    128c <loadKeyValue+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
mov    %dl,-0x1(%rcx)
movzbl (%rcx),%edx
add    $0x1,%rcx
cmp    $0x23,%dl
je     1280 <loadKeyValue+0xe0>
test   %dl,%dl
je     12b0 <loadKeyValue+0x110>
cmp    $0x3d,%dl
jne    1285 <loadKeyValue+0xe5>
test   %eax,%eax
jne    1285 <loadKeyValue+0xe5>
mov    $0x1,%eax
mov    $0x20,%dl
jmp    1282 <loadKeyValue+0xe2>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1090 <sscanf@plt>
cmp    $0x2,%eax
jne    1230 <loadKeyValue+0x90>
movsbl 0x10(%rsp),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1230 <loadKeyValue+0x90>
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10c0 <KeyValueaddparm@plt>
jmp    1230 <loadKeyValue+0x90>
lea    0xd07(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     130e <loadKeyValue+0x16e>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
jmp    1342 <loadKeyValue+0x1a2>
mov    0x2ccc(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11e4 <loadKeyValue+0x44>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
lea    0xccc(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x598,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.KeyValue = type { i32 }
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"loadKeyValue: no file: %s\0A\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define %struct.KeyValue* @loadKeyValue(i8* %0) {
%2 = alloca %struct.KeyValue*
%3 = alloca i8*
%4 = alloca %struct.KeyValue*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca [200 x i8]
%10 = alloca [200 x i8]
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i32*, i32** @stdin
store i32* %15, i32** %5
br label %19
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %5
br label %19
19: ; preds = %16, %14
%20 = load i32*, i32** %5
%21 = icmp ne i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store %struct.KeyValue* null, %struct.KeyValue** %2
br label %110
26: ; preds = %19
%27 = call %struct.KeyValue* (...) @newKeyValue()
store %struct.KeyValue* %27, %struct.KeyValue** %4
br label %28
28: ; preds = %26, %44, %89, %95, %96
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%30 = load i32*, i32** %5
%31 = call i64 @fgets(i8* %29, i32 999, i32* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
br label %101
34: ; preds = %28
%35 = load i32*, i32** %5
%36 = call i64 @feof(i32* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %101
39: ; preds = %34
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
br label %28
45: ; preds = %39
store i32 0, i32* %7
store i32 0, i32* %6
br label %46
46: ; preds = %80, %45
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %83
53: ; preds = %46
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 35
br i1 %59, label %60, label %64
60: ; preds = %53
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %62
store i8 0, i8* %63
br label %79
64: ; preds = %53
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 61
br i1 %70, label %71, label %78
71: ; preds = %64
%72 = load i32, i32* %7
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = load i32, i32* %6
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %76
store i8 32, i8* %77
store i32 1, i32* %7
br label %78
78: ; preds = %74, %71, %64
br label %79
79: ; preds = %78, %60
br label %80
80: ; preds = %79
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %6
br label %46
83: ; preds = %46
%84 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%85 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%86 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%87 = call i32 @sscanf(i8* %84, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %85, i8* %86)
%88 = icmp ne i32 %87, 2
br i1 %88, label %89, label %90
89: ; preds = %83
br label %28
90: ; preds = %83
%91 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%92 = load i8, i8* %91
%93 = call i64 @isdigit(i8 signext %92)
%94 = icmp ne i64 %93, 0
br i1 %94, label %95, label %96
95: ; preds = %90
br label %28
96: ; preds = %90
%97 = load %struct.KeyValue*, %struct.KeyValue** %4
%98 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%99 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%100 = call i32 @KeyValueaddparm(%struct.KeyValue* %97, i8* %98, i8* %99)
br label %28
101: ; preds = %38, %33
%102 = load i8*, i8** %3
%103 = call i64 @strcmp(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%104 = icmp ne i64 %103, 0
br i1 %104, label %105, label %108
105: ; preds = %101
%106 = load i32*, i32** %5
%107 = call i32 @fclose(i32* %106)
br label %108
108: ; preds = %105, %101
%109 = load %struct.KeyValue*, %struct.KeyValue** %4
store %struct.KeyValue* %109, %struct.KeyValue** %2
br label %110
110: ; preds = %108, %22
%111 = load %struct.KeyValue*, %struct.KeyValue** %2
ret %struct.KeyValue* %111
}

LLVM IR (-O2):
%struct.KeyValue = type { i32 }
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"loadKeyValue: no file: %s\0A\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define %struct.KeyValue* @loadKeyValue(i8* %0) {
%2 = alloca [1000 x i8]
%3 = alloca [200 x i8]
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32*, i32** @stdin
br label %14
12: ; preds = %1
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = phi i32* [ %11, %10 ], [ %13, %12 ]
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %64
20: ; preds = %14
%21 = tail call %struct.KeyValue* (...) @newKeyValue()
%22 = call i64 @fgets(i8* %5, i32 999, i32* %15)
%23 = icmp eq i64 %22, 0
br i1 %23, label %59, label %24
24: ; preds = %20, %56
%25 = call i64 @feof(i32* %15)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %59
27: ; preds = %24
%28 = load i8, i8* %5
%29 = icmp eq i8 %28, 0
br i1 %29, label %56, label %30
30: ; preds = %27, %42
%31 = phi i8 [ %46, %42 ], [ %28, %27 ]
%32 = phi i64 [ %44, %42 ], [ 0, %27 ]
%33 = phi i32 [ %43, %42 ], [ 0, %27 ]
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %32
switch i8 %31, label %35 [
i8 0, label %47
i8 35, label %39
]
35: ; preds = %30
%36 = icmp eq i8 %31, 61
%37 = icmp eq i32 %33, 0
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %39, label %42
39: ; preds = %35, %30
%40 = phi i8 [ 0, %30 ], [ 32, %35 ]
%41 = phi i32 [ %33, %30 ], [ 1, %35 ]
store i8 %40, i8* %34
br label %42
42: ; preds = %39, %35
%43 = phi i32 [ %33, %35 ], [ %41, %39 ]
%44 = add nuw i64 %32, 1
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
br label %30
47: ; preds = %30
%48 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7)
%49 = icmp eq i32 %48, 2
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i8, i8* %6
%52 = call i64 @isdigit(i8 signext %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @KeyValueaddparm(%struct.KeyValue* %21, i8* %6, i8* %7)
br label %56
56: ; preds = %54, %27, %47, %50
%57 = call i64 @fgets(i8* %5, i32 999, i32* %15)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %24
59: ; preds = %56, %24, %20
%60 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i32 @fclose(i32* %15)
br label %64
64: ; preds = %59, %62, %17
%65 = phi %struct.KeyValue* [ null, %17 ], [ %21, %62 ], [ %21, %59 ]
ret %struct.KeyValue* %65
}