#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 scalar_t__ clock_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
double CLOCKS_PER_SEC;
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
scalar_t__ clock();
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, double);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd1, fd2;
  int len;
  char buf[1];
  clock_t start, stop;
  double duration;
  fd1 = open("news.txt", O_RDONLY);
  fd2 = open("copy.txt", O_WRONLY | O_CREAT | O_TRUNC);
  start = clock();
  while ((len = read(fd1, buf, sizeof(buf))) > 0)
    write(fd2, buf, len);
  stop = clock();
  duration = (double)(stop - start) / CLOCKS_PER_SEC;
  printf("used time: %f\n", duration);
  close(fd1);
  close(fd2);
  return 0;
}


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)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
lea    0xe59(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11f4 <main+0x94>
mov    -0x18(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    11c3 <main+0x63>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dbd(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1080 <open@plt>
mov    0x2e35(%rip),%rcx
mov    0x2e6e(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %eax,%r15d
mov    0x2e58(%rip),%rax
or     (%rax),%esi
lea    0xe68(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
lea    0x7(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    11f0 <main+0x90>
lea    0x7(%rsp),%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2dca(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"news.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"copy.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [15 x i8] c"used time: %f\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 [1 x i8]
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %7
%21 = call i64 (...) @clock()
store i64 %21, i64* %10
br label %22
22: ; preds = %27, %2
%23 = load i32, i32* %6
%24 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 1)
store i32 %25, i32* %8
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %7
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %9, i64 0, i64 0
%30 = load i32, i32* %8
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
br label %22
32: ; preds = %22
%33 = call i64 (...) @clock()
store i64 %33, i64* %11
%34 = load i64, i64* %11
%35 = load i64, i64* %10
%36 = sub nsw i64 %34, %35
%37 = sitofp i64 %36 to double
%38 = load double, double* @CLOCKS_PER_SEC
%39 = fdiv double %37, %38
store double %39, double* %12
%40 = load double, double* %12
%41 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %40)
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"news.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [9 x i8] c"copy.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [15 x i8] c"used time: %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i64 (...) @clock()
%14 = call i32 @read(i32 %6, i8* %4, i32 1)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2, %16
%17 = phi i32 [ %19, %16 ], [ %14, %2 ]
%18 = call i32 @write(i32 %12, i8* %4, i32 %17)
%19 = call i32 @read(i32 %6, i8* %4, i32 1)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %16, label %21
21: ; preds = %16, %2
%22 = tail call i64 (...) @clock()
%23 = sub nsw i64 %22, %13
%24 = sitofp i64 %23 to double
%25 = load double, double* @CLOCKS_PER_SEC
%26 = fdiv double %24, %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = tail call i32 @close(i32 %6)
%29 = tail call i32 @close(i32 %12)
ret i32 0
}