#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  double tv_sec;
  double tv_usec;
};
struct TYPE_3__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ ITIMER_VIRTUAL;
double LONG_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
double floor(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
scalar_t__ setitimer(int /*<<< orphan*/, struct itimerval *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
double strtod(char *, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  const char *program_name = argv[0];
  double timeout;
  if (argc < 3) {
    fprintf(stderr,
            "setitimer-helper: runs a program with a virtual CPU limit\n"
            "usage: %s TIMEOUT PROGRAM [ARG...]\n"
            "  where TIMEOUT is the virtual CPU limit, in seconds,\n"
            "    and remaining arguments specify the program to run\n"
            "    and its argument.\n",
            program_name);
    return EXIT_FAILURE;
  }
  timeout = strtod(argv[1], NULL);
  if (timeout >= 0.0 && timeout < LONG_MAX) {
    struct itimerval it;
    it.it_interval.tv_sec = 0;
    it.it_interval.tv_usec = 0;
    it.it_value.tv_sec = timeout;
    it.it_value.tv_usec = (timeout - floor(timeout)) * 1000000;
    if (setitimer(ITIMER_VIRTUAL, &it, NULL) < 0)
      fprintf(stderr, "%s: setitimer: %s\n", program_name, strerror(errno));
  } else
    fprintf(stderr, "%s: invalid timeout value \"%s\"\n", program_name,
            argv[1]);
  execvp(argv[2], &argv[2]);
  fprintf(stderr, "%s: couldn't exec \"%s\": %s\n", program_name, argv[2],
          strerror(errno));
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11b7 <main+0x57>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1331 <main+0x1d1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12a3 <main+0x143>
movsd  -0x20(%rbp),%xmm1
mov    0x2de5(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    12a3 <main+0x143>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1080 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xdc5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <setitimer@plt>
cmp    $0x0,%rax
jge    129e <main+0x13e>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12c6 <main+0x166>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1060 <execvp@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    %rax,%r8
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    (%rsi),%r14
cmp    $0x2,%edi
jg     118f <main+0x2f>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1290 <main+0x130>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1231 <main+0xd1>
mov    0x2e1e(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm0,%xmm1
jbe    1231 <main+0xd1>
xorpd  %xmm1,%xmm1
movupd %xmm1,0x20(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1080 <floor@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe17(%rip),%xmm1
movsd  %xmm1,0x18(%rsp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <setitimer@plt>
test   %rax,%rax
jns    124f <main+0xef>
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebp
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xec2(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
jmp    1248 <main+0xe8>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rcx
lea    0xeb7(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x10(%rbx),%rsi
mov    0x10(%rbx),%rdi
call   1060 <execvp@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rbx),%rbx
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe9e(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, double }
%struct.TYPE_3__ = type { i64, i64 }
@stderr = global i32 0
@.str = [225 x i8] c"setitimer-helper: runs a program with a virtual CPU limit\0Ausage: %s TIMEOUT PROGRAM [ARG...]\0A where TIMEOUT is the virtual CPU limit, in seconds,\0A and remaining arguments specify the program to run\0A and its argument.\0A\00"
@EXIT_FAILURE = global i32 0
@LONG_MAX = global double 0.000000e+00
@ITIMER_VIRTUAL = global i32 0
@.str.1 = [19 x i8] c"%s: setitimer: %s\0A\00"
@errno = global i32 0
@.str.2 = [32 x i8] c"%s: invalid timeout value \22%s\22\0A\00"
@.str.3 = [28 x i8] c"%s: couldn't exec \22%s\22: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca double
%8 = alloca %struct.itimerval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
store i8* %11, i8** %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %6
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %78
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call double @strtod(i8* %22, i32* null)
store double %23, double* %7
%24 = load double, double* %7
%25 = fcmp oge double %24, 0.000000e+00
br i1 %25, label %26, label %55
26: ; preds = %19
%27 = load double, double* %7
%28 = load double, double* @LONG_MAX
%29 = fcmp olt double %27, %28
br i1 %29, label %30, label %55
30: ; preds = %26
%31 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %8, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %8, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 0
store i64 0, i64* %34
%35 = load double, double* %7
%36 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %8, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 0
store double %35, double* %37
%38 = load double, double* %7
%39 = load double, double* %7
%40 = call double @llvm.floor.f64(double %39)
%41 = fsub double %38, %40
%42 = fmul double %41, 1.000000e+06
%43 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %8, i32 0, i32 0
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %43, i32 0, i32 1
store double %42, double* %44
%45 = load i32, i32* @ITIMER_VIRTUAL
%46 = call i64 @setitimer(i32 %45, %struct.itimerval* %8, i32* null)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %30
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %6
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %52)
br label %54
54: ; preds = %48, %30
br label %62
55: ; preds = %26, %19
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %6
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* %60)
br label %62
62: ; preds = %55, %54
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = call i32 @execvp(i8* %65, i8** %67)
%69 = load i32, i32* @stderr
%70 = load i8*, i8** %6
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %70, i8* %73, i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
store i32 %77, i32* %3
br label %78
78: ; preds = %62, %14
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { double, double }
%struct.TYPE_3__ = type { i64, i64 }
@stderr = global i32 0
@.str = [225 x i8] c"setitimer-helper: runs a program with a virtual CPU limit\0Ausage: %s TIMEOUT PROGRAM [ARG...]\0A where TIMEOUT is the virtual CPU limit, in seconds,\0A and remaining arguments specify the program to run\0A and its argument.\0A\00"
@EXIT_FAILURE = global i32 0
@LONG_MAX = global double 0.000000e+00
@ITIMER_VIRTUAL = global i32 0
@.str.1 = [19 x i8] c"%s: setitimer: %s\0A\00"
@errno = global i32 0
@.str.2 = [32 x i8] c"%s: invalid timeout value \22%s\22\0A\00"
@.str.3 = [28 x i8] c"%s: couldn't exec \22%s\22: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.itimerval
%4 = load i8*, i8** %1
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %48
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call double @strtod(i8* nocapture %11, i32* null)
%13 = fcmp oge double %12, 0.000000e+00
%14 = load double, double* @LONG_MAX
%15 = fcmp olt double %12, %14
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %35
17: ; preds = %9
%18 = bitcast %struct.itimerval* %3 to i8*
%19 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 1, i32 0
%20 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 0
%21 = bitcast i64* %19 to i8*
store double %12, double* %20
%22 = tail call double @llvm.floor.f64(double %12)
%23 = fsub double %12, %22
%24 = fmul double %23, 1.000000e+06
%25 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %3, i64 0, i32 0, i32 1
store double %24, double* %25
%26 = load i32, i32* @ITIMER_VIRTUAL
%27 = call i64 @setitimer(i32 %26, %struct.itimerval* %3, i32* null)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %32)
br label %34
34: ; preds = %29, %17
br label %39
35: ; preds = %9
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %37)
br label %39
39: ; preds = %35, %34
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = tail call i32 @execvp(i8* %41, i8** %40)
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %40
%45 = load i32, i32* @errno
%46 = tail call i8* @strerror(i32 %45)
%47 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %44, i8* %46)
br label %48
48: ; preds = %39, %6
%49 = load i32, i32* @EXIT_FAILURE
ret i32 %49
}