#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*/ line;
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 *, const char *, const char *,
                                  const char *),
                   void *user) {
  char line[1024];
  char section[64] = "";
  char prev_name[64] = "";
  char *start;
  char *end;
  char *name;
  char *value;
  int lineno = 0;
  int error = 0;
  while (fgets(line, sizeof(line), file) != NULL) {
    lineno++;
    start = lskip(rstrip(line));
    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;
      }
    }
  }
  return error;
}


x86 assembly (clang, -O0):
<ini_parse_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x4a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
movl   $0x0,-0x4c4(%rbp)
movl   $0x0,-0x4c8(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     144d <ini_parse_file+0x2ed>
mov    -0x4c4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c4(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <rstrip@plt>
mov    %rax,%rdi
call   1080 <lskip@plt>
mov    %rax,-0x4a8(%rbp)
mov    -0x4a8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     1220 <ini_parse_file+0xc0>
mov    -0x4a8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1225 <ini_parse_file+0xc5>
jmp    1448 <ini_parse_file+0x2e8>
mov    -0x4a8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    12bc <ini_parse_file+0x15c>
mov    -0x4a8(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5d,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x4b0(%rbp)
mov    -0x4b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5d,%eax
jne    1299 <ini_parse_file+0x139>
mov    -0x4b0(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x460(%rbp),%rdi
mov    -0x4a8(%rbp),%rsi
add    $0x1,%rsi
mov    $0x40,%edx
call   1070 <strncpy0@plt>
movb   $0x0,-0x4a0(%rbp)
jmp    12b7 <ini_parse_file+0x157>
cmpl   $0x0,-0x4c8(%rbp)
jne    12b2 <ini_parse_file+0x152>
mov    -0x4c4(%rbp),%eax
mov    %eax,-0x4c8(%rbp)
jmp    12b7 <ini_parse_file+0x157>
jmp    1443 <ini_parse_file+0x2e3>
mov    -0x4a8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     143e <ini_parse_file+0x2de>
mov    -0x4a8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     143e <ini_parse_file+0x2de>
mov    -0x4a8(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x4b0(%rbp)
mov    -0x4b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
je     1325 <ini_parse_file+0x1c5>
mov    -0x4a8(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x4b0(%rbp)
mov    -0x4b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
je     134b <ini_parse_file+0x1eb>
mov    -0x4b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    141b <ini_parse_file+0x2bb>
mov    -0x4b0(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4a8(%rbp),%rdi
call   1030 <rstrip@plt>
mov    %rax,-0x4b8(%rbp)
mov    -0x4b0(%rbp),%rdi
add    $0x1,%rdi
call   1080 <lskip@plt>
mov    %rax,-0x4c0(%rbp)
mov    -0x4c0(%rbp),%rdi
xor    %esi,%esi
call   1060 <find_char_or_comment@plt>
mov    %rax,-0x4b0(%rbp)
mov    -0x4b0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    13b1 <ini_parse_file+0x251>
mov    -0x4b0(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4c0(%rbp),%rdi
call   1030 <rstrip@plt>
lea    -0x4a0(%rbp),%rdi
mov    -0x4b8(%rbp),%rsi
mov    $0x40,%edx
call   1070 <strncpy0@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
lea    -0x460(%rbp),%rsi
mov    -0x4b8(%rbp),%rdx
mov    -0x4c0(%rbp),%rcx
call   *%rax
cmp    $0x0,%eax
jne    1416 <ini_parse_file+0x2b6>
cmpl   $0x0,-0x4c8(%rbp)
jne    1416 <ini_parse_file+0x2b6>
mov    -0x4c4(%rbp),%eax
mov    %eax,-0x4c8(%rbp)
jmp    1439 <ini_parse_file+0x2d9>
cmpl   $0x0,-0x4c8(%rbp)
jne    1434 <ini_parse_file+0x2d4>
mov    -0x4c4(%rbp),%eax
mov    %eax,-0x4c8(%rbp)
jmp    1439 <ini_parse_file+0x2d9>
jmp    143e <ini_parse_file+0x2de>
jmp    1443 <ini_parse_file+0x2e3>
jmp    1448 <ini_parse_file+0x2e8>
jmp    11b1 <ini_parse_file+0x51>
mov    -0x4c8(%rbp),%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ini_parse_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4a8,%rsp
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xa0(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1314 <ini_parse_file+0x1c4>
mov    $0x1,%r12d
lea    0xa0(%rsp),%r15
jmp    1224 <ini_parse_file+0xd4>
mov    %rbp,%rdi
call   1030 <rstrip@plt>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1060 <strncpy0@plt>
mov    0x18(%rsp),%rdi
lea    0x60(%rsp),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   *0x10(%rsp)
mov    0xc(%rsp),%ebx
or     %ebx,%eax
cmove  %r12d,%ebx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%r12d
test   %rax,%rax
je     1314 <ini_parse_file+0x1c4>
mov    %r15,%rdi
call   1030 <rstrip@plt>
mov    %rax,%rdi
call   1070 <lskip@plt>
mov    %rax,%r13
movzbl (%rax),%eax
cmp    $0x3a,%al
jg     1250 <ini_parse_file+0x100>
test   %al,%al
je     1207 <ini_parse_file+0xb7>
cmp    $0x23,%al
je     1207 <ini_parse_file+0xb7>
jmp    12a0 <ini_parse_file+0x150>
nopl   0x0(%rax,%rax,1)
cmp    $0x3b,%al
je     1207 <ini_parse_file+0xb7>
cmp    $0x5b,%al
jne    12a0 <ini_parse_file+0x150>
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x5d,%esi
call   1050 <find_char_or_comment@plt>
cmpb   $0x5d,(%rax)
jne    130d <ini_parse_file+0x1bd>
movb   $0x0,(%rax)
lea    0x60(%rsp),%rdi
mov    %r13,%rsi
mov    $0x40,%edx
call   1060 <strncpy0@plt>
movb   $0x0,0x20(%rsp)
jmp    1207 <ini_parse_file+0xb7>
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,%rbp
cmpb   $0x3d,(%rax)
je     12d0 <ini_parse_file+0x180>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1050 <find_char_or_comment@plt>
mov    %rax,%rbp
movzbl (%rax),%eax
cmp    $0x3d,%al
je     12d0 <ini_parse_file+0x180>
cmp    $0x3a,%al
jne    130d <ini_parse_file+0x1bd>
mov    %ebx,0xc(%rsp)
movb   $0x0,0x0(%rbp)
mov    %r13,%rdi
call   1030 <rstrip@plt>
mov    %rax,%rbx
add    $0x1,%rbp
mov    %rbp,%rdi
call   1070 <lskip@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <find_char_or_comment@plt>
cmpb   $0x3b,(%rax)
jne    11cf <ini_parse_file+0x7f>
movb   $0x0,(%rax)
jmp    11cf <ini_parse_file+0x7f>
test   %ebx,%ebx
jmp    1203 <ini_parse_file+0xb3>
mov    %ebx,%eax
add    $0x4a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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 [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 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 %60, label %12
12: ; preds = %3, %56
%13 = phi i32 [ %57, %56 ], [ 0, %3 ]
%14 = phi i32 [ %15, %56 ], [ 0, %3 ]
%15 = add nuw nsw i32 %14, 1
%16 = call i8* @rstrip(i8* %7)
%17 = call i8* @lskip(i8* %16)
%18 = load i8, i8* %17
switch i8 %18, label %29 [
i8 59, label %56
i8 35, label %56
i8 91, label %19
i8 0, label %56
]
19: ; preds = %12
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = call i8* @find_char_or_comment(i8* %20, i8 signext 93)
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 93
br i1 %23, label %24, label %26
24: ; preds = %19
store i8 0, i8* %21
%25 = call i32 @strncpy0(i8* %8, i8* %20, i32 64)
store i8 0, i8* %9
br label %56
26: ; preds = %19
%27 = icmp eq i32 %13, 0
%28 = select i1 %27, i32 %15, i32 %13
br label %56
29: ; preds = %12
%30 = call i8* @find_char_or_comment(i8* %17, i8 signext 61)
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 61
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = call i8* @find_char_or_comment(i8* %17, i8 signext 58)
%35 = load i8, i8* %34
switch i8 %35, label %53 [
i8 61, label %36
i8 58, label %36
]
36: ; preds = %29, %33, %33
%37 = phi i8* [ %34, %33 ], [ %34, %33 ], [ %30, %29 ]
store i8 0, i8* %37
%38 = call i8* @rstrip(i8* %17)
%39 = getelementptr inbounds i8, i8* %37, i64 1
%40 = call i8* @lskip(i8* %39)
%41 = call i8* @find_char_or_comment(i8* %40, i8 signext 0)
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 59
br i1 %43, label %44, label %45
44: ; preds = %36
store i8 0, i8* %41
br label %45
45: ; preds = %44, %36
%46 = call i8* @rstrip(i8* %40)
%47 = call i32 @strncpy0(i8* %9, i8* %38, i32 64)
%48 = call i32 %1(i8* %2, i8* %8, i8* %38, i8* %40)
%49 = icmp ne i32 %48, 0
%50 = icmp ne i32 %13, 0
%51 = select i1 %49, i1 true, i1 %50
%52 = select i1 %51, i32 %13, i32 %15
br label %56
53: ; preds = %33
%54 = icmp eq i32 %13, 0
%55 = select i1 %54, i32 %15, i32 %13
br label %56
56: ; preds = %53, %45, %26, %12, %12, %12, %24
%57 = phi i32 [ %13, %12 ], [ %13, %24 ], [ %13, %12 ], [ %28, %26 ], [ %13, %12 ], [ %52, %45 ], [ %55, %53 ]
%58 = call i32* @fgets(i8* %7, i32 1024, i32* %0)
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %12
60: ; preds = %56, %3
%61 = phi i32 [ 0, %3 ], [ %57, %56 ]
ret i32 %61
}