#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
double now();
int /*<<< orphan*/ printf(char *, double);
void io() {
  double start = now();
  int i;
  FILE *in = fopen("/dev/urandom", "r");
  FILE *out = fopen("/tmp/test", "w");
  for (i = 0; (i < 1000000); i++) {
    int ch = fgetc(in);
    fputc(ch, out);
  }
  fclose(in);
  fclose(out);
  double end = now();
  printf("I/O benchmark time: %.04f\r\n", end - start);
}


x86 assembly (clang, -O0):
<io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1080 <now@plt>
movsd  %xmm0,-0x8(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf4240,-0xc(%rbp)
jge    11dc <io+0x7c>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a9 <io+0x49>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1080 <now@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <now@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xe84(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe7d(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0xf4240,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0xffffffff,%ebp
jne    11b0 <io+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1080 <now@plt>
subsd  0x8(%rsp),%xmm0
lea    0xe30(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"/tmp/test\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"I/O benchmark time: %.04f\0D\0A\00"
define void @io() {
%1 = alloca double
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double
%7 = call double (...) @now()
store double %7, double* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %4
store i32 0, i32* %2
br label %10
10: ; preds = %19, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1000000
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = load i32*, i32** %4
%18 = call i32 @fputc(i32 %16, i32* %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %10
22: ; preds = %10
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i32*, i32** %4
%26 = call i32 @fclose(i32* %25)
%27 = call double (...) @now()
store double %27, double* %6
%28 = load double, double* %6
%29 = load double, double* %1
%30 = fsub double %28, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), double %30)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"/tmp/test\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [28 x i8] c"I/O benchmark time: %.04f\0D\0A\00"
define void @io() {
%1 = tail call double (...) @now()
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %8, %4 ]
%6 = tail call i32 @fgetc(i32* %2)
%7 = tail call i32 @fputc(i32 %6, i32* %3)
%8 = add nuw nsw i32 %5, 1
%9 = icmp eq i32 %8, 1000000
br i1 %9, label %10, label %4
10: ; preds = %4
%11 = tail call i32 @fclose(i32* %2)
%12 = tail call i32 @fclose(i32* %3)
%13 = tail call double (...) @now()
%14 = fsub double %13, %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), double %14)
ret void
}