#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 match(struct cymkd_parser *, char);
int /*<<< orphan*/ parser_emit_char(struct cymkd_parser *, int);
int /*<<< orphan*/ parser_emit_string(struct cymkd_parser *, char *);
bool italics(struct cymkd_parser *parser) {
  bool success;
  int start_ch;
  int ch;
  success = match(parser, '*');
  if (success) {
    start_ch = '*';
  } else {
    success = match(parser, '_');
    if (success) {
      start_ch = '_';
    }
  }
  if (!success) {
    return false;
  }
  parser_emit_string(parser, "<em>");
  while ((ch = consume(parser)) != start_ch && ch != -1) {
    parser_emit_char(parser, ch);
  }
  if (ch == start_ch) {
    parser_emit_string(parser, "</em>");
    return true;
  }
  return false;
}


x86 assembly (clang, -O0):
<italics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1050 <match@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1173 <italics+0x33>
movl   $0x2a,-0x18(%rbp)
jmp    119a <italics+0x5a>
mov    -0x10(%rbp),%rdi
mov    $0x5f,%esi
call   1050 <match@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1195 <italics+0x55>
movl   $0x5f,-0x18(%rbp)
jmp    119a <italics+0x5a>
cmpl   $0x0,-0x14(%rbp)
jne    11b0 <italics+0x70>
movl   $0x0,-0x4(%rbp)
jmp    1236 <italics+0xf6>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1040 <parser_emit_string@plt>
mov    -0x10(%rbp),%rdi
call   1030 <consume@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x1d(%rbp)
je     11e6 <italics+0xa6>
cmpl   $0xffffffff,-0x1c(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11f6 <italics+0xb6>
jmp    1207 <italics+0xc7>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <parser_emit_char@plt>
jmp    11c0 <italics+0x80>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    122f <italics+0xef>
mov    -0x10(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1040 <parser_emit_string@plt>
movl   $0x1,-0x4(%rbp)
jmp    1236 <italics+0xf6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<italics>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2a,%ebp
mov    $0x2a,%esi
call   1050 <match@plt>
test   %eax,%eax
jne    116f <italics+0x2f>
mov    $0x5f,%ebp
mov    %rbx,%rdi
mov    $0x5f,%esi
call   1050 <match@plt>
test   %eax,%eax
je     11b9 <italics+0x79>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <parser_emit_string@plt>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <consume@plt>
cmp    %ebp,%eax
je     119d <italics+0x5d>
cmp    $0xffffffff,%eax
je     119d <italics+0x5d>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <parser_emit_char@plt>
jmp    1180 <italics+0x40>
xor    %ecx,%ecx
cmp    %ebp,%eax
jne    11bb <italics+0x7b>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <parser_emit_string@plt>
mov    $0x1,%ecx
jmp    11bb <italics+0x7b>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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