#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*/ consume(struct cymkd_parser *);
scalar_t__ match(struct cymkd_parser *, char);
int next(struct cymkd_parser *);
int /*<<< orphan*/ parser_emit_char(struct cymkd_parser *, char);
int /*<<< orphan*/ parser_emit_string(struct cymkd_parser *, char *);
int /*<<< orphan*/ text_and_inline(struct cymkd_parser *);
bool paragraph(struct cymkd_parser *parser) {
  parser_emit_string(parser, "<p>");
  while (true) {
    if (!text_and_inline(parser)) {
      return false;
    }
    if (match(parser, '\n') && next(parser) == '\n') {
      consume(parser);
      parser_emit_string(parser, "</p>");
      break;
    } else if (next(parser) == -1) {
      parser_emit_string(parser, "</p>");
      break;
    } else {
      parser_emit_char(parser, '\n');
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<paragraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <parser_emit_string@plt>
mov    -0x10(%rbp),%rdi
call   1050 <text_and_inline@plt>
cmp    $0x0,%eax
jne    119a <paragraph+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    1228 <paragraph+0xc8>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1070 <match@plt>
cmp    $0x0,%rax
je     11e2 <paragraph+0x82>
mov    -0x10(%rbp),%rdi
call   1030 <next@plt>
cmp    $0xa,%eax
jne    11e2 <paragraph+0x82>
mov    -0x10(%rbp),%rdi
call   1040 <consume@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <parser_emit_string@plt>
jmp    1221 <paragraph+0xc1>
mov    -0x10(%rbp),%rdi
call   1030 <next@plt>
cmp    $0xffffffff,%eax
jne    1209 <paragraph+0xa9>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <parser_emit_string@plt>
jmp    1221 <paragraph+0xc1>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1080 <parser_emit_char@plt>
jmp    121c <paragraph+0xbc>
jmp    117c <paragraph+0x1c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paragraph>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe93(%rip),%rsi
call   1060 <parser_emit_string@plt>
mov    %rbx,%rdi
call   1050 <text_and_inline@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11e3 <paragraph+0x83>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <match@plt>
test   %rax,%rax
je     119f <paragraph+0x3f>
mov    %rbx,%rdi
call   1030 <next@plt>
cmp    $0xa,%eax
je     11c7 <paragraph+0x67>
mov    %rbx,%rdi
call   1030 <next@plt>
cmp    $0xffffffff,%eax
je     11cf <paragraph+0x6f>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <parser_emit_char@plt>
mov    %rbx,%rdi
call   1050 <text_and_inline@plt>
test   %eax,%eax
jne    1180 <paragraph+0x20>
jmp    11e3 <paragraph+0x83>
mov    %rbx,%rdi
call   1040 <consume@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <parser_emit_string@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.cymkd_parser = type { i32 }
@.str = [4 x i8] c"<p>\00"
@.str.1 = [5 x i8] c"</p>\00"
define i32 @paragraph(%struct.cymkd_parser* %0) {
%2 = alloca i32
%3 = alloca %struct.cymkd_parser*
store %struct.cymkd_parser* %0, %struct.cymkd_parser** %3
%4 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%5 = call i32 @parser_emit_string(%struct.cymkd_parser* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %1, %35
%7 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%8 = call i32 @text_and_inline(%struct.cymkd_parser* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %6
store i32 0, i32* %2
br label %37
11: ; preds = %6
%12 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%13 = call i64 @match(%struct.cymkd_parser* %12, i8 signext 10)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%17 = call i32 @next(%struct.cymkd_parser* %16)
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%21 = call i32 @consume(%struct.cymkd_parser* %20)
%22 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%23 = call i32 @parser_emit_string(%struct.cymkd_parser* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %36
24: ; preds = %15, %11
%25 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%26 = call i32 @next(%struct.cymkd_parser* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%30 = call i32 @parser_emit_string(%struct.cymkd_parser* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %36
31: ; preds = %24
%32 = load %struct.cymkd_parser*, %struct.cymkd_parser** %3
%33 = call i32 @parser_emit_char(%struct.cymkd_parser* %32, i8 signext 10)
br label %34
34: ; preds = %31
br label %35
35: ; preds = %34
br label %6
36: ; preds = %28, %19
store i32 1, i32* %2
br label %37
37: ; preds = %36, %10
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
%struct.cymkd_parser = type { i32 }
@.str = [4 x i8] c"<p>\00"
@.str.1 = [5 x i8] c"</p>\00"
define i32 @paragraph(%struct.cymkd_parser* %0) {
%2 = tail call i32 @parser_emit_string(%struct.cymkd_parser* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @text_and_inline(%struct.cymkd_parser* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %1, %16
%6 = tail call i64 @match(%struct.cymkd_parser* %0, i8 signext 10)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @next(%struct.cymkd_parser* %0)
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @consume(%struct.cymkd_parser* %0)
br label %20
13: ; preds = %8, %5
%14 = tail call i32 @next(%struct.cymkd_parser* %0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = tail call i32 @parser_emit_char(%struct.cymkd_parser* %0, i8 signext 10)
%18 = tail call i32 @text_and_inline(%struct.cymkd_parser* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %5
20: ; preds = %13, %11
%21 = tail call i32 @parser_emit_string(%struct.cymkd_parser* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %16, %20, %1
%23 = phi i32 [ 0, %1 ], [ 1, %20 ], [ 0, %16 ]
ret i32 %23
}