#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*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ feof(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fpi, fpo;
  char buffer;
  fpi = open(argv[1], O_RDONLY);
  fpo = open(argv[2], O_WRONLY);
  while (1) {
    read(fpi, &buffer, 1);
    if (feof(fpi)) {
      break;
    }
    write(fpo, &buffer, 1);
  }
  close(fpi);
  close(fpo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    -0x14(%rbp),%edi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c0 <main+0x70>
jmp    11d6 <main+0x86>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1198 <main+0x48>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r14d
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1060 <feof@plt>
test   %rax,%rax
jne    11db <main+0x8b>
lea    0xf(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1060 <feof@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %7
br label %19
19: ; preds = %2, %26
%20 = load i32, i32* %6
%21 = call i32 @read(i32 %20, i8* %8, i32 1)
%22 = load i32, i32* %6
%23 = call i64 @feof(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %29
26: ; preds = %19
%27 = load i32, i32* %7
%28 = call i32 @write(i32 %27, i8* %8, i32 1)
br label %19
29: ; preds = %25
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %7
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %5, i32 %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = call i32 @read(i32 %7, i8* %3, i32 1)
%13 = tail call i64 @feof(i32 %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2, %15
%16 = call i32 @write(i32 %11, i8* %3, i32 1)
%17 = call i32 @read(i32 %7, i8* %3, i32 1)
%18 = tail call i64 @feof(i32 %7)
%19 = icmp eq i64 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %2
%21 = tail call i32 @close(i32 %7)
%22 = tail call i32 @close(i32 %11)
ret i32 0
}