#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*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp_s, *fp_t;
  int flag;
  char buf[512];
  fp_s = fopen(argv[1], "r+");
  fp_t = fopen(argv[2], "w+");
  while ((flag = fread(buf, 1, 512, fp_s)) > 0)
    fwrite(buf, 1, flag, fp_t);
  fclose(fp_s);
  fclose(fp_t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    11cc <main+0x8c>
lea    -0x230(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    1189 <main+0x49>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11cb <main+0x8b>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [3 x i8] c"w+\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 i32
%9 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
br label %18
18: ; preds = %23, %2
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%20 = load i32*, i32** %6
%21 = call i32 @fread(i8* %19, i32 1, i32 512, i32* %20)
store i32 %21, i32* %8
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%25 = load i32, i32* %8
%26 = load i32*, i32** %7
%27 = call i32 @fwrite(i8* %24, i32 1, i32 %25, i32* %26)
br label %18
28: ; preds = %18
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @fread(i8* %4, i32 1, i32 512, i32* %7)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2, %13
%14 = phi i32 [ %16, %13 ], [ %11, %2 ]
%15 = call i32 @fwrite(i8* %4, i32 1, i32 %14, i32* %10)
%16 = call i32 @fread(i8* %4, i32 1, i32 512, i32* %7)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %13, label %18
18: ; preds = %13, %2
%19 = tail call i32 @fclose(i32* %7)
%20 = tail call i32 @fclose(i32* %10)
ret i32 0
}