#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 */
char EOF;
int /*<<< orphan*/ EXIT_FAILURE;
char *check_alloc(char *, int, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mem_chk(char *);
int /*<<< orphan*/ *parse_comments(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ parse_line(char *);
int /*<<< orphan*/ skip_past_char(int /*<<< orphan*/ *, char);
int /*<<< orphan*/ *skip_past_newline(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void parse(FILE *is) {
  char prev = '\0', curr;
  int linesize = 81;
  int pos = 0, count = 0;
  char *line = malloc(linesize * sizeof(*line));
  mem_chk(line);
  while ((curr = fgetc(is)) != EOF) {
    line[pos] = curr;
    if (curr == '\'' || curr == '"') {
      skip_past_char(is, curr);
    } else if (curr == '/' && prev == '/') {
      is = parse_comments(is, 1);
      pos = -1;
    } else if (curr == '*' && prev == '/') {
      is = parse_comments(is, 2);
      pos -= 2;
    } else if (curr == '{') {
      if (count == 0) {
        line[pos + 1] = '\0';
        parse_line(line);
      }
      count++;
      pos = -1;
    } else if (curr == '}') {
      count--;
      pos = -1;
      if (count < 0) {
        fprintf(stderr, "Error encountered. Are you "
                        "sure you didn't attempt to "
                        "close a non-existent "
                        "block?\n");
        exit(EXIT_FAILURE);
      }
    } else if (curr == ';') {
      pos = -1;
    } else if (curr == '#' && pos == 0) {
      is = skip_past_newline(is);
    }
    prev = curr;
    pos++;
    line = check_alloc(line, pos, &linesize);
  }
  if (count != 0) {
    fprintf(stderr, "Error encountered. Are you sure you terminated "
                    "all of your blocks correctly?\n");
    exit(EXIT_FAILURE);
  }
  free(line);
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movl   $0x51,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <mem_chk@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0xa(%rbp)
movsbl %al,%eax
mov    0x2de1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13d6 <parse+0x226>
mov    -0xa(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0xa(%rbp),%eax
cmp    $0x27,%eax
je     123a <parse+0x8a>
movsbl -0xa(%rbp),%eax
cmp    $0x22,%eax
jne    124c <parse+0x9c>
mov    -0x8(%rbp),%rdi
movsbl -0xa(%rbp),%esi
call   1060 <skip_past_char@plt>
jmp    13ae <parse+0x1fe>
movsbl -0xa(%rbp),%eax
cmp    $0x2f,%eax
jne    1284 <parse+0xd4>
movsbl -0x9(%rbp),%eax
cmp    $0x2f,%eax
jne    1284 <parse+0xd4>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <parse_comments@plt>
mov    %rax,-0x8(%rbp)
movl   $0xffffffff,-0x14(%rbp)
jmp    13a9 <parse+0x1f9>
movsbl -0xa(%rbp),%eax
cmp    $0x2a,%eax
jne    12be <parse+0x10e>
movsbl -0x9(%rbp),%eax
cmp    $0x2f,%eax
jne    12be <parse+0x10e>
mov    -0x8(%rbp),%rdi
mov    $0x2,%esi
call   10a0 <parse_comments@plt>
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    13a4 <parse+0x1f4>
movsbl -0xa(%rbp),%eax
cmp    $0x7b,%eax
jne    1304 <parse+0x154>
cmpl   $0x0,-0x18(%rbp)
jne    12ef <parse+0x13f>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1090 <parse_line@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
jmp    139f <parse+0x1ef>
movsbl -0xa(%rbp),%eax
cmp    $0x7d,%eax
jne    1353 <parse+0x1a3>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    134e <parse+0x19e>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xcc5(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    139a <parse+0x1ea>
movsbl -0xa(%rbp),%eax
cmp    $0x3b,%eax
jne    136c <parse+0x1bc>
movl   $0xffffffff,-0x14(%rbp)
jmp    1395 <parse+0x1e5>
movsbl -0xa(%rbp),%eax
cmp    $0x23,%eax
jne    1390 <parse+0x1e0>
cmpl   $0x0,-0x14(%rbp)
jne    1390 <parse+0x1e0>
mov    -0x8(%rbp),%rdi
call   1030 <skip_past_newline@plt>
mov    %rax,-0x8(%rbp)
jmp    1395 <parse+0x1e5>
jmp    139a <parse+0x1ea>
jmp    139f <parse+0x1ef>
jmp    13a4 <parse+0x1f4>
jmp    13a9 <parse+0x1f9>
jmp    13ae <parse+0x1fe>
mov    -0xa(%rbp),%al
mov    %al,-0x9(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdx
call   10d0 <check_alloc@plt>
mov    %rax,-0x20(%rbp)
jmp    11f1 <parse+0x41>
cmpl   $0x0,-0x18(%rbp)
je     1403 <parse+0x253>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x51,0x4(%rsp)
mov    $0x51,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <mem_chk@plt>
mov    %r14,%rdi
call   1070 <fgetc@plt>
mov    0x2dfe(%rip),%r12
cmp    (%r12),%al
je     1313 <parse+0x163>
movl   $0x0,(%rsp)
lea    0x4(%rsp),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    1241 <parse+0x91>
nopw   0x0(%rax,%rax,1)
movsbl %r13b,%esi
mov    %r14,%rdi
call   1060 <skip_past_char@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   10d0 <check_alloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1070 <fgetc@plt>
cmp    (%r12),%al
je     130d <parse+0x15d>
mov    %r13d,%ecx
mov    %eax,%r13d
movslq %ebp,%rax
mov    %r13b,(%rbx,%rax,1)
cmp    $0x27,%r13b
je     1210 <parse+0x60>
cmp    $0x22,%r13b
je     1210 <parse+0x60>
cmp    $0x2f,%cl
jne    127c <parse+0xcc>
cmp    $0x2f,%r13b
jne    127c <parse+0xcc>
mov    %r14,%rdi
mov    $0x1,%esi
call   10a0 <parse_comments@plt>
mov    %rax,%r14
mov    $0xffffffff,%ebp
jmp    121c <parse+0x6c>
cmp    $0x2f,%cl
jne    129c <parse+0xec>
cmp    $0x2a,%r13b
jne    129c <parse+0xec>
mov    %r14,%rdi
mov    $0x2,%esi
call   10a0 <parse_comments@plt>
mov    %rax,%r14
add    $0xfffffffe,%ebp
jmp    121c <parse+0x6c>
cmp    $0x3b,%r13b
je     12c8 <parse+0x118>
cmp    $0x7d,%r13b
je     12d2 <parse+0x122>
cmp    $0x7b,%r13b
jne    12e9 <parse+0x139>
mov    (%rsp),%ebp
test   %ebp,%ebp
jne    12c2 <parse+0x112>
movb   $0x0,0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1090 <parse_line@plt>
add    $0x1,%ebp
mov    %ebp,(%rsp)
mov    $0xffffffff,%ebp
jmp    121c <parse+0x6c>
mov    (%rsp),%eax
test   %eax,%eax
jle    133c <parse+0x18c>
add    $0xffffffff,%eax
mov    %eax,(%rsp)
mov    $0xffffffff,%ebp
jmp    121c <parse+0x6c>
test   %ebp,%ebp
jne    121c <parse+0x6c>
cmp    $0x23,%r13b
jne    121c <parse+0x6c>
mov    %r14,%rdi
call   1030 <skip_past_newline@plt>
mov    %rax,%r14
xor    %ebp,%ebp
jmp    121c <parse+0x6c>
cmpl   $0x0,(%rsp)
jne    132a <parse+0x17a>
mov    %rbx,%rdi
call   1040 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
jmp    134c <parse+0x19c>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xcb4(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@EOF = global i8 0
@stderr = global i32 0
@.str = [83 x i8] c"Error encountered. Are you sure you didn't attempt to close a non-existent block?\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [78 x i8] c"Error encountered. Are you sure you terminated all of your blocks correctly?\0A\00"
define void @parse(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %2
store i8 0, i8* %3
store i32 81, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i32 @mem_chk(i8* %14)
br label %16
16: ; preds = %118, %1
%17 = load i32*, i32** %2
%18 = call signext i8 @fgetc(i32* %17)
store i8 %18, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %125
23: ; preds = %16
%24 = load i8, i8* %4
%25 = load i8*, i8** %8
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i8, i8* %4
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 39
br i1 %31, label %36, label %32
32: ; preds = %23
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 34
br i1 %35, label %36, label %40
36: ; preds = %32, %23
%37 = load i32*, i32** %2
%38 = load i8, i8* %4
%39 = call i32 @skip_past_char(i32* %37, i8 signext %38)
br label %118
40: ; preds = %32
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 47
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 47
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32*, i32** %2
%50 = call i32* @parse_comments(i32* %49, i32 1)
store i32* %50, i32** %2
store i32 -1, i32* %6
br label %117
51: ; preds = %44, %40
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 42
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i8, i8* %3
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 47
br i1 %58, label %59, label %64
59: ; preds = %55
%60 = load i32*, i32** %2
%61 = call i32* @parse_comments(i32* %60, i32 2)
store i32* %61, i32** %2
%62 = load i32, i32* %6
%63 = sub nsw i32 %62, 2
store i32 %63, i32* %6
br label %116
64: ; preds = %55, %51
%65 = load i8, i8* %4
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 123
br i1 %67, label %68, label %82
68: ; preds = %64
%69 = load i32, i32* %7
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %79
71: ; preds = %68
%72 = load i8*, i8** %8
%73 = load i32, i32* %6
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 0, i8* %76
%77 = load i8*, i8** %8
%78 = call i32 @parse_line(i8* %77)
br label %79
79: ; preds = %71, %68
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
store i32 -1, i32* %6
br label %115
82: ; preds = %64
%83 = load i8, i8* %4
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 125
br i1 %85, label %86, label %97
86: ; preds = %82
%87 = load i32, i32* %7
%88 = add nsw i32 %87, -1
store i32 %88, i32* %7
store i32 -1, i32* %6
%89 = load i32, i32* %7
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %86
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; preds = %86
br label %114
97: ; preds = %82
%98 = load i8, i8* %4
%99 = sext i8 %98 to i32
%100 = icmp eq i32 %99, 59
br i1 %100, label %101, label %102
101: ; preds = %97
store i32 -1, i32* %6
br label %113
102: ; preds = %97
%103 = load i8, i8* %4
%104 = sext i8 %103 to i32
%105 = icmp eq i32 %104, 35
br i1 %105, label %106, label %112
106: ; preds = %102
%107 = load i32, i32* %6
%108 = icmp eq i32 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %106
%110 = load i32*, i32** %2
%111 = call i32* @skip_past_newline(i32* %110)
store i32* %111, i32** %2
br label %112
112: ; preds = %109, %106, %102
br label %113
113: ; preds = %112, %101
br label %114
114: ; preds = %113, %96
br label %115
115: ; preds = %114, %79
br label %116
116: ; preds = %115, %59
br label %117
117: ; preds = %116, %48
br label %118
118: ; preds = %117, %36
%119 = load i8, i8* %4
store i8 %119, i8* %3
%120 = load i32, i32* %6
%121 = add nsw i32 %120, 1
store i32 %121, i32* %6
%122 = load i8*, i8** %8
%123 = load i32, i32* %6
%124 = call i8* @check_alloc(i8* %122, i32 %123, i32* %5)
store i8* %124, i8** %8
br label %16
125: ; preds = %16
%126 = load i32, i32* %7
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %133
128: ; preds = %125
%129 = load i32, i32* @stderr
%130 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%131 = load i32, i32* @EXIT_FAILURE
%132 = call i32 @exit(i32 %131)
unreachable
133: ; preds = %125
%134 = load i8*, i8** %8
%135 = call i32 @free(i8* %134)
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
@stderr = global i32 0
@.str = [83 x i8] c"Error encountered. Are you sure you didn't attempt to close a non-existent block?\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [78 x i8] c"Error encountered. Are you sure you terminated all of your blocks correctly?\0A\00"
define void @parse(i32* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 81, i32* %2
%4 = tail call dereferenceable_or_null(81) i8* @malloc(i32 81)
%5 = tail call i32 @mem_chk(i8* %4)
%6 = call signext i8 @fgetc(i32* %0)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %72, label %9
9: ; preds = %1, %56
%10 = phi i8 [ %62, %56 ], [ %6, %1 ]
%11 = phi i8* [ %61, %56 ], [ %4, %1 ]
%12 = phi i32 [ %59, %56 ], [ 0, %1 ]
%13 = phi i32 [ %60, %56 ], [ 0, %1 ]
%14 = phi i32* [ %57, %56 ], [ %0, %1 ]
%15 = phi i8 [ %10, %56 ], [ 0, %1 ]
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
store i8 %10, i8* %17
switch i8 %10, label %20 [
i8 39, label %18
i8 34, label %18
]
18: ; preds = %9, %9
%19 = call i32 @skip_past_char(i32* %14, i8 signext %10)
br label %56
20: ; preds = %9
%21 = icmp eq i8 %10, 47
%22 = icmp eq i8 %15, 47
%23 = and i1 %22, %21
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32* @parse_comments(i32* %14, i32 1)
br label %56
26: ; preds = %20
%27 = icmp eq i8 %10, 42
%28 = and i1 %22, %27
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32* @parse_comments(i32* %14, i32 2)
%31 = add nsw i32 %13, -2
br label %56
32: ; preds = %26
switch i8 %10, label %50 [
i8 123, label %33
i8 125, label %42
i8 59, label %56
]
33: ; preds = %32
%34 = icmp eq i32 %12, 0
br i1 %34, label %35, label %40
35: ; preds = %33
%36 = add nsw i32 %13, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %11, i64 %37
store i8 0, i8* %38
%39 = call i32 @parse_line(i8* %11)
br label %40
40: ; preds = %35, %33
%41 = add nsw i32 %12, 1
br label %56
42: ; preds = %32
%43 = add nsw i32 %12, -1
%44 = icmp slt i32 %12, 1
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %32
%51 = icmp eq i8 %10, 35
%52 = icmp eq i32 %13, 0
%53 = and i1 %52, %51
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32* @skip_past_newline(i32* %14)
br label %56
56: ; preds = %32, %24, %40, %54, %50, %42, %29, %18
%57 = phi i32* [ %14, %18 ], [ %25, %24 ], [ %30, %29 ], [ %14, %40 ], [ %14, %42 ], [ %55, %54 ], [ %14, %50 ], [ %14, %32 ]
%58 = phi i32 [ %13, %18 ], [ -1, %24 ], [ %31, %29 ], [ -1, %40 ], [ -1, %42 ], [ 0, %54 ], [ %13, %50 ], [ -1, %32 ]
%59 = phi i32 [ %12, %18 ], [ %12, %24 ], [ %12, %29 ], [ %41, %40 ], [ %43, %42 ], [ %12, %54 ], [ %12, %50 ], [ %12, %32 ]
%60 = add nsw i32 %58, 1
%61 = call i8* @check_alloc(i8* %11, i32 %60, i32* %2)
%62 = call signext i8 @fgetc(i32* %57)
%63 = load i8, i8* @EOF
%64 = icmp eq i8 %62, %63
br i1 %64, label %65, label %9
65: ; preds = %56
%66 = icmp eq i32 %59, 0
br i1 %66, label %72, label %67
67: ; preds = %65
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %1, %65
%73 = phi i8* [ %61, %65 ], [ %4, %1 ]
%74 = call i32 @free(i8* %73)
ret void
}