#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 */
int /*<<< orphan*/ advance(int /*<<< orphan*/ *, int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ html_encode(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ parse_colour_code(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
char peek(int /*<<< orphan*/ *);
void parse(FILE *in, FILE *out) {
  int c = 0;
  while ((c = fgetc(in)) != -1) {
    if (c == '\033') {
      if (peek(in) == '[') {
        advance(in, 1);
        parse_colour_code(in, out);
      } else {
        fputc('\033', out);
      }
    } else {
      html_encode(c, out);
    }
  }
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11ef <parse+0x8f>
cmpl   $0x1b,-0x14(%rbp)
jne    11de <parse+0x7e>
mov    -0x8(%rbp),%rdi
call   1030 <peek@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
jne    11cb <parse+0x6b>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <advance@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <parse_colour_code@plt>
jmp    11d9 <parse+0x79>
mov    -0x10(%rbp),%rsi
mov    $0x1b,%edi
call   1060 <fputc@plt>
jmp    11ea <parse+0x8a>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <html_encode@plt>
jmp    1177 <parse+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
jmp    117d <parse+0x1d>
nopl   0x0(%rax)
mov    $0x1b,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0x1b,%eax
je     11a0 <parse+0x40>
cmp    $0xffffffff,%eax
je     11c6 <parse+0x66>
mov    %eax,%edi
mov    %r14,%rsi
call   1080 <html_encode@plt>
jmp    117d <parse+0x1d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <peek@plt>
cmp    $0x5b,%al
jne    1170 <parse+0x10>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <advance@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <parse_colour_code@plt>
jmp    117d <parse+0x1d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @parse(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %6
6: ; preds = %32, %2
%7 = load i32*, i32** %3
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %5
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 27
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = call signext i8 @peek(i32* %14)
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 91
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32*, i32** %3
%20 = call i32 @advance(i32* %19, i32 1)
%21 = load i32*, i32** %3
%22 = load i32*, i32** %4
%23 = call i32 @parse_colour_code(i32* %21, i32* %22)
br label %27
24: ; preds = %13
%25 = load i32*, i32** %4
%26 = call i32 @fputc(i8 signext 27, i32* %25)
br label %27
27: ; preds = %24, %18
br label %32
28: ; preds = %10
%29 = load i32, i32* %5
%30 = load i32*, i32** %4
%31 = call i32 @html_encode(i32 %29, i32* %30)
br label %32
32: ; preds = %28, %27
br label %6
33: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @parse(i32* %0, i32* %1) {
br label %3
3: ; preds = %11, %2
%4 = tail call i32 @fgetc(i32* %0)
switch i32 %4, label %14 [
i32 -1, label %16
i32 27, label %5
]
5: ; preds = %3
%6 = tail call signext i8 @peek(i32* %0)
%7 = icmp eq i8 %6, 91
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @advance(i32* %0, i32 1)
%10 = tail call i32 @parse_colour_code(i32* %0, i32* %1)
br label %11
11: ; preds = %8, %12, %14
br label %3
12: ; preds = %5
%13 = tail call i32 @fputc(i8 signext 27, i32* %1)
br label %11
14: ; preds = %3
%15 = tail call i32 @html_encode(i32 %4, i32* %1)
br label %11
16: ; preds = %3
ret void
}