#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*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stderr;
void parse(char *fn, void parser(), void *data) {
  char buffer[1024];
  char *kp, *vp, *wp;
  int line = 0;
  FILE *cf = fopen(fn, "r");
  assert(cf);
  while (fgets((char *)&buffer, 1024, cf)) {
    line++;
    kp = vp = wp = (char *)&buffer;
    if (*wp == '#' || *wp == '\0')
      continue;
    while (*wp != '\0') {
      switch (*wp) {
      case '\n':
        *wp = '\0';
        break;
      case '=':
        if (kp == vp) {
          vp = wp + 1;
          *wp = '\0';
        }
        break;
      }
      wp++;
    }
    if (kp != vp) {
      parser(data, kp, vp);
    } else {
      fprintf(stderr, "Didn't understand line %d in %s\n", line, fn);
    }
  }
  fclose(cf);
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x43c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rdi
call   1050 <assert@plt>
lea    -0x420(%rbp),%rdi
mov    -0x448(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1308 <parse+0x1b8>
mov    -0x43c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x43c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    %rax,-0x430(%rbp)
mov    %rax,-0x428(%rbp)
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1207 <parse+0xb7>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    120c <parse+0xbc>
jmp    1194 <parse+0x44>
jmp    1211 <parse+0xc1>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12b1 <parse+0x161>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x44c(%rbp)
sub    $0xa,%eax
je     1256 <parse+0x106>
jmp    1242 <parse+0xf2>
mov    -0x44c(%rbp),%eax
sub    $0x3d,%eax
je     1265 <parse+0x115>
jmp    129a <parse+0x14a>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
jmp    129a <parse+0x14a>
mov    -0x428(%rbp),%rax
cmp    -0x430(%rbp),%rax
jne    1295 <parse+0x145>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
jmp    129a <parse+0x14a>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
jmp    1211 <parse+0xc1>
mov    -0x428(%rbp),%rax
cmp    -0x430(%rbp),%rax
je     12e4 <parse+0x194>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rdi
mov    -0x428(%rbp),%rsi
mov    -0x430(%rbp),%rdx
mov    $0x0,%al
call   *%rcx
jmp    1303 <parse+0x1b3>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x43c(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xd04(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1194 <parse+0x44>
mov    -0x448(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
lea    0xe92(%rip),%rsi
mov    %rdi,0x8(%rsp)
call   1070 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1050 <assert@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1234 <parse+0xe4>
lea    0x11(%rsp),%r15
xor    %ebp,%ebp
jmp    11d5 <parse+0x85>
nopw   0x0(%rax,%rax,1)
cmp    %rdx,%rbx
je     1216 <parse+0xc6>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   *%r12
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1234 <parse+0xe4>
add    $0x1,%ebp
mov    0x10(%rsp),%cl
test   %cl,%cl
je     11c0 <parse+0x70>
cmp    $0x23,%cl
je     11c0 <parse+0x70>
mov    %r15,%rax
mov    %rbx,%rdx
jmp    11ff <parse+0xaf>
nopl   (%rax)
movb   $0x0,-0x1(%rax)
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     11b0 <parse+0x60>
movsbl %cl,%ecx
cmp    $0xa,%ecx
je     11f0 <parse+0xa0>
cmp    $0x3d,%ecx
jne    11f4 <parse+0xa4>
cmp    %rdx,%rbx
jne    11f4 <parse+0xa4>
mov    %rax,%rdx
jmp    11f0 <parse+0xa0>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
mov    %ebp,%edx
mov    0x8(%rsp),%rcx
call   1060 <fprintf@plt>
jmp    11c0 <parse+0x70>
mov    %r13,%rdi
call   1030 <fclose@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Didn't understand line %d in %s\0A\00"
define void @parse(i8* %0, void (...)* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca void (...)*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %4
store void (...)* %1, void (...)** %5
store i8* %2, i8** %6
store i32 0, i32* %11
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = call i32 @assert(i32* %15)
br label %17
17: ; preds = %75, %35, %3
%18 = bitcast [1024 x i8]* %7 to i8*
%19 = load i32*, i32** %12
%20 = call i64 @fgets(i8* %18, i32 1024, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %76
22: ; preds = %17
%23 = load i32, i32* %11
%24 = add nsw i32 %23, 1
store i32 %24, i32* %11
%25 = bitcast [1024 x i8]* %7 to i8*
store i8* %25, i8** %10
store i8* %25, i8** %9
store i8* %25, i8** %8
%26 = load i8*, i8** %10
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 35
br i1 %29, label %35, label %30
30: ; preds = %22
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30, %22
br label %17
36: ; preds = %30
br label %37
37: ; preds = %57, %36
%38 = load i8*, i8** %10
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %60
42: ; preds = %37
%43 = load i8*, i8** %10
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
switch i32 %45, label %57 [
i32 10, label %46
i32 61, label %48
]
46: ; preds = %42
%47 = load i8*, i8** %10
store i8 0, i8* %47
br label %57
48: ; preds = %42
%49 = load i8*, i8** %8
%50 = load i8*, i8** %9
%51 = icmp eq i8* %49, %50
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 1
store i8* %54, i8** %9
%55 = load i8*, i8** %10
store i8 0, i8* %55
br label %56
56: ; preds = %52, %48
br label %57
57: ; preds = %42, %56, %46
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %10
br label %37
60: ; preds = %37
%61 = load i8*, i8** %8
%62 = load i8*, i8** %9
%63 = icmp ne i8* %61, %62
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load void (...)*, void (...)** %5
%66 = load i8*, i8** %6
%67 = load i8*, i8** %8
%68 = load i8*, i8** %9
%69 = bitcast void (...)* %65 to void (i8*, i8*, i8*, ...)*
br label %75
70: ; preds = %60
%71 = load i32, i32* @stderr
%72 = load i32, i32* %11
%73 = load i8*, i8** %4
%74 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %72, i8* %73)
br label %75
75: ; preds = %70, %64
br label %17
76: ; preds = %17
%77 = load i32*, i32** %12
%78 = call i32 @fclose(i32* %77)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Didn't understand line %d in %s\0A\00"
define void @parse(i8* %0, void (...)* nocapture %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @assert(i32* %6)
%8 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %41, label %10
10: ; preds = %3
%11 = bitcast void (...)* %1 to void (i8*, i8*, i8*, ...)*
br label %12
12: ; preds = %10, %16
%13 = phi i32 [ 0, %10 ], [ %14, %16 ]
%14 = add nuw nsw i32 %13, 1
%15 = load i8, i8* %5
switch i8 %15, label %19 [
i8 35, label %16
i8 0, label %16
]
16: ; preds = %37, %38, %12, %12
%17 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %41, label %12
19: ; preds = %12, %30
%20 = phi i8* [ %31, %30 ], [ %5, %12 ]
%21 = phi i8* [ %32, %30 ], [ %5, %12 ]
%22 = phi i8 [ %33, %30 ], [ %15, %12 ]
%23 = sext i8 %22 to i32
switch i32 %23, label %30 [
i32 10, label %28
i32 61, label %24
]
24: ; preds = %19
%25 = icmp eq i8* %5, %20
br i1 %25, label %26, label %30
26: ; preds = %24
%27 = getelementptr inbounds i8, i8* %21, i64 1
br label %28
28: ; preds = %19, %26
%29 = phi i8* [ %27, %26 ], [ %20, %19 ]
store i8 0, i8* %21
br label %30
30: ; preds = %28, %24, %19
%31 = phi i8* [ %20, %19 ], [ %20, %24 ], [ %29, %28 ]
%32 = getelementptr inbounds i8, i8* %21, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %19
35: ; preds = %30
%36 = icmp eq i8* %5, %31
br i1 %36, label %38, label %37
37: ; preds = %35
br label %16
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %0)
br label %16
41: ; preds = %16, %3
%42 = call i32 @fclose(i32* %6)
ret void
}