#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ doc2text(char *, size_t, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  char *buffer = NULL;
  char *src = NULL;
  size_t length;
  assert(argc == 2);
  FILE *f = fopen(argv[1], "rb");
  assert(f != NULL);
  if (f) {
    assert(fseek(f, 0, SEEK_END) == 0);
    assert((length = ftell(f)) != -1);
    assert(fseek(f, 0, SEEK_SET) == 0);
    assert((src = malloc(length)) != NULL);
    fread(src, 1, length, f);
    fclose(f);
  }
  doc2text(src, length, &buffer);
  free(src);
  puts(buffer);
  free(buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpq   $0x0,-0x30(%rbp)
je     12b1 <main+0x111>
mov    -0x30(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10c0 <doc2text@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1070 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe31(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1070 <assert@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %r14,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <doc2text@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %9
%18 = load i32*, i32** %9
%19 = icmp ne i32* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %53
24: ; preds = %2
%25 = load i32*, i32** %9
%26 = load i32, i32* @SEEK_END
%27 = call i64 @fseek(i32* %25, i32 0, i32 %26)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32*, i32** %9
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %8
%33 = icmp ne i64 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32*, i32** %9
%37 = load i32, i32* @SEEK_SET
%38 = call i64 @fseek(i32* %36, i32 0, i32 %37)
%39 = icmp eq i64 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i64, i64* %8
%43 = call i8* @malloc(i64 %42)
store i8* %43, i8** %7
%44 = icmp ne i8* %43, null
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i8*, i8** %7
%48 = load i64, i64* %8
%49 = load i32*, i32** %9
%50 = call i32 @fread(i8* %47, i32 1, i64 %48, i32* %49)
%51 = load i32*, i32** %9
%52 = call i32 @fclose(i32* %51)
br label %53
53: ; preds = %24, %2
%54 = load i8*, i8** %7
%55 = load i64, i64* %8
%56 = call i32 @doc2text(i8* %54, i64 %55, i8** %6)
%57 = load i8*, i8** %7
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %6
%60 = call i32 @puts(i8* %59)
%61 = load i8*, i8** %6
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp eq i32 %0, 2
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32* %10, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
tail call void @llvm.assume(i1 %11)
%14 = load i32, i32* @SEEK_END
%15 = tail call i64 @fseek(i32* %10, i32 0, i32 %14)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i64 @ftell(i32* %10)
%20 = icmp ne i64 %19, -1
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i64 @fseek(i32* %10, i32 0, i32 %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i8* @malloc(i64 %19)
%29 = icmp ne i8* %28, null
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = tail call i32 @fread(i8* %28, i32 1, i64 %19, i32* %10)
%33 = tail call i32 @fclose(i32* %10)
%34 = call i32 @doc2text(i8* %28, i64 %19, i8** %3)
%35 = call i32 @free(i8* %28)
%36 = load i8*, i8** %3
%37 = call i32 @puts(i8* dereferenceable(1) %36)
%38 = load i8*, i8** %3
%39 = call i32 @free(i8* %38)
ret i32 0
}