#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ *openFile(char *, char *);
int /*<<< orphan*/ printUsage();
int main(int argc, char **argv) {
  FILE *inFile, *outFile;
  char *buffer;
  char word[4];
  int blockSize;
  int words, bytes;
  if (argc != 3) {
    printUsage();
    return 1;
  }
  inFile = openFile(argv[1], "rb");
  if (inFile == NULL) {
    return 2;
  }
  outFile = openFile(argv[2], "wb");
  if (outFile == NULL) {
    return 3;
  }
  while (!feof(inFile)) {
    buffer = (char *)malloc(128 * 1024);
    blockSize = fread(buffer, 1, 128 * 1024, inFile);
    for (words = 0; words < blockSize; words += 4) {
      memcpy(word, buffer + words, 4);
      for (bytes = 0; bytes < 4; bytes++) {
        buffer[words + 4 - bytes - 1] = word[bytes];
      }
    }
    fwrite(buffer, 1, blockSize, outFile);
    free(buffer);
  }
  fclose(outFile);
  fclose(inFile);
  return 0;
}


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)
je     11c3 <main+0x33>
mov    $0x0,%al
call   10a0 <printUsage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <openFile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <main+0x62>
movl   $0x2,-0x4(%rbp)
jmp    1324 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe02(%rip),%rsi
call   1060 <openFile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <main+0x91>
movl   $0x3,-0x4(%rbp)
jmp    1324 <main+0x194>
jmp    1226 <main+0x96>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1244 <main+0xb4>
jmp    130b <main+0x17b>
mov    $0x20000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20000,%edx
call   1040 <fread@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    12e8 <main+0x158>
lea    -0x2c(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jge    12d5 <main+0x145>
movslq -0x38(%rbp),%rax
mov    -0x2c(%rbp,%rax,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x4,%ecx
sub    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    129f <main+0x10f>
jmp    12da <main+0x14a>
mov    -0x34(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
jmp    1273 <main+0xe3>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1226 <main+0x96>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    11fa <main+0x6a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <openFile@plt>
test   %rax,%rax
je     1208 <main+0x78>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <openFile@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     120f <main+0x7f>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1223 <main+0x93>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1214 <main+0x84>
xor    %eax,%eax
call   10a0 <printUsage@plt>
mov    $0x1,%eax
jmp    1214 <main+0x84>
mov    $0x2,%eax
jmp    1214 <main+0x84>
mov    $0x3,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%r12
jmp    1259 <main+0xc9>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    0x10(%rsp),%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e4 <main+0x54>
mov    $0x20000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x20000,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    1230 <main+0xa0>
mov    %r13d,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%r14,1),%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1080 <memcpy@plt>
movzbl 0xc(%rsp),%eax
mov    %al,0x3(%rbx,%r14,1)
movzbl 0xd(%rsp),%eax
mov    %al,0x2(%rbx,%r14,1)
movzbl 0xe(%rsp),%eax
mov    %al,0x1(%rbx,%r14,1)
movzbl 0xf(%rsp),%eax
mov    %al,(%rbx,%r14,1)
lea    0x4(%r14),%rax
mov    %rax,%r14
cmp    %rbp,%rax
jl     1290 <main+0x100>
jmp    1230 <main+0xa0>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [4 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (...) @printUsage()
store i32 1, i32* %3
br label %91
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @openFile(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 2, i32* %3
br label %91
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @openFile(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 3, i32* %3
br label %91
33: ; preds = %25
br label %34
34: ; preds = %79, %33
%35 = load i32*, i32** %6
%36 = call i32 @feof(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %86
39: ; preds = %34
%40 = call i64 @malloc(i32 131072)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = load i32*, i32** %6
%44 = call i32 @fread(i8* %42, i32 1, i32 131072, i32* %43)
store i32 %44, i32* %10
store i32 0, i32* %11
br label %45
45: ; preds = %76, %39
%46 = load i32, i32* %11
%47 = load i32, i32* %10
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %79
49: ; preds = %45
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%51 = load i8*, i8** %8
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = call i32 @memcpy(i8* %50, i8* %54, i32 4)
store i32 0, i32* %12
br label %56
56: ; preds = %72, %49
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, 4
br i1 %58, label %59, label %75
59: ; preds = %56
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = load i8*, i8** %8
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 4
%67 = load i32, i32* %12
%68 = sub nsw i32 %66, %67
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %64, i64 %70
store i8 %63, i8* %71
br label %72
72: ; preds = %59
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %56
75: ; preds = %56
br label %76
76: ; preds = %75
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 4
store i32 %78, i32* %11
br label %45
79: ; preds = %45
%80 = load i8*, i8** %8
%81 = load i32, i32* %10
%82 = load i32*, i32** %7
%83 = call i32 @fwrite(i8* %80, i32 1, i32 %81, i32* %82)
%84 = load i8*, i8** %8
%85 = call i32 @free(i8* %84)
br label %34
86: ; preds = %34
%87 = load i32*, i32** %7
%88 = call i32 @fclose(i32* %87)
%89 = load i32*, i32** %6
%90 = call i32 @fclose(i32* %89)
store i32 0, i32* %3
br label %91
91: ; preds = %86, %32, %24, %15
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @printUsage()
br label %56
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @openFile(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %56, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @openFile(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %56, label %18
18: ; preds = %13
%19 = call i32 @feof(i32* %11)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %18
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
br label %25
25: ; preds = %21, %48
%26 = call i64 @malloc(i32 131072)
%27 = inttoptr i64 %26 to i8*
%28 = call i32 @fread(i8* %27, i32 1, i32 131072, i32* %11)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %48
30: ; preds = %25
%31 = zext i32 %28 to i64
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %36, %32 ]
%34 = getelementptr inbounds i8, i8* %27, i64 %33
%35 = call i32 @memcpy(i8* %4, i8* %34, i32 4)
%36 = add nuw i64 %33, 4
%37 = load i8, i8* %4
%38 = or i64 %33, 3
%39 = getelementptr inbounds i8, i8* %27, i64 %38
store i8 %37, i8* %39
%40 = load i8, i8* %22
%41 = or i64 %33, 2
%42 = getelementptr inbounds i8, i8* %27, i64 %41
store i8 %40, i8* %42
%43 = load i8, i8* %23
%44 = or i64 %33, 1
%45 = getelementptr inbounds i8, i8* %27, i64 %44
store i8 %43, i8* %45
%46 = load i8, i8* %24
store i8 %46, i8* %34
%47 = icmp slt i64 %36, %31
br i1 %47, label %32, label %48
48: ; preds = %32, %25
%49 = call i32 @fwrite(i8* %27, i32 1, i32 %28, i32* %16)
%50 = call i32 @free(i8* %27)
%51 = call i32 @feof(i32* %11)
%52 = icmp eq i32 %51, 0
br i1 %52, label %25, label %53
53: ; preds = %48, %18
%54 = call i32 @fclose(i32* %16)
%55 = call i32 @fclose(i32* %11)
br label %56
56: ; preds = %13, %8, %53, %6
%57 = phi i32 [ 1, %6 ], [ 0, %53 ], [ 2, %8 ], [ 3, %13 ]
ret i32 %57
}