#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 */

/* Variables and functions */
int /*<<< orphan*/ checkArgc(int);
int createFile(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *nameFilter(char *);
int openFile(char *);
int read(int, char *, int);
int /*<<< orphan*/ setprogname(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd_src, fd_trgt, n;
  char *file_name;
  char buf[20480];
  setprogname(argv[0]);
  checkArgc(argc);
  int length;
  length = strlen(argv[1]);
  char changeable_name[length];
  strcpy(changeable_name, argv[1]);
  file_name = changeable_name;
  file_name = nameFilter(file_name);
  fd_trgt = createFile(file_name, argv[2]);
  fd_src = openFile(argv[1]);
  while ((n = read(fd_src, buf, 20480)) > 0)
    if (write(fd_trgt, buf, n) != n) {
      fprintf(stderr, "write error\n");
      exit(1);
    }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <setprogname@plt>
mov    -0x8(%rbp),%edi
call   1030 <checkArgc@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x5034(%rbp)
mov    -0x5034(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x5040(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x5050(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x5048(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x5050(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <nameFilter@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1080 <createFile@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <openFile@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x5030(%rbp),%rsi
mov    $0x5000,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12ca <main+0x11a>
mov    -0x18(%rbp),%edi
lea    -0x5030(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <write@plt>
cmp    -0x1c(%rbp),%eax
je     12c5 <main+0x115>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    126b <main+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x5040(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5008,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    (%rsi),%rdi
call   10d0 <setprogname@plt>
mov    %ebx,%edi
call   1030 <checkArgc@plt>
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
mov    %rsp,%r13
mov    %eax,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   10a0 <nameFilter@plt>
mov    0x10(%r14),%rsi
mov    %rax,%rdi
call   1080 <createFile@plt>
mov    %eax,%r15d
mov    0x8(%r14),%rdi
call   1060 <openFile@plt>
mov    %eax,%r14d
lea    -0x5030(%rbp),%r12
nopl   (%rax)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x5000,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1276 <main+0xc6>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebx,%eax
je     1230 <main+0x80>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"write error\0A\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 i8*
%10 = alloca [20480 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @setprogname(i8* %16)
%18 = load i32, i32* %4
%19 = call i32 @checkArgc(i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %12
%27 = alloca i8, i64 %25
store i64 %25, i64* %13
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %27, i8* %30)
store i8* %27, i8** %9
%32 = load i8*, i8** %9
%33 = call i8* @nameFilter(i8* %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @createFile(i8* %34, i8* %37)
store i32 %38, i32* %7
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @openFile(i8* %41)
store i32 %42, i32* %6
br label %43
43: ; preds = %59, %2
%44 = load i32, i32* %6
%45 = getelementptr inbounds [20480 x i8], [20480 x i8]* %10, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 20480)
store i32 %46, i32* %8
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %43
%49 = load i32, i32* %7
%50 = getelementptr inbounds [20480 x i8], [20480 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* %8
%52 = call i32 @write(i32 %49, i8* %50, i32 %51)
%53 = load i32, i32* %8
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %48
br label %43
60: ; preds = %43
store i32 0, i32* %3
%61 = load i8*, i8** %12
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"write error\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20480 x i8]
%4 = getelementptr inbounds [20480 x i8], [20480 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = tail call i32 @setprogname(i8* %5)
%7 = tail call i32 @checkArgc(i32 %0)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* %9)
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = load i8*, i8** %8
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = call i8* @nameFilter(i8* %13)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @createFile(i8* %16, i8* %18)
%20 = load i8*, i8** %8
%21 = call i32 @openFile(i8* %20)
br label %22
22: ; preds = %25, %2
%23 = call i32 @read(i32 %21, i8* %4, i32 20480)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = call i32 @write(i32 %19, i8* %4, i32 %23)
%27 = icmp eq i32 %26, %23
br i1 %27, label %22, label %28
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %22
ret i32 0
}