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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
char *find_char_or_comment(char *, char);
char *lskip(char *);
char *rstrip(char *);
int /*<<< orphan*/ strncpy0(char *, char *, int);
int ini_parse_file(FILE *file,
                   int (*handler)(void *user, char *section, char *key,
                                  char *value),
                   void *user) {
  char line[1024];
  char section[32] = "";
  char prev_name[32] = "";
  char *start;
  char *end;
  char *name;
  char *value;
  int lineno = 0;
  int error = 0;
  while (fgets(line, 1024, file) != NULL) {
    lineno++;
    start = line;
    start = lskip(rstrip(start));
    if (*start == ';' || *start == '#') {
    } else if (*start == '[') {
      end = find_char_or_comment(start + 1, ']');
      if (*end == ']') {
        *end = '\0';
        strncpy0(section, start + 1, sizeof(section));
        *prev_name = '\0';
      } else if (!error) {
        error = lineno;
      }
    } else if (*start && *start != ';') {
      end = find_char_or_comment(start, '=');
      if (*end != '=') {
        end = find_char_or_comment(start, ':');
      }
      if (*end == '=' || *end == ':') {
        *end = '\0';
        name = rstrip(start);
        value = lskip(end + 1);
        end = find_char_or_comment(value, '\0');
        if (*end == ';')
          *end = '\0';
        rstrip(value);
        strncpy0(prev_name, name, sizeof(prev_name));
        if (handler(user, section, name, value) && !error)
          error = lineno;
      } else if (!error) {
        error = lineno;
      }
    }
    if (error)
      break;
  }
  return error;
}


x86 assembly (clang, -O0):
<ini_parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x484(%rbp)
movl   $0x0,-0x488(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     146d <ini_parse_file+0x30d>
mov    -0x484(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x484(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x468(%rbp),%rdi
call   1030 <rstrip@plt>
mov    %rax,%rdi
call   1080 <lskip@plt>
mov    %rax,-0x468(%rbp)
mov    -0x468(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     122e <ini_parse_file+0xce>
mov    -0x468(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1233 <ini_parse_file+0xd3>
jmp    1456 <ini_parse_file+0x2f6>
mov    -0x468(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    12ca <ini_parse_file+0x16a>
mov    -0x468(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5d,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x470(%rbp)
mov    -0x470(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    12a7 <ini_parse_file+0x147>
mov    -0x470(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x440(%rbp),%rdi
mov    -0x468(%rbp),%rsi
add    $0x1,%rsi
mov    $0x20,%edx
call   1070 <strncpy0@plt>
movb   $0x0,-0x460(%rbp)
jmp    12c5 <ini_parse_file+0x165>
cmpl   $0x0,-0x488(%rbp)
jne    12c0 <ini_parse_file+0x160>
mov    -0x484(%rbp),%eax
mov    %eax,-0x488(%rbp)
jmp    12c5 <ini_parse_file+0x165>
jmp    1451 <ini_parse_file+0x2f1>
mov    -0x468(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     144c <ini_parse_file+0x2ec>
mov    -0x468(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     144c <ini_parse_file+0x2ec>
mov    -0x468(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x470(%rbp)
mov    -0x470(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
je     1333 <ini_parse_file+0x1d3>
mov    -0x468(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x470(%rbp)
mov    -0x470(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
je     1359 <ini_parse_file+0x1f9>
mov    -0x470(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1429 <ini_parse_file+0x2c9>
mov    -0x470(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x468(%rbp),%rdi
call   1030 <rstrip@plt>
mov    %rax,-0x478(%rbp)
mov    -0x470(%rbp),%rdi
add    $0x1,%rdi
call   1080 <lskip@plt>
mov    %rax,-0x480(%rbp)
mov    -0x480(%rbp),%rdi
xor    %esi,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x470(%rbp)
mov    -0x470(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    13bf <ini_parse_file+0x25f>
mov    -0x470(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x480(%rbp),%rdi
call   1030 <rstrip@plt>
lea    -0x460(%rbp),%rdi
mov    -0x478(%rbp),%rsi
mov    $0x20,%edx
call   1070 <strncpy0@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
lea    -0x440(%rbp),%rsi
mov    -0x478(%rbp),%rdx
mov    -0x480(%rbp),%rcx
call   *%rax
cmp    $0x0,%eax
je     1424 <ini_parse_file+0x2c4>
cmpl   $0x0,-0x488(%rbp)
jne    1424 <ini_parse_file+0x2c4>
mov    -0x484(%rbp),%eax
mov    %eax,-0x488(%rbp)
jmp    1447 <ini_parse_file+0x2e7>
cmpl   $0x0,-0x488(%rbp)
jne    1442 <ini_parse_file+0x2e2>
mov    -0x484(%rbp),%eax
mov    %eax,-0x488(%rbp)
jmp    1447 <ini_parse_file+0x2e7>
jmp    144c <ini_parse_file+0x2ec>
jmp    1451 <ini_parse_file+0x2f1>
jmp    1456 <ini_parse_file+0x2f6>
cmpl   $0x0,-0x488(%rbp)
je     1468 <ini_parse_file+0x308>
jmp    146d <ini_parse_file+0x30d>
jmp    11b1 <ini_parse_file+0x51>
mov    -0x488(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ini_parse_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,(%rsp)
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x50(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12f8 <ini_parse_file+0x1a8>
xor    %r15d,%r15d
mov    $0x1,%ebp
lea    0x50(%rsp),%r12
jmp    120c <ini_parse_file+0xbc>
mov    %rbx,%rdi
call   1030 <rstrip@plt>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    $0x20,%edx
call   1060 <strncpy0@plt>
mov    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   *(%rsp)
test   %eax,%eax
jne    130e <ini_parse_file+0x1be>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebp
test   %rax,%rax
je     12f8 <ini_parse_file+0x1a8>
add    $0x1,%r15d
mov    %r12,%rdi
call   1030 <rstrip@plt>
mov    %rax,%rdi
call   1070 <lskip@plt>
mov    %rax,%r13
movzbl (%rax),%eax
cmp    $0x3a,%al
jg     1240 <ini_parse_file+0xf0>
test   %al,%al
je     11f0 <ini_parse_file+0xa0>
cmp    $0x23,%al
je     11f0 <ini_parse_file+0xa0>
jmp    1290 <ini_parse_file+0x140>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x3b,%al
je     11f0 <ini_parse_file+0xa0>
cmp    $0x5b,%al
jne    1290 <ini_parse_file+0x140>
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x5d,%esi
call   1050 <find_char_or_comment@plt>
cmpb   $0x5d,(%rax)
jne    12fa <ini_parse_file+0x1aa>
movb   $0x0,(%rax)
lea    0x30(%rsp),%rdi
mov    %r13,%rsi
mov    $0x20,%edx
call   1060 <strncpy0@plt>
movb   $0x0,0x10(%rsp)
jmp    11f0 <ini_parse_file+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x3d,%esi
call   1050 <find_char_or_comment@plt>
mov    %rax,%rbx
cmpb   $0x3d,(%rax)
je     12c0 <ini_parse_file+0x170>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1050 <find_char_or_comment@plt>
mov    %rax,%rbx
movzbl (%rax),%eax
cmp    $0x3d,%al
je     12c0 <ini_parse_file+0x170>
cmp    $0x3a,%al
jne    130e <ini_parse_file+0x1be>
movb   $0x0,(%rbx)
mov    %r13,%rdi
call   1030 <rstrip@plt>
mov    %rax,%r13
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <lskip@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <find_char_or_comment@plt>
cmpb   $0x3b,(%rax)
jne    11ae <ini_parse_file+0x5e>
movb   $0x0,(%rax)
jmp    11ae <ini_parse_file+0x5e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15d,%ebp
jmp    12fa <ini_parse_file+0x1aa>

LLVM IR (-O0):
define i32 @ini_parse_file(i32* %0, i32 (i8*, i8*, i8*, i8*)* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32 (i8*, i8*, i8*, i8*)*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [32 x i8]
%9 = alloca [32 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %4
store i32 (i8*, i8*, i8*, i8*)* %1, i32 (i8*, i8*, i8*, i8*)** %5
store i8* %2, i8** %6
%16 = bitcast [32 x i8]* %8 to i8*
%17 = bitcast [32 x i8]* %9 to i8*
store i32 0, i32* %14
store i32 0, i32* %15
br label %18
18: ; preds = %144, %3
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 1024, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %145
23: ; preds = %18
%24 = load i32, i32* %14
%25 = add nsw i32 %24, 1
store i32 %25, i32* %14
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = call i8* @rstrip(i8* %27)
%29 = call i8* @lskip(i8* %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 59
br i1 %33, label %39, label %34
34: ; preds = %23
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 35
br i1 %38, label %39, label %40
39: ; preds = %34, %23
br label %140
40: ; preds = %34
%41 = load i8*, i8** %10
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 91
br i1 %44, label %45, label %67
45: ; preds = %40
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i8* @find_char_or_comment(i8* %47, i8 signext 93)
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 93
br i1 %52, label %53, label %60
53: ; preds = %45
%54 = load i8*, i8** %11
store i8 0, i8* %54
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i32 @strncpy0(i8* %55, i8* %57, i32 32)
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
store i8 0, i8* %59
br label %66
60: ; preds = %45
%61 = load i32, i32* %15
%62 = icmp ne i32 %61, 0
br i1 %62, label %65, label %63
63: ; preds = %60
%64 = load i32, i32* %14
store i32 %64, i32* %15
br label %65
65: ; preds = %63, %60
br label %66
66: ; preds = %65, %53
br label %139
67: ; preds = %40
%68 = load i8*, i8** %10
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %138
72: ; preds = %67
%73 = load i8*, i8** %10
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp ne i32 %75, 59
br i1 %76, label %77, label %138
77: ; preds = %72
%78 = load i8*, i8** %10
%79 = call i8* @find_char_or_comment(i8* %78, i8 signext 61)
store i8* %79, i8** %11
%80 = load i8*, i8** %11
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp ne i32 %82, 61
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = load i8*, i8** %10
%86 = call i8* @find_char_or_comment(i8* %85, i8 signext 58)
store i8* %86, i8** %11
br label %87
87: ; preds = %84, %77
%88 = load i8*, i8** %11
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 61
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = load i8*, i8** %11
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 58
br i1 %96, label %97, label %131
97: ; preds = %92, %87
%98 = load i8*, i8** %11
store i8 0, i8* %98
%99 = load i8*, i8** %10
%100 = call i8* @rstrip(i8* %99)
store i8* %100, i8** %12
%101 = load i8*, i8** %11
%102 = getelementptr inbounds i8, i8* %101, i64 1
%103 = call i8* @lskip(i8* %102)
store i8* %103, i8** %13
%104 = load i8*, i8** %13
%105 = call i8* @find_char_or_comment(i8* %104, i8 signext 0)
store i8* %105, i8** %11
%106 = load i8*, i8** %11
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = icmp eq i32 %108, 59
br i1 %109, label %110, label %112
110: ; preds = %97
%111 = load i8*, i8** %11
store i8 0, i8* %111
br label %112
112: ; preds = %110, %97
%113 = load i8*, i8** %13
%114 = call i8* @rstrip(i8* %113)
%115 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%116 = load i8*, i8** %12
%117 = call i32 @strncpy0(i8* %115, i8* %116, i32 32)
%118 = load i32 (i8*, i8*, i8*, i8*)*, i32 (i8*, i8*, i8*, i8*)** %5
%119 = load i8*, i8** %6
%120 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%121 = load i8*, i8** %12
%122 = load i8*, i8** %13
%123 = call i32 %118(i8* %119, i8* %120, i8* %121, i8* %122)
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %130
125: ; preds = %112
%126 = load i32, i32* %15
%127 = icmp ne i32 %126, 0
br i1 %127, label %130, label %128
128: ; preds = %125
%129 = load i32, i32* %14
store i32 %129, i32* %15
br label %130
130: ; preds = %128, %125, %112
br label %137
131: ; preds = %92
%132 = load i32, i32* %15
%133 = icmp ne i32 %132, 0
br i1 %133, label %136, label %134
134: ; preds = %131
%135 = load i32, i32* %14
store i32 %135, i32* %15
br label %136
136: ; preds = %134, %131
br label %137
137: ; preds = %136, %130
br label %138
138: ; preds = %137, %72, %67
br label %139
139: ; preds = %138, %66
br label %140
140: ; preds = %139, %39
%141 = load i32, i32* %15
%142 = icmp ne i32 %141, 0
br i1 %142, label %143, label %144
143: ; preds = %140
br label %145
144: ; preds = %140
br label %18
145: ; preds = %143, %18
%146 = load i32, i32* %15
ret i32 %146
}

LLVM IR (-O2):
define i32 @ini_parse_file(i32* nocapture %0, i32 (i8*, i8*, i8*, i8*)* nocapture %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = call i32* @fgets(i8* %7, i32 1024, i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %49, label %12
12: ; preds = %3, %46
%13 = phi i32 [ %14, %46 ], [ 0, %3 ]
%14 = add nuw nsw i32 %13, 1
%15 = call i8* @rstrip(i8* %7)
%16 = call i8* @lskip(i8* %15)
%17 = load i8, i8* %16
switch i8 %17, label %25 [
i8 59, label %46
i8 35, label %46
i8 91, label %18
i8 0, label %46
]
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = call i8* @find_char_or_comment(i8* %19, i8 signext 93)
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 93
br i1 %22, label %23, label %49
23: ; preds = %18
store i8 0, i8* %20
%24 = call i32 @strncpy0(i8* %8, i8* %19, i32 32)
store i8 0, i8* %9
br label %46
25: ; preds = %12
%26 = call i8* @find_char_or_comment(i8* %16, i8 signext 61)
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 61
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i8* @find_char_or_comment(i8* %16, i8 signext 58)
%31 = load i8, i8* %30
switch i8 %31, label %49 [
i8 61, label %32
i8 58, label %32
]
32: ; preds = %25, %29, %29
%33 = phi i8* [ %30, %29 ], [ %30, %29 ], [ %26, %25 ]
store i8 0, i8* %33
%34 = call i8* @rstrip(i8* %16)
%35 = getelementptr inbounds i8, i8* %33, i64 1
%36 = call i8* @lskip(i8* %35)
%37 = call i8* @find_char_or_comment(i8* %36, i8 signext 0)
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 59
br i1 %39, label %40, label %41
40: ; preds = %32
store i8 0, i8* %37
br label %41
41: ; preds = %40, %32
%42 = call i8* @rstrip(i8* %36)
%43 = call i32 @strncpy0(i8* %9, i8* %34, i32 32)
%44 = call i32 %1(i8* %2, i8* %8, i8* %34, i8* %36)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41, %12, %12, %12, %23
%47 = call i32* @fgets(i8* %7, i32 1024, i32* %0)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %12
49: ; preds = %46, %18, %41, %29, %3
%50 = phi i32 [ 0, %3 ], [ %14, %29 ], [ %14, %41 ], [ %14, %18 ], [ 0, %46 ]
ret i32 %50
}