#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char c = '\0';
  int in = -1, out = -1;
  in = open("1m_data.file", O_RDONLY);
  out = open("1m_data.file.copy", O_WRONLY | O_TRUNC | O_CREAT,
             S_IRUSR | S_IWUSR);
  while (read(in, &c, 1) == 1) {
    write(out, &c, 1);
  }
  close(in);
  close(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
or     (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    0x2e2a(%rip),%rax
or     (%rax),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11e9 <main+0xa9>
mov    -0x10(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11b9 <main+0x79>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xf(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x2e42(%rip),%rax
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e78(%rip),%rax
or     (%rax),%esi
mov    0x2e37(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11e4 <main+0xa4>
lea    0xf(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     11c0 <main+0x80>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"1m_data.file\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"1m_data.file.copy\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i8 0, i8* %2
store i32 -1, i32* %3
store i32 -1, i32* %4
%5 = load i32, i32* @O_RDONLY
%6 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
store i32 %15, i32* %4
br label %16
16: ; preds = %20, %0
%17 = load i32, i32* %3
%18 = call i32 @read(i32 %17, i8* %2, i32 1)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %4
%22 = call i32 @write(i32 %21, i8* %2, i32 1)
br label %16
23: ; preds = %16
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"1m_data.file\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"1m_data.file.copy\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca i8
store i8 0, i8* %1
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %5, %4
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %11)
%13 = call i32 @read(i32 %3, i8* %1, i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %0, %15
%16 = call i32 @write(i32 %12, i8* %1, i32 1)
%17 = call i32 @read(i32 %3, i8* %1, i32 1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %15, label %19
19: ; preds = %15, %0
%20 = tail call i32 @close(i32 %3)
%21 = tail call i32 @close(i32 %12)
ret i32 0
}