#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 */
struct cymkd_parser {
  int dummy;
};

/* Variables and functions */
int consume(struct cymkd_parser *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ header_prefix(struct cymkd_parser *, int *);
int /*<<< orphan*/ parser_emit_char(struct cymkd_parser *, int);
int /*<<< orphan*/ parser_emit_string(struct cymkd_parser *, char *, int);
int /*<<< orphan*/ stderr;
bool header(struct cymkd_parser *parser) {
  int ch;
  int header_level;
  if (header_prefix(parser, &header_level)) {
    while ((ch = consume(parser)) != '\n' && ch != -1) {
      parser_emit_char(parser, ch);
    }
    ch = consume(parser);
    if (ch != '\n' && ch != -1) {
      fprintf(stderr, "ERROR: Header must end with two newlines\n");
      return false;
    }
    parser_emit_string(parser, "</h%d>", header_level);
    return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <header_prefix@plt>
cmp    $0x0,%rax
je     121f <header+0xcf>
jmp    1178 <header+0x28>
mov    -0x10(%rbp),%rdi
call   1040 <consume@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     119e <header+0x4e>
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ae <header+0x5e>
jmp    11bf <header+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <parser_emit_char@plt>
jmp    1178 <header+0x28>
mov    -0x10(%rbp),%rdi
call   1040 <consume@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
je     1200 <header+0xb0>
cmpl   $0xffffffff,-0x14(%rbp)
je     1200 <header+0xb0>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1226 <header+0xd6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe1c(%rip),%rsi
call   1050 <parser_emit_string@plt>
movl   $0x1,-0x4(%rbp)
jmp    1226 <header+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%rsi
call   1060 <header_prefix@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11cf <header+0x7f>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <consume@plt>
cmp    $0xffffffff,%eax
je     118e <header+0x3e>
cmp    $0xa,%eax
je     118e <header+0x3e>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <parser_emit_char@plt>
jmp    1170 <header+0x20>
mov    %rbx,%rdi
call   1040 <consume@plt>
cmp    $0xffffffff,%eax
je     11a0 <header+0x50>
cmp    $0xa,%eax
jne    11ba <header+0x6a>
mov    0x4(%rsp),%edx
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <parser_emit_string@plt>
mov    $0x1,%ebp
jmp    11cf <header+0x7f>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.cymkd_parser = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: Header must end with two newlines\0A\00"
@.str.1 = [7 x i8] c"</h%d>\00"
define i32 @header(%struct.cymkd_parser* %0) {
%2 = alloca i32
%3 = alloca %struct.cymkd_parser*
%4 = alloca i32
%5 = alloca i32
store %struct.cymkd_parser* %0, %struct.cymkd_parser** %3
%6 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%7 = call i64 @header_prefix(%struct.cymkd_parser* %6, i32* %5)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %38
9: ; preds = %1
br label %10
10: ; preds = %19, %9
%11 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%12 = call i32 @consume(%struct.cymkd_parser* %11)
store i32 %12, i32* %4
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, -1
br label %17
17: ; preds = %14, %10
%18 = phi i1 [ false, %10 ], [ %16, %14 ]
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%21 = load i32, i32* %4
%22 = call i32 @parser_emit_char(%struct.cymkd_parser* %20, i32 %21)
br label %10
23: ; preds = %17
%24 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%25 = call i32 @consume(%struct.cymkd_parser* %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %39
34: ; preds = %28, %23
%35 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%36 = load i32, i32* %5
%37 = call i32 @parser_emit_string(%struct.cymkd_parser* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i32 1, i32* %2
br label %39
38: ; preds = %1
store i32 0, i32* %2
br label %39
39: ; preds = %38, %34, %31
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.cymkd_parser = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"ERROR: Header must end with two newlines\0A\00"
@.str.1 = [7 x i8] c"</h%d>\00"
define i32 @header(%struct.cymkd_parser* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @header_prefix(%struct.cymkd_parser* %0, i32* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1, %8
%7 = call i32 @consume(%struct.cymkd_parser* %0)
switch i32 %7, label %8 [
i32 -1, label %10
i32 10, label %10
]
8: ; preds = %6
%9 = call i32 @parser_emit_char(%struct.cymkd_parser* %0, i32 %7)
br label %6
10: ; preds = %6, %6
%11 = call i32 @consume(%struct.cymkd_parser* %0)
switch i32 %11, label %12 [
i32 -1, label %15
i32 10, label %15
]
12: ; preds = %10
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %18
15: ; preds = %10, %10
%16 = load i32, i32* %2
%17 = call i32 @parser_emit_string(%struct.cymkd_parser* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %1, %15, %12
%19 = phi i32 [ 0, %12 ], [ 1, %15 ], [ 0, %1 ]
ret i32 %19
}