#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;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int onUrl(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int onHeader(FILE *out_fp, FILE *in_fp) {
  int count = 1, onUrlstate;
  char ch;
  while ((ch = fgetc(in_fp)) == '#') {
    ++count;
  }
  if (count > 6) {
    while (count--) {
      fprintf(out_fp, "#");
    }
    fprintf(out_fp, "%c", ch);
    return 1;
  }
  fprintf(out_fp, "<h%d>", count);
  while (ch != '\n' && ch != EOF) {
    if (ch == '[') {
      onUrlstate = onUrl(out_fp, in_fp);
      if (onUrlstate == 2 || onUrlstate == 4) {
        break;
      }
    } else {
      fprintf(out_fp, "%c", ch);
    }
    ch = fgetc(in_fp);
  }
  fprintf(out_fp, "</h%i>\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<onHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0x23,%eax
jne    116d <onHeader+0x3d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <onHeader+0x17>
cmpl   $0x6,-0x1c(%rbp)
jle    11c9 <onHeader+0x99>
jmp    117c <onHeader+0x4c>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     11a7 <onHeader+0x77>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    117c <onHeader+0x4c>
mov    -0x10(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <onHeader+0x164>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x22(%rbp)
je     1206 <onHeader+0xd6>
movsbl -0x21(%rbp),%eax
mov    0x2ded(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1216 <onHeader+0xe6>
jmp    1278 <onHeader+0x148>
movsbl -0x21(%rbp),%eax
cmp    $0x5b,%eax
jne    1251 <onHeader+0x121>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <onUrl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
je     1247 <onHeader+0x117>
cmpl   $0x4,-0x20(%rbp)
jne    124c <onHeader+0x11c>
jmp    1278 <onHeader+0x148>
jmp    1267 <onHeader+0x137>
mov    -0x10(%rbp),%rdi
movsbl -0x21(%rbp),%edx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
jmp    11de <onHeader+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1030 <fgetc@plt>
add    $0xffffffff,%ebp
cmp    $0x23,%al
je     1160 <onHeader+0x20>
mov    %eax,%ebx
mov    %ebp,%r12d
neg    %r12d
cmp    $0x7,%r12d
jb     11a5 <onHeader+0x65>
movsbl %bl,%ebx
mov    $0x23,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
inc    %ebp
jne    1180 <onHeader+0x40>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    $0x1,%ebp
jmp    1223 <onHeader+0xe3>
lea    0xe54(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0xa,%bl
je     120f <onHeader+0xcf>
mov    0x2e21(%rip),%r13
cmp    0x0(%r13),%bl
je     120f <onHeader+0xcf>
nopl   (%rax)
cmp    $0x5b,%bl
jne    11f0 <onHeader+0xb0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <onUrl@plt>
cmp    $0x2,%eax
je     120f <onHeader+0xcf>
cmp    $0x4,%eax
jne    11fb <onHeader+0xbb>
jmp    120f <onHeader+0xcf>
nopl   0x0(%rax)
movsbl %bl,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     120f <onHeader+0xcf>
mov    %eax,%ebx
cmp    0x0(%r13),%bl
jne    11d0 <onHeader+0x90>
lea    0xdf0(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"#\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [6 x i8] c"<h%d>\00"
@EOF = global i8 0
@.str.3 = [8 x i8] c"</h%i>\0A\00"
define i32 @onHeader(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 1, i32* %6
br label %9
9: ; preds = %14, %2
%10 = load i32*, i32** %5
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %8
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 35
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
br label %9
17: ; preds = %9
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 6
br i1 %19, label %20, label %33
20: ; preds = %17
br label %21
21: ; preds = %25, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
%24 = icmp ne i32 %22, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
28: ; preds = %21
%29 = load i32*, i32** %4
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
store i32 1, i32* %3
br label %76
33: ; preds = %17
%34 = load i32*, i32** %4
%35 = load i32, i32* %6
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %69, %33
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i8, i8* %8
%43 = sext i8 %42 to i32
%44 = load i8, i8* @EOF
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %43, %45
br label %47
47: ; preds = %41, %37
%48 = phi i1 [ false, %37 ], [ %46, %41 ]
br i1 %48, label %49, label %72
49: ; preds = %47
%50 = load i8, i8* %8
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 91
br i1 %52, label %53, label %64
53: ; preds = %49
%54 = load i32*, i32** %4
%55 = load i32*, i32** %5
%56 = call i32 @onUrl(i32* %54, i32* %55)
store i32 %56, i32* %7
%57 = load i32, i32* %7
%58 = icmp eq i32 %57, 2
br i1 %58, label %62, label %59
59: ; preds = %53
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, 4
br i1 %61, label %62, label %63
62: ; preds = %59, %53
br label %72
63: ; preds = %59
br label %69
64: ; preds = %49
%65 = load i32*, i32** %4
%66 = load i8, i8* %8
%67 = sext i8 %66 to i32
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %64, %63
%70 = load i32*, i32** %5
%71 = call signext i8 @fgetc(i32* %70)
store i8 %71, i8* %8
br label %37
72: ; preds = %62, %47
%73 = load i32*, i32** %4
%74 = load i32, i32* %6
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %74)
store i32 0, i32* %3
br label %76
76: ; preds = %72, %28
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str.2 = [6 x i8] c"<h%d>\00"
@EOF = global i8 0
@.str.3 = [8 x i8] c"</h%i>\0A\00"
define i32 @onHeader(i32* %0, i32* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 1, %2 ], [ %7, %3 ]
%5 = tail call signext i8 @fgetc(i32* %1)
%6 = icmp eq i8 %5, 35
%7 = add nuw nsw i32 %4, 1
br i1 %6, label %3, label %8
8: ; preds = %3
%9 = sext i8 %5 to i32
%10 = icmp ugt i32 %4, 6
br i1 %10, label %11, label %18
11: ; preds = %8, %11
%12 = phi i32 [ %13, %11 ], [ %4, %8 ]
%13 = add nsw i32 %12, -1
%14 = tail call i32 @fputc(i32 35, i32* %0)
%15 = icmp eq i32 %13, 0
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = tail call i32 @fputc(i32 %9, i32* %0)
br label %40
18: ; preds = %8
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%20 = icmp ne i8 %5, 10
%21 = load i8, i8* @EOF
%22 = icmp ne i8 %5, %21
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %38
24: ; preds = %18, %32
%25 = phi i8 [ %33, %32 ], [ %5, %18 ]
%26 = icmp eq i8 %25, 91
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @onUrl(i32* %0, i32* %1)
switch i32 %28, label %32 [
i32 4, label %38
i32 2, label %38
]
29: ; preds = %24
%30 = sext i8 %25 to i32
%31 = tail call i32 @fputc(i32 %30, i32* %0)
br label %32
32: ; preds = %27, %29
%33 = tail call signext i8 @fgetc(i32* %1)
%34 = icmp ne i8 %33, 10
%35 = load i8, i8* @EOF
%36 = icmp ne i8 %33, %35
%37 = select i1 %34, i1 %36, i1 false
br i1 %37, label %24, label %38
38: ; preds = %32, %27, %27, %18
%39 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %4)
br label %40
40: ; preds = %38, %16
%41 = phi i32 [ 1, %16 ], [ 0, %38 ]
ret i32 %41
}