#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  double tv_sec;
  double tv_usec;
};
struct rusage {
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
scalar_t__ dup2(int, int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ execv(char *, char **);
int fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ wait4(int, int *, int /*<<< orphan*/, struct rusage *);
double run(char *prog) {
  struct rusage ru;
  double sec, usec;
  int in, out;
  char *cmd[2];
  int pid;
  int status;
  sec = 0;
  usec = 0;
  pid = fork();
  if (pid < 0) {
    err(1, "Could not fork\n");
  } else if (pid == 0) {
    if ((in = open("/dev/zero", O_RDONLY)) < 0)
      err(1, "could not open /dev/zero");
    if ((out = open("/dev/null", O_WRONLY)) < 0)
      err(1, "could not open /dev/null");
    if (dup2(in, 0) < 0)
      err(1, "could not reopen stdin");
    if (dup2(out, 1) < 0)
      err(1, "could not reopen stdout");
    cmd[0] = prog;
    cmd[1] = NULL;
    execv(prog, cmd);
    err(1, "Failed to exec\n");
  } else {
    wait4(pid, &status, 0, &ru);
    if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
      err(1, "Subprogram failed to execute\n");
    sec = ru.ru_utime.tv_sec;
    usec = ru.ru_utime.tv_usec / (1000.0 * 1000.0);
  }
  return sec + usec;
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    11c6 <run+0x46>
mov    $0x1,%edi
lea    0xe4c(%rip),%rsi
call   1040 <err@plt>
jmp    131f <run+0x19f>
cmpl   $0x0,-0x44(%rbp)
jne    12b4 <run+0x134>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1202 <run+0x82>
mov    $0x1,%edi
lea    0xe1b(%rip),%rsi
call   1040 <err@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1234 <run+0xb4>
mov    $0x1,%edi
lea    0xe02(%rip),%rsi
call   1040 <err@plt>
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    1259 <run+0xd9>
mov    $0x1,%edi
lea    0xdf6(%rip),%rsi
call   1040 <err@plt>
mov    -0x30(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    1281 <run+0x101>
mov    $0x1,%edi
lea    0xde5(%rip),%rsi
call   1040 <err@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <execv@plt>
mov    $0x1,%edi
lea    0xdcf(%rip),%rsi
call   1040 <err@plt>
jmp    131a <run+0x19a>
mov    -0x44(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
call   1050 <wait4@plt>
mov    -0x48(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%eax
je     12e9 <run+0x169>
mov    -0x48(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12fa <run+0x17a>
mov    $0x1,%edi
lea    0xd94(%rip),%rsi
call   1040 <err@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xcef(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    131f <run+0x19f>
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     11f0 <run+0x70>
je     11fc <run+0x7c>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %eax,%edi
xor    %edx,%edx
call   1050 <wait4@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %eax,%eax
je     11c6 <run+0x46>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     11d7 <run+0x57>
lea    0xebc(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
divsd  0xe15(%rip),%xmm0
jmp    12cb <run+0x14b>
lea    0xe11(%rip),%rsi
jmp    12b9 <run+0x139>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    0xe1b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1229 <run+0xa9>
lea    0xdf9(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1255 <run+0xd5>
lea    0xde6(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   1030 <dup2@plt>
test   %rax,%rax
jns    1275 <run+0xf5>
lea    0xddf(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
test   %rax,%rax
jns    1297 <run+0x117>
lea    0xdd4(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    %rbx,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <execv@plt>
lea    0xdc0(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { double, double }
@.str = [16 x i8] c"Could not fork\0A\00"
@.str.1 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.2 = [25 x i8] c"could not open /dev/zero\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.4 = [25 x i8] c"could not open /dev/null\00"
@.str.5 = [23 x i8] c"could not reopen stdin\00"
@.str.6 = [24 x i8] c"could not reopen stdout\00"
@.str.7 = [16 x i8] c"Failed to exec\0A\00"
@.str.8 = [30 x i8] c"Subprogram failed to execute\0A\00"
define double @run(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.rusage
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i8*]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %2
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
%11 = call i32 (...) @fork()
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %72
16: ; preds = %1
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %51
19: ; preds = %16
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 %21, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* @O_WRONLY
%27 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 %27, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %6
%33 = call i64 @dup2(i32 %32, i32 0)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %7
%39 = call i64 @dup2(i32 %38, i32 1)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = load i8*, i8** %2
%45 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
store i8* %44, i8** %45
%46 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 1
store i8* null, i8** %46
%47 = load i8*, i8** %2
%48 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
%49 = call i32 @execv(i8* %47, i8** %48)
%50 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %71
51: ; preds = %16
%52 = load i32, i32* %9
%53 = call i32 @wait4(i32 %52, i32* %10, i32 0, %struct.rusage* %3)
%54 = load i32, i32* %10
%55 = call i32 @WIFEXITED(i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %51
%58 = load i32, i32* %10
%59 = call i64 @WEXITSTATUS(i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %57, %51
%62 = call i32 @err(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %63
63: ; preds = %61, %57
%64 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i32 0, i32 0
%65 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %64, i32 0, i32 0
%66 = load double, double* %65
store double %66, double* %4
%67 = getelementptr inbounds %struct.rusage, %struct.rusage* %3, i32 0, i32 0
%68 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %67, i32 0, i32 1
%69 = load double, double* %68
%70 = fdiv double %69, 1.000000e+06
store double %70, double* %5
br label %71
71: ; preds = %63, %43
br label %72
72: ; preds = %71, %14
%73 = load double, double* %4
%74 = load double, double* %5
%75 = fadd double %73, %74
ret double %75
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { double, double }
@.str = [16 x i8] c"Could not fork\0A\00"
@.str.1 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.2 = [25 x i8] c"could not open /dev/zero\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.4 = [25 x i8] c"could not open /dev/null\00"
@.str.5 = [23 x i8] c"could not reopen stdin\00"
@.str.6 = [24 x i8] c"could not reopen stdout\00"
@.str.7 = [16 x i8] c"Failed to exec\0A\00"
@.str.8 = [30 x i8] c"Subprogram failed to execute\0A\00"
define double @run(i8* %0) {
%2 = alloca %struct.rusage
%3 = alloca [2 x i8*]
%4 = alloca i32
%5 = bitcast %struct.rusage* %2 to i8*
%6 = bitcast [2 x i8*]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 (...) @fork()
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %58
12: ; preds = %1
%13 = icmp eq i32 %8, 0
br i1 %13, label %14, label %41
14: ; preds = %12
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* @O_WRONLY
%22 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = tail call i64 @dup2(i32 %16, i32 0)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = tail call i64 @dup2(i32 %22, i32 1)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %0, i8** %37
%38 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* null, i8** %38
%39 = call i32 @execv(i8* %0, i8** %37)
%40 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %58
41: ; preds = %12
%42 = call i32 @wait4(i32 %8, i32* %4, i32 0, %struct.rusage* %2)
%43 = load i32, i32* %4
%44 = call i32 @WIFEXITED(i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = load i32, i32* %4
%48 = call i64 @WEXITSTATUS(i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46, %41
%51 = call i32 @err(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i64 0, i32 0, i32 0
%54 = load double, double* %53
%55 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i64 0, i32 0, i32 1
%56 = load double, double* %55
%57 = fdiv double %56, 1.000000e+06
br label %58
58: ; preds = %36, %52, %10
%59 = phi double [ 0.000000e+00, %10 ], [ 0.000000e+00, %36 ], [ %57, %52 ]
%60 = phi double [ 0.000000e+00, %10 ], [ 0.000000e+00, %36 ], [ %54, %52 ]
%61 = fadd double %59, %60
ret double %61
}