#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ charset_close();
int /*<<< orphan*/ charset_init_input(char *, int /*<<< orphan*/ *);
int charset_read(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char buf[0x20000];
  int read;
  if (argc == 3) {
    FILE *file = fopen(argv[2], "r");
    if (!file) {
      perror("fopen");
      exit(1);
    }
    charset_init_input(argv[1], file);
    do {
      read = charset_read(buf, sizeof(buf), 0);
      fwrite(buf, 1, read, stdout);
    } while (read > 0);
    charset_close();
    if (fclose(file)) {
      perror("fclose");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    126a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20020(%rbp)
cmpq   $0x0,-0x20020(%rbp)
jne    11e2 <main+0x62>
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20020(%rbp),%rsi
call   1030 <charset_init_input@plt>
lea    -0x20010(%rbp),%rdi
mov    $0x20000,%esi
xor    %edx,%edx
call   1050 <charset_read@plt>
mov    %eax,-0x20014(%rbp)
lea    -0x20010(%rbp),%rdi
mov    -0x20014(%rbp),%edx
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
cmpl   $0x0,-0x20014(%rbp)
jg     11f6 <main+0x76>
mov    $0x0,%al
call   1080 <charset_close@plt>
mov    -0x20020(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1265 <main+0xe5>
lea    0xda8(%rip),%rdi
call   1070 <perror@plt>
jmp    126a <main+0xea>
mov    -0x4(%rbp),%eax
add    $0x20020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x20008,%rsp
cmp    $0x3,%edi
jne    120b <main+0x8b>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xe60(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1229 <main+0xa9>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
mov    %rax,%rsi
call   1030 <charset_init_input@plt>
mov    %rsp,%rbx
mov    0x2e1d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x20000,%esi
xor    %edx,%edx
call   1050 <charset_read@plt>
mov    %eax,%ebp
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   10a0 <fwrite@plt>
test   %ebp,%ebp
jg     11d0 <main+0x50>
xor    %eax,%eax
call   1080 <charset_close@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    121b <main+0x9b>
xor    %eax,%eax
add    $0x20008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde6(%rip),%rdi
call   1070 <perror@plt>
jmp    120b <main+0x8b>
lea    0xdd2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
@stdout = global i32 0
@.str.2 = [7 x i8] c"fclose\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [131072 x i8]
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 3
br i1 %10, label %11, label %45
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32*, i32** %8
%26 = call i32 @charset_init_input(i8* %24, i32* %25)
br label %27
27: ; preds = %34, %21
%28 = getelementptr inbounds [131072 x i8], [131072 x i8]* %6, i64 0, i64 0
%29 = call i32 @charset_read(i8* %28, i32 131072, i32 0)
store i32 %29, i32* %7
%30 = getelementptr inbounds [131072 x i8], [131072 x i8]* %6, i64 0, i64 0
%31 = load i32, i32* %7
%32 = load i32, i32* @stdout
%33 = call i32 @fwrite(i8* %30, i32 1, i32 %31, i32 %32)
br label %34
34: ; preds = %27
%35 = load i32, i32* %7
%36 = icmp sgt i32 %35, 0
br i1 %36, label %27, label %37
37: ; preds = %34
%38 = call i32 (...) @charset_close()
%39 = load i32*, i32** %8
%40 = call i64 @fclose(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
br label %45
45: ; preds = %44, %2
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
@stdout = global i32 0
@.str.2 = [7 x i8] c"fclose\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [131072 x i8]
%4 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %29
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @charset_init_input(i8* %16, i32* %9)
br label %18
18: ; preds = %18, %14
%19 = call i32 @charset_read(i8* %4, i32 131072, i32 0)
%20 = load i32, i32* @stdout
%21 = call i32 @fwrite(i8* %4, i32 1, i32 %19, i32 %20)
%22 = icmp sgt i32 %19, 0
br i1 %22, label %18, label %23
23: ; preds = %18
%24 = call i32 (...) @charset_close()
%25 = call i64 @fclose(i32* %9)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %23, %27, %2
ret i32 0
}