#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, long long);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s source target\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  FILE *inputfile, *outputfile;
  if ((inputfile = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Failed to open file \"%s\"\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  if ((outputfile = fopen(argv[2], "rb")) != NULL) {
    fprintf(stderr, "File \"%s\" existed\n", argv[2]);
    exit(EXIT_FAILURE);
  } else {
    fclose(outputfile);
    outputfile = fopen(argv[2], "wb");
  }
  long long sof;
  fseek(inputfile, 0L, SEEK_END);
  sof = ftell(inputfile);
  fclose(inputfile);
  fclose(outputfile);
  int in, out;
  in = open(argv[1], O_RDONLY);
  out = open(argv[2], O_WRONLY);
  char *temp;
  temp = (char *)malloc(sof * sizeof(char));
  read(in, temp, sof);
  for (int i = (sof - 1); i >= 0; i--) {
    write(out, &temp[i], 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)
je     11ea <main+0x4a>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe20(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1237 <main+0x97>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd3(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1284 <main+0xe4>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdc5(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdad(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <read@plt>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     1368 <main+0x1c8>
mov    -0x30(%rbp),%edi
mov    -0x38(%rbp),%rsi
movslq -0x3c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    1338 <main+0x198>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    12a8 <main+0x108>
mov    0x8(%r14),%rdi
lea    0xe5b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12bd <main+0x11d>
mov    %rax,%r15
mov    0x10(%r14),%rdi
lea    0xe3f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    12d3 <main+0x133>
xor    %edi,%edi
call   1040 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbp
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r15,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x8(%r14),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1050 <read@plt>
mov    %ebx,%eax
add    $0xffffffff,%eax
js     129b <main+0xfb>
mov    %eax,%eax
add    %rax,%rbp
nop
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rbp
test   %ebx,%ebx
jg     1280 <main+0xe0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd45(%rip),%rsi
jmp    12e7 <main+0x147>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd4b(%rip),%rsi
jmp    12e7 <main+0x147>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r14),%rdx
lea    0xd4f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s source target\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [26 x i8] c"Failed to open file \22%s\22\0A\00"
@.str.3 = [19 x i8] c"File \22%s\22 existed\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@O_RDONLY = global i32 0
@O_WRONLY = 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 i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%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 %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %6
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %23
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %7
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %51
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %37
%52 = load i32*, i32** %7
%53 = call i32 @fclose(i32* %52)
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %57, i32** %7
br label %58
58: ; preds = %51
%59 = load i32*, i32** %6
%60 = load i32, i32* @SEEK_END
%61 = call i32 @fseek(i32* %59, i64 0, i32 %60)
%62 = load i32*, i32** %6
%63 = call i64 @ftell(i32* %62)
store i64 %63, i64* %8
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = load i32, i32* @O_RDONLY
%72 = call i32 @open(i8* %70, i32 %71)
store i32 %72, i32* %9
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 2
%75 = load i8*, i8** %74
%76 = load i32, i32* @O_WRONLY
%77 = call i32 @open(i8* %75, i32 %76)
store i32 %77, i32* %10
%78 = load i64, i64* %8
%79 = mul i64 %78, 1
%80 = call i64 @malloc(i64 %79)
%81 = inttoptr i64 %80 to i8*
store i8* %81, i8** %11
%82 = load i32, i32* %9
%83 = load i8*, i8** %11
%84 = load i64, i64* %8
%85 = call i32 @read(i32 %82, i8* %83, i64 %84)
%86 = load i64, i64* %8
%87 = sub nsw i64 %86, 1
%88 = trunc i64 %87 to i32
store i32 %88, i32* %12
br label %89
89: ; preds = %99, %58
%90 = load i32, i32* %12
%91 = icmp sge i32 %90, 0
br i1 %91, label %92, label %102
92: ; preds = %89
%93 = load i32, i32* %10
%94 = load i8*, i8** %11
%95 = load i32, i32* %12
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
%98 = call i32 @write(i32 %93, i8* %97, i32 1)
br label %99
99: ; preds = %92
%100 = load i32, i32* %12
%101 = add nsw i32 %100, -1
store i32 %101, i32* %12
br label %89
102: ; preds = %89
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s source target\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [26 x i8] c"Failed to open file \22%s\22\0A\00"
@.str.3 = [19 x i8] c"File \22%s\22 existed\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %11
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %10
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %32, label %26
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %22
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
%33 = tail call i32 @fclose(i32* null)
%34 = load i8*, i8** %22
%35 = tail call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @SEEK_END
%37 = tail call i32 @fseek(i32* %13, i64 0, i32 %36)
%38 = tail call i64 @ftell(i32* %13)
%39 = tail call i32 @fclose(i32* %13)
%40 = tail call i32 @fclose(i32* %35)
%41 = load i8*, i8** %11
%42 = load i32, i32* @O_RDONLY
%43 = tail call i32 @open(i8* %41, i32 %42)
%44 = load i8*, i8** %22
%45 = load i32, i32* @O_WRONLY
%46 = tail call i32 @open(i8* %44, i32 %45)
%47 = tail call i64 @malloc(i64 %38)
%48 = inttoptr i64 %47 to i8*
%49 = tail call i32 @read(i32 %43, i8* %48, i64 %38)
%50 = trunc i64 %38 to i32
%51 = add i32 %50, -1
%52 = icmp sgt i32 %51, -1
br i1 %52, label %54, label %53
53: ; preds = %54, %32
ret i32 0
54: ; preds = %32, %54
%55 = phi i32 [ %59, %54 ], [ %51, %32 ]
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %48, i64 %56
%58 = tail call i32 @write(i32 %46, i8* %57, i32 1)
%59 = add nsw i32 %55, -1
%60 = icmp sgt i32 %55, 0
br i1 %60, label %54, label %53
}