#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*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ level_done();
int /*<<< orphan*/ map_line(char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
void process(FILE *fp) {
  char buf[1024];
  int in_level = 0;
  while (fgets(buf, 1024, fp)) {
    char *p = strchr(buf, '\n');
    if (p == NULL) {
      fprintf(stderr, "Invalid line '%s'.\n", buf);
      exit(1);
    }
    *p = 0;
    if (in_level) {
      if (strchr(buf, '#'))
        map_line(buf);
      else {
        level_done();
        in_level = 0;
      }
    } else {
      if (strchr(buf, '#')) {
        in_level = 1;
        map_line(buf);
      }
    }
  }
  if (in_level == 1)
    level_done();
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1278 <process+0x118>
lea    -0x410(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    11e4 <process+0x84>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x414(%rbp)
je     123d <process+0xdd>
lea    -0x410(%rbp),%rdi
mov    $0x23,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1227 <process+0xc7>
lea    -0x410(%rbp),%rdi
call   1060 <map_line@plt>
jmp    1238 <process+0xd8>
mov    $0x0,%al
call   1070 <level_done@plt>
movl   $0x0,-0x414(%rbp)
jmp    1273 <process+0x113>
lea    -0x410(%rbp),%rdi
mov    $0x23,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     126e <process+0x10e>
movl   $0x1,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
call   1060 <map_line@plt>
jmp    1273 <process+0x113>
jmp    1179 <process+0x19>
cmpl   $0x1,-0x414(%rbp)
jne    128c <process+0x12c>
mov    $0x0,%al
call   1070 <level_done@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1202 <process+0xa2>
xor    %ebp,%ebp
mov    %rsp,%r15
jmp    11b9 <process+0x59>
nopl   0x0(%rax)
test   %rax,%rax
je     11f1 <process+0x91>
mov    %r15,%rdi
call   1060 <map_line@plt>
mov    $0x1,%ebp
mov    $0x1,%bl
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f7 <process+0x97>
mov    %r15,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1210 <process+0xb0>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    $0x23,%esi
call   1030 <strchr@plt>
test   %ebp,%ebp
je     1190 <process+0x30>
test   %rax,%rax
jne    1195 <process+0x35>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <level_done@plt>
xor    %ebp,%ebp
jmp    11a4 <process+0x44>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11a4 <process+0x44>
test   %bl,%bl
je     1202 <process+0xa2>
xor    %eax,%eax
call   1070 <level_done@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Invalid line '%s'.\0A\00"
define void @process(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i8*
store i32* %0, i32** %2
store i32 0, i32* %4
br label %6
6: ; preds = %43, %1
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i64 @fgets(i8* %7, i32 1024, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i8* @strchr(i8* %12, i8 signext 10)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i8*, i8** %5
store i8 0, i8* %22
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i8* @strchr(i8* %26, i8 signext 35)
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%31 = call i32 @map_line(i8* %30)
br label %34
32: ; preds = %25
%33 = call i32 (...) @level_done()
store i32 0, i32* %4
br label %34
34: ; preds = %32, %29
br label %43
35: ; preds = %21
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%37 = call i8* @strchr(i8* %36, i8 signext 35)
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %35
store i32 1, i32* %4
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%41 = call i32 @map_line(i8* %40)
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %34
br label %6
44: ; preds = %6
%45 = load i32, i32* %4
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (...) @level_done()
br label %49
49: ; preds = %47, %44
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Invalid line '%s'.\0A\00"
define void @process(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i64 @fgets(i8* %3, i32 1024, i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %34, label %6
6: ; preds = %1, %26
%7 = phi i32 [ %28, %26 ], [ 0, %1 ]
%8 = call i8* @strchr(i8* %3, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %3)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %6
store i8 0, i8* %8
%15 = icmp eq i32 %7, 0
%16 = call i8* @strchr(i8* %3, i8 signext 35)
%17 = icmp eq i8* %16, null
br i1 %15, label %23, label %18
18: ; preds = %14
br i1 %17, label %21, label %19
19: ; preds = %18
%20 = call i32 @map_line(i8* %3)
br label %26
21: ; preds = %18
%22 = call i32 (...) @level_done()
br label %26
23: ; preds = %14
br i1 %17, label %26, label %24
24: ; preds = %23
%25 = call i32 @map_line(i8* %3)
br label %26
26: ; preds = %23, %24, %19, %21
%27 = phi i1 [ false, %23 ], [ true, %24 ], [ true, %19 ], [ false, %21 ]
%28 = phi i32 [ 0, %23 ], [ 1, %24 ], [ 1, %19 ], [ 0, %21 ]
%29 = call i64 @fgets(i8* %3, i32 1024, i32* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %6
31: ; preds = %26
br i1 %27, label %32, label %34
32: ; preds = %31
%33 = call i32 (...) @level_done()
br label %34
34: ; preds = %1, %32, %31
ret void
}