#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 EOF;
int /*<<< orphan*/ cymkd_render(char const *, char *, size_t,
                                int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
char *realloc(char *, size_t);
void cymkd_render_file(const char *file_name, FILE *in_fp, FILE *out_fp) {
  int ch;
  char *content;
  size_t content_len;
  size_t content_bufsize;
  content_bufsize = 1024;
  content = malloc(content_bufsize);
  content_len = 0;
  while ((ch = fgetc(in_fp)) != EOF) {
    if (content_len + 1 >= content_bufsize - 1) {
      content_bufsize *= 2;
      content = realloc(content, content_bufsize);
    }
    content[content_len] = ch;
    content_len++;
  }
  content[content_len] = '\0';
  cymkd_render(file_name, content, content_len, out_fp);
  free(content);
}


x86 assembly (clang, -O0):
<cymkd_render_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x400,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
je     11f3 <cymkd_render_file+0xa3>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     11d2 <cymkd_render_file+0x82>
mov    -0x38(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1181 <cymkd_render_file+0x31>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1050 <cymkd_render@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cymkd_render_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
mov    $0x400,%ebx
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e5a(%rip),%rax
cmp    (%rax),%ebp
jne    11c6 <cymkd_render_file+0x76>
xor    %r15d,%r15d
movb   $0x0,0x0(%r13,%r15,1)
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    0x10(%rsp),%rcx
call   1050 <cymkd_render@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
xor    %r14d,%r14d
jmp    11ed <cymkd_render_file+0x9d>
nopl   0x0(%rax,%rax,1)
mov    %bpl,0x0(%r13,%r14,1)
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %r15,%r14
mov    0x2dff(%rip),%rax
cmp    (%rax),%ebp
je     1195 <cymkd_render_file+0x45>
lea    0x1(%r14),%r15
lea    -0x1(%rbx),%rax
cmp    %rax,%r15
jb     11d0 <cymkd_render_file+0x80>
add    %rbx,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <realloc@plt>
mov    %rax,%r13
jmp    11d0 <cymkd_render_file+0x80>

LLVM IR (-O0):
@EOF = global i32 0
define void @cymkd_render_file(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i64 1024, i64* %10
%11 = load i64, i64* %10
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %8
store i64 0, i64* %9
br label %13
13: ; preds = %30, %3
%14 = load i32*, i32** %5
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %7
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = load i64, i64* %9
%20 = add i64 %19, 1
%21 = load i64, i64* %10
%22 = sub i64 %21, 1
%23 = icmp uge i64 %20, %22
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load i64, i64* %10
%26 = mul i64 %25, 2
store i64 %26, i64* %10
%27 = load i8*, i8** %8
%28 = load i64, i64* %10
%29 = call i8* @realloc(i8* %27, i64 %28)
store i8* %29, i8** %8
br label %30
30: ; preds = %24, %18
%31 = load i32, i32* %7
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %8
%34 = load i64, i64* %9
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 %32, i8* %35
%36 = load i64, i64* %9
%37 = add i64 %36, 1
store i64 %37, i64* %9
br label %13
38: ; preds = %13
%39 = load i8*, i8** %8
%40 = load i64, i64* %9
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %4
%43 = load i8*, i8** %8
%44 = load i64, i64* %9
%45 = load i32*, i32** %6
%46 = call i32 @cymkd_render(i8* %42, i8* %43, i64 %44, i32* %45)
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @cymkd_render_file(i8* %0, i32* nocapture %1, i32* %2) {
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i64 1024)
%5 = tail call i32 @fgetc(i32* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %3, %19
%9 = phi i32 [ %24, %19 ], [ %5, %3 ]
%10 = phi i64 [ %21, %19 ], [ 1024, %3 ]
%11 = phi i64 [ %13, %19 ], [ 0, %3 ]
%12 = phi i8* [ %20, %19 ], [ %4, %3 ]
%13 = add i64 %11, 1
%14 = add i64 %10, -1
%15 = icmp ult i64 %13, %14
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = shl i64 %10, 1
%18 = tail call i8* @realloc(i8* %12, i64 %17)
br label %19
19: ; preds = %16, %8
%20 = phi i8* [ %18, %16 ], [ %12, %8 ]
%21 = phi i64 [ %17, %16 ], [ %10, %8 ]
%22 = trunc i32 %9 to i8
%23 = getelementptr inbounds i8, i8* %20, i64 %11
store i8 %22, i8* %23
%24 = tail call i32 @fgetc(i32* %1)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %8
27: ; preds = %19, %3
%28 = phi i8* [ %4, %3 ], [ %20, %19 ]
%29 = phi i64 [ 0, %3 ], [ %13, %19 ]
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @cymkd_render(i8* %0, i8* %28, i64 %29, i32* %2)
%32 = tail call i32 @free(i8* %28)
ret void
}