#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;
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ simplecrypt(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *infilename;
  char *outfilename;
  if (argc == 3) {
    FILE *infile = NULL;
    FILE *outfile = NULL;
    int fsize;
    infilename = argv[1];
    outfilename = argv[2];
    if (1)
      printf("infilename: %s, outfilename: %s\n", infilename, outfilename);
    char *big_buf = NULL;
    if (!(infile = fopen(infilename, "r"))) {
      perror(infilename);
      return 1;
    }
    if (!(outfile = fopen(outfilename, "w"))) {
      perror(outfilename);
      return 1;
    }
    if (1)
      printf("open ok\n");
    fseek(infile, 0, SEEK_END);
    fsize = ftell(infile);
    if (1)
      printf("size: %d\n", fsize);
    big_buf = malloc(fsize + 8);
    if (!big_buf) {
      perror("malloc");
      return 1;
    }
    memset(big_buf, 0, fsize);
    fseek(infile, 0, SEEK_SET);
    if (errno)
      perror("fseek");
    fread(big_buf, fsize, 1, infile);
    if (errno)
      perror("fread");
    fclose(infile);
    simplecrypt(big_buf + (64 * 1024), fsize - (64 * 1024));
    fwrite(big_buf, fsize, 1, outfile);
    fclose(outfile);
    return 0;
  } else
    fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    13ba <main+0x1fa>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1259 <main+0x99>
mov    -0x18(%rbp),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13dd <main+0x21d>
mov    -0x20(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    128c <main+0xcc>
mov    -0x20(%rbp),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13dd <main+0x21d>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d43(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%edi
add    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12fd <main+0x13d>
lea    0xd4c(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13dd <main+0x21d>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    0x2cb2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    0x2caa(%rip),%rax
cmpq   $0x0,(%rax)
je     133c <main+0x17c>
lea    0xd08(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    0x2c78(%rip),%rax
cmpq   $0x0,(%rax)
je     136e <main+0x1ae>
lea    0xcdc(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
add    $0x10000,%rdi
mov    -0x34(%rbp),%esi
sub    $0x10000,%esi
call   1030 <simplecrypt@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13dd <main+0x21d>
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc7a(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x3,%edi
jne    1313 <main+0x143>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r12
lea    0xe0f(%rip),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     133a <main+0x16a>
mov    %rax,%r15
lea    0xe03(%rip),%rsi
mov    %r12,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1344 <main+0x174>
mov    %rax,%r14
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r15,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r12d
lea    0xdc0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x8(%r12),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     134e <main+0x17e>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1080 <memset@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    0x2d25(%rip),%r13
cmpq   $0x0,0x0(%r13)
jne    135c <main+0x18c>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmpq   $0x0,0x0(%r13)
jne    136d <main+0x19d>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
add    $0x10000,%rdi
mov    %r12d,%esi
add    $0xffff0000,%esi
call   1030 <simplecrypt@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   10f0 <fwrite@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    1330 <main+0x160>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd1c(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   10e0 <perror@plt>
jmp    132b <main+0x15b>
mov    %r12,%rdi
call   10e0 <perror@plt>
jmp    132b <main+0x15b>
lea    0xcda(%rip),%rdi
call   10e0 <perror@plt>
jmp    132b <main+0x15b>
lea    0xcd3(%rip),%rdi
call   10e0 <perror@plt>
jmp    12b6 <main+0xe6>
lea    0xcc8(%rip),%rdi
call   10e0 <perror@plt>
jmp    12d4 <main+0x104>

LLVM IR (-O0):
@.str = [33 x i8] c"infilename: %s, outfilename: %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"open ok\0A\00"
@SEEK_END = global i32 0
@.str.4 = [10 x i8] c"size: %d\0A\00"
@.str.5 = [7 x i8] c"malloc\00"
@SEEK_SET = global i32 0
@errno = global i64 0
@.str.6 = [6 x i8] c"fseek\00"
@.str.7 = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.8 = [26 x i8] c"Usage: %s infile outfile\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %87
14: ; preds = %2
store i32* null, i32** %8
store i32* null, i32** %9
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
store i8* null, i8** %11
%24 = load i8*, i8** %6
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %8
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %14
%28 = load i8*, i8** %6
%29 = call i32 @perror(i8* %28)
store i32 1, i32* %3
br label %94
30: ; preds = %14
%31 = load i8*, i8** %7
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %9
%33 = icmp ne i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i8*, i8** %7
%36 = call i32 @perror(i8* %35)
store i32 1, i32* %3
br label %94
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %8
%40 = load i32, i32* @SEEK_END
%41 = call i32 @fseek(i32* %39, i32 0, i32 %40)
%42 = load i32*, i32** %8
%43 = call i32 @ftell(i32* %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 8
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = icmp ne i8* %49, null
br i1 %50, label %53, label %51
51: ; preds = %37
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %94
53: ; preds = %37
%54 = load i8*, i8** %11
%55 = load i32, i32* %10
%56 = call i32 @memset(i8* %54, i32 0, i32 %55)
%57 = load i32*, i32** %8
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @fseek(i32* %57, i32 0, i32 %58)
%60 = load i64, i64* @errno
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %53
%65 = load i8*, i8** %11
%66 = load i32, i32* %10
%67 = load i32*, i32** %8
%68 = call i32 @fread(i8* %65, i32 %66, i32 1, i32* %67)
%69 = load i64, i64* @errno
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %71, %64
%74 = load i32*, i32** %8
%75 = call i32 @fclose(i32* %74)
%76 = load i8*, i8** %11
%77 = getelementptr inbounds i8, i8* %76, i64 65536
%78 = load i32, i32* %10
%79 = sub nsw i32 %78, 65536
%80 = call i32 @simplecrypt(i8* %77, i32 %79)
%81 = load i8*, i8** %11
%82 = load i32, i32* %10
%83 = load i32*, i32** %9
%84 = call i32 @fwrite(i8* %81, i32 %82, i32 1, i32* %83)
%85 = load i32*, i32** %9
%86 = call i32 @fclose(i32* %85)
store i32 0, i32* %3
br label %94
87: ; preds = %2
%88 = load i32, i32* @stderr
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 0
%91 = load i8*, i8** %90
%92 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %87
store i32 1, i32* %3
br label %94
94: ; preds = %93, %73, %51, %34, %27
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [33 x i8] c"infilename: %s, outfilename: %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@.str.4 = [10 x i8] c"size: %d\0A\00"
@.str.5 = [7 x i8] c"malloc\00"
@SEEK_SET = global i32 0
@errno = global i64 0
@.str.6 = [6 x i8] c"fseek\00"
@.str.7 = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.8 = [26 x i8] c"Usage: %s infile outfile\0A\00"
@str = [8 x i8] c"open ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %51
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %8)
%10 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @perror(i8* %6)
br label %55
14: ; preds = %4
%15 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @perror(i8* %8)
br label %55
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @fseek(i32* %10, i32 0, i32 %21)
%23 = tail call i32 @ftell(i32* %10)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = add nsw i32 %23, 8
%26 = tail call i8* @malloc(i32 %25)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %55
30: ; preds = %19
%31 = tail call i32 @memset(i8* %26, i32 0, i32 %23)
%32 = load i32, i32* @SEEK_SET
%33 = tail call i32 @fseek(i32* %10, i32 0, i32 %32)
%34 = load i64, i64* @errno
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %30
%37 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
%39 = tail call i32 @fread(i8* %26, i32 %23, i32 1, i32* %10)
%40 = load i64, i64* @errno
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = tail call i32 @fclose(i32* %10)
%46 = getelementptr inbounds i8, i8* %26, i64 65536
%47 = add nsw i32 %23, -65536
%48 = tail call i32 @simplecrypt(i8* %46, i32 %47)
%49 = tail call i32 @fwrite(i8* %26, i32 %23, i32 1, i32* %15)
%50 = tail call i32 @fclose(i32* %15)
br label %55
51: ; preds = %2
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %1
%54 = tail call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %12, %17, %28, %44, %51
%56 = phi i32 [ 1, %51 ], [ 0, %44 ], [ 1, %28 ], [ 1, %17 ], [ 1, %12 ]
ret i32 %56
}