#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ match(struct cymkd_parser *, char);
int /*<<< orphan*/ parser_emit_string(struct cymkd_parser *, char *, int);
int /*<<< orphan*/ stderr;
bool header_prefix(struct cymkd_parser *parser, int *header_level_ptr) {
  int header_level = 0;
  while (match(parser, '#')) {
    header_level++;
  }
  if (header_level == 0) {
    return false;
  }
  if (!match(parser, ' ')) {
    fprintf(stderr, "ERROR: Expected space after #\n");
    return false;
  }
  parser_emit_string(parser, "<h%d>", header_level);
  *header_level_ptr = header_level;
  return true;
}


x86 assembly (clang, -O0):
<header_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x23,%esi
call   1050 <match@plt>
cmp    $0x0,%rax
je     116d <header_prefix+0x3d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <header_prefix+0x17>
cmpl   $0x0,-0x1c(%rbp)
jne    1183 <header_prefix+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11df <header_prefix+0xaf>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1050 <match@plt>
cmp    $0x0,%rax
jne    11bc <header_prefix+0x8c>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11df <header_prefix+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe55(%rip),%rsi
call   1040 <parser_emit_string@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<header_prefix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x23,%esi
call   1050 <match@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1150 <header_prefix+0x20>
xor    %r15d,%r15d
test   %ebp,%ebp
je     11af <header_prefix+0x7f>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <match@plt>
test   %rax,%rax
je     119a <header_prefix+0x6a>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <parser_emit_string@plt>
mov    %ebp,(%r14)
mov    $0x1,%r15d
jmp    11af <header_prefix+0x7f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1030 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cymkd_parser = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"ERROR: Expected space after #\0A\00"
@.str.1 = [6 x i8] c"<h%d>\00"
define i32 @header_prefix(%struct.cymkd_parser* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.cymkd_parser*
%5 = alloca i32*
%6 = alloca i32
store %struct.cymkd_parser* %0, %struct.cymkd_parser** %4
store i32* %1, i32** %5
store i32 0, i32* %6
br label %7
7: ; preds = %11, %2
%8 = load %struct.cymkd_parser*, %struct.cymkd_parser** %4
%9 = call i64 @match(%struct.cymkd_parser* %8, i8 signext 35)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
br label %7
14: ; preds = %7
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %3
br label %31
18: ; preds = %14
%19 = load %struct.cymkd_parser*, %struct.cymkd_parser** %4
%20 = call i64 @match(%struct.cymkd_parser* %19, i8 signext 32)
%21 = icmp ne i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %31
25: ; preds = %18
%26 = load %struct.cymkd_parser*, %struct.cymkd_parser** %4
%27 = load i32, i32* %6
%28 = call i32 @parser_emit_string(%struct.cymkd_parser* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = load i32*, i32** %5
store i32 %29, i32* %30
store i32 1, i32* %3
br label %31
31: ; preds = %25, %22, %17
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.cymkd_parser = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"ERROR: Expected space after #\0A\00"
@.str.1 = [6 x i8] c"<h%d>\00"
define i32 @header_prefix(%struct.cymkd_parser* %0, i32* nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 0, %2 ], [ %7, %3 ]
%5 = tail call i64 @match(%struct.cymkd_parser* %0, i8 signext 35)
%6 = icmp eq i64 %5, 0
%7 = add nuw nsw i32 %4, 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = icmp eq i32 %4, 0
br i1 %9, label %18, label %10
10: ; preds = %8
%11 = tail call i64 @match(%struct.cymkd_parser* %0, i8 signext 32)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %10
%17 = tail call i32 @parser_emit_string(%struct.cymkd_parser* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %4)
store i32 %4, i32* %1
br label %18
18: ; preds = %8, %16, %13
%19 = phi i32 [ 1, %16 ], [ 0, %13 ], [ 0, %8 ]
ret i32 %19
}