#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*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fwrite(char const *, int, size_t, int /*<<< orphan*/ *);
double getRealTime();
scalar_t__ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ stderr;
void run(const char *restrict command, const char *restrict buffer,
         size_t buffer_size, unsigned int buffer_copy, unsigned int repeats,
         double *results) {
  for (unsigned int r = 0; r < repeats; r++) {
    FILE *target = popen(command, "w");
    if (!target) {
      fprintf(stderr, "Can't start \"%s\"\n", command);
      results[r] = -1;
    }
    double start = getRealTime();
    for (unsigned int b = 0; b < buffer_copy; b++) {
      fwrite(buffer, sizeof(char), buffer_size, target);
      fflush(target);
    }
    if (pclose(target) != 0) {
      fprintf(stderr, "\"%s\" had an error.\n", command);
      results[r] = -1;
    }
    double stop = getRealTime();
    results[r] = (stop - start);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    129a <run+0x13a>
mov    -0x8(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11de <run+0x7e>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsd  0xe27(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1060 <getRealTime@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    122a <run+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fflush@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11f1 <run+0x91>
mov    -0x38(%rbp),%rdi
call   1030 <pclose@plt>
cmp    $0x0,%rax
je     126a <run+0x10a>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdcb(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsd  0xd9b(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1060 <getRealTime@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1186 <run+0x26>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0xc(%rsp)
test   %r8d,%r8d
je     1285 <run+0x125>
mov    %r9,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r12
mov    %r8d,%eax
mov    %rax,0x10(%rsp)
xor    %r14d,%r14d
mov    %rdi,0x18(%rsp)
jmp    11c2 <run+0x62>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getRealTime@plt>
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%r15,%r14,8)
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     1285 <run+0x125>
mov    %r12,%rdi
lea    0xe34(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11ff <run+0x9f>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
mov    %r12,%rdx
call   1040 <fprintf@plt>
movabs $0xbff0000000000000,%rax
mov    %rax,(%r15,%r14,8)
mov    %r15,%r12
xor    %eax,%eax
call   1060 <getRealTime@plt>
movsd  %xmm0,0x20(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,%r15d
test   %eax,%eax
je     1241 <run+0xe1>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    %r13,%rdi
call   1050 <fflush@plt>
add    $0xffffffff,%r15d
jne    1220 <run+0xc0>
mov    %r13,%rdi
call   1030 <pclose@plt>
test   %rax,%rax
mov    %r12,%r15
mov    0x18(%rsp),%r12
je     11a0 <run+0x40>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    %r12,%rdx
call   1040 <fprintf@plt>
movabs $0xbff0000000000000,%rax
mov    %rax,(%r15,%r14,8)
jmp    11a0 <run+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Can't start \22%s\22\0A\00"
@.str.2 = [20 x i8] c"\22%s\22 had an error.\0A\00"
define void @run(i8* noalias %0, i8* noalias %1, i64 %2, i32 %3, i32 %4, double* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32*
%15 = alloca double
%16 = alloca i32
%17 = alloca double
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double* %5, double** %12
store i32 0, i32* %13
br label %18
18: ; preds = %72, %6
%19 = load i32, i32* %13
%20 = load i32, i32* %11
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %75
22: ; preds = %18
%23 = load i8*, i8** %7
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %14
%25 = load i32*, i32** %14
%26 = icmp ne i32* %25, null
br i1 %26, label %35, label %27
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %7
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load double*, double** %12
%32 = load i32, i32* %13
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double -1.000000e+00, double* %34
br label %35
35: ; preds = %27, %22
%36 = call double (...) @getRealTime()
store double %36, double* %15
store i32 0, i32* %16
br label %37
37: ; preds = %48, %35
%38 = load i32, i32* %16
%39 = load i32, i32* %10
%40 = icmp ult i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i8*, i8** %8
%43 = load i64, i64* %9
%44 = load i32*, i32** %14
%45 = call i32 @fwrite(i8* %42, i32 1, i64 %43, i32* %44)
%46 = load i32*, i32** %14
%47 = call i32 @fflush(i32* %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %16
%50 = add i32 %49, 1
store i32 %50, i32* %16
br label %37
51: ; preds = %37
%52 = load i32*, i32** %14
%53 = call i64 @pclose(i32* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %7
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = load double*, double** %12
%60 = load i32, i32* %13
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double -1.000000e+00, double* %62
br label %63
63: ; preds = %55, %51
%64 = call double (...) @getRealTime()
store double %64, double* %17
%65 = load double, double* %17
%66 = load double, double* %15
%67 = fsub double %65, %66
%68 = load double*, double** %12
%69 = load i32, i32* %13
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
store double %67, double* %71
br label %72
72: ; preds = %63
%73 = load i32, i32* %13
%74 = add i32 %73, 1
store i32 %74, i32* %13
br label %18
75: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Can't start \22%s\22\0A\00"
@.str.2 = [20 x i8] c"\22%s\22 had an error.\0A\00"
define void @run(i8* noalias %0, i8* noalias nocapture %1, i64 %2, i32 %3, i32 %4, double* nocapture writeonly %5) {
%7 = icmp eq i32 %4, 0
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = icmp eq i32 %3, 0
%10 = zext i32 %4 to i64
br label %12
11: ; preds = %35, %6
ret void
12: ; preds = %8, %35
%13 = phi i64 [ 0, %8 ], [ %39, %35 ]
%14 = tail call i32* @popen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = getelementptr inbounds double, double* %5, i64 %13
store double -1.000000e+00, double* %19
br label %20
20: ; preds = %16, %12
%21 = tail call double (...) @getRealTime()
br i1 %9, label %22, label %25
22: ; preds = %25, %20
%23 = tail call i64 @pclose(i32* %14)
%24 = icmp eq i64 %23, 0
br i1 %24, label %35, label %31
25: ; preds = %20, %25
%26 = phi i32 [ %29, %25 ], [ 0, %20 ]
%27 = tail call i32 @fwrite(i8* %1, i32 1, i64 %2, i32* %14)
%28 = tail call i32 @fflush(i32* %14)
%29 = add nuw i32 %26, 1
%30 = icmp eq i32 %29, %3
br i1 %30, label %22, label %25
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = getelementptr inbounds double, double* %5, i64 %13
store double -1.000000e+00, double* %34
br label %35
35: ; preds = %31, %22
%36 = tail call double (...) @getRealTime()
%37 = fsub double %36, %21
%38 = getelementptr inbounds double, double* %5, i64 %13
store double %37, double* %38
%39 = add nuw nsw i64 %13, 1
%40 = icmp eq i64 %39, %10
br i1 %40, label %11, label %12
}