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

/* Variables and functions */
int /*<<< orphan*/ RepFclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *RepFread(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int LenIn, LenOut;
  int i;
  char Buf[10240];
  FILE *F;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s type filename > output\n", argv[0]);
    exit(-1);
  }
  F = RepFread(argv[1], argv[2]);
  if (!F) {
    fprintf(stderr, "ERROR: Invalid -- type='%s' filename='%s'\n", argv[1],
            argv[2]);
    return (-1);
  }
  LenIn = 1;
  while (LenIn > 0) {
    LenIn = fread(Buf, 1, sizeof(Buf), F);
    if (LenIn > 0) {
      LenOut = 0;
      while (LenOut < LenIn) {
        i = fwrite(Buf + LenOut, 1, LenIn - LenOut, stdout);
        LenOut += i;
        if (i == 0)
          break;
      }
    }
  }
  RepFclose(F);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ab <main+0x4b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1060 <RepFread@plt>
mov    %rax,-0x2828(%rbp)
cmpq   $0x0,-0x2828(%rbp)
jne    1208 <main+0xa8>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <main+0x15a>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    12a7 <main+0x147>
lea    -0x2820(%rbp),%rdi
mov    -0x2828(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2800,%edx
call   1030 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    12a2 <main+0x142>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    129d <main+0x13d>
lea    -0x2820(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
sub    -0x18(%rbp),%edx
mov    0x2d67(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1298 <main+0x138>
jmp    129d <main+0x13d>
jmp    124a <main+0xea>
jmp    12a2 <main+0x142>
jmp    120f <main+0xaf>
mov    -0x2828(%rbp),%rdi
call   1040 <RepFclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2800,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    1233 <main+0xd3>
mov    0x8(%rbp),%rdi
mov    0x10(%rbp),%rsi
call   1060 <RepFread@plt>
test   %rax,%rax
je     11ff <main+0x9f>
mov    %rax,%r15
mov    %rsp,%r14
mov    0x2e3e(%rip),%r12
jmp    11a4 <main+0x44>
nopl   0x0(%rax)
test   %ebp,%ebp
jle    11f3 <main+0x93>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x2800,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11f3 <main+0x93>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edx
sub    %ebx,%edx
jle    11a0 <main+0x40>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
mov    (%r12),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
add    %eax,%ebx
test   %eax,%eax
jne    11d0 <main+0x70>
jmp    11a0 <main+0x40>
mov    %r15,%rdi
call   1040 <RepFclose@plt>
xor    %eax,%eax
jmp    1223 <main+0xc3>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
mov    0x10(%rbp),%rcx
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x2800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s type filename > output\0A\00"
@.str.1 = [43 x i8] c"ERROR: Invalid -- type='%s' filename='%s'\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10240 x i8]
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @RepFread(i8* %23, i8* %26)
store i32* %27, i32** %10
%28 = load i32*, i32** %10
%29 = icmp ne i32* %28, null
br i1 %29, label %39, label %30
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %37)
store i32 -1, i32* %3
br label %76
39: ; preds = %20
store i32 1, i32* %6
br label %40
40: ; preds = %72, %39
%41 = load i32, i32* %6
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %73
43: ; preds = %40
%44 = getelementptr inbounds [10240 x i8], [10240 x i8]* %9, i64 0, i64 0
%45 = load i32*, i32** %10
%46 = call i32 @fread(i8* %44, i32 1, i32 10240, i32* %45)
store i32 %46, i32* %6
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %72
49: ; preds = %43
store i32 0, i32* %7
br label %50
50: ; preds = %70, %49
%51 = load i32, i32* %7
%52 = load i32, i32* %6
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %71
54: ; preds = %50
%55 = getelementptr inbounds [10240 x i8], [10240 x i8]* %9, i64 0, i64 0
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = sub nsw i32 %59, %60
%62 = load i32, i32* @stdout
%63 = call i32 @fwrite(i8* %58, i32 1, i32 %61, i32 %62)
store i32 %63, i32* %8
%64 = load i32, i32* %8
%65 = load i32, i32* %7
%66 = add nsw i32 %65, %64
store i32 %66, i32* %7
%67 = load i32, i32* %8
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %54
br label %71
70: ; preds = %54
br label %50
71: ; preds = %69, %50
br label %72
72: ; preds = %71, %43
br label %40
73: ; preds = %40
%74 = load i32*, i32** %10
%75 = call i32 @RepFclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %73, %30
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s type filename > output\0A\00"
@.str.1 = [43 x i8] c"ERROR: Invalid -- type='%s' filename='%s'\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10240 x i8]
%4 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @RepFread(i8* %13, i8* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %12
%21 = load i8*, i8** %14
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
br label %40
23: ; preds = %11, %37
%24 = call i32 @fread(i8* %4, i32 1, i32 10240, i32* %16)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %23, %29
%27 = phi i32 [ %35, %29 ], [ 0, %23 ]
%28 = icmp sgt i32 %24, %27
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = sext i32 %27 to i64
%31 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 %30
%32 = sub nsw i32 %24, %27
%33 = load i32, i32* @stdout
%34 = call i32 @fwrite(i8* %31, i32 1, i32 %32, i32 %33)
%35 = add nsw i32 %34, %27
%36 = icmp eq i32 %34, 0
br i1 %36, label %37, label %26
37: ; preds = %26, %29
br i1 %25, label %23, label %38
38: ; preds = %23, %37
%39 = call i32 @RepFclose(i32* %16)
br label %40
40: ; preds = %38, %18
%41 = phi i32 [ 0, %38 ], [ -1, %18 ]
ret i32 %41
}