#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 */
struct tms {
  double tms_cutime;
  double tms_cstime;
};
struct rlimit {
  long rlim_cur;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ RLIMIT_CPU;
int /*<<< orphan*/ SIGTERM;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ _SC_CLK_TCK;
long atol(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strncmp(char *, char *, int);
double sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ times(struct tms *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  long timelimit, memlimit;
  int showtime, hidetime;
  struct rlimit res;
  showtime = argc >= 4 && !strncmp("-s", argv[3], 3);
  hidetime = argc >= 4 && !strncmp("-h", argv[3], 3);
  if (argc < 5 || !(showtime || hidetime)) {
    fprintf(stderr,
            "usage: %s <time limit in seconds> <virtual memory limit in MiB>\n"
            "          <show/hide cpu time: -s|-h> <command> <args>...\n\n"
            "Zero sets no limit (keeps the actual limit)\n",
            argv[0]);
    return EXIT_FAILURE;
  }
  if (showtime) {
    int pid = fork();
    if (pid == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (pid > 0) {
      int status;
      struct tms tms;
      double time;
      waitpid(pid, &status, 0);
      times(&tms);
      time = (double)((tms.tms_cutime + tms.tms_cstime + 0.0) /
                      sysconf(_SC_CLK_TCK));
      fprintf(stdout, "why3cpulimit time : %f s\n", time);
      fflush(stdout);
      if (WIFEXITED(status))
        return WEXITSTATUS(status);
      kill(getpid(), SIGTERM);
    }
  }
  timelimit = atol(argv[1]);
  if (timelimit > 0) {
    getrlimit(RLIMIT_CPU, &res);
    res.rlim_cur = timelimit;
    setrlimit(RLIMIT_CPU, &res);
  }
  memlimit = atol(argv[2]);
  if (memlimit > 0) {
    getrlimit(RLIMIT_AS, &res);
    res.rlim_cur = memlimit * 1024 * 1024;
    setrlimit(RLIMIT_AS, &res);
  }
  if (timelimit > 0 || memlimit > 0) {
    getrlimit(RLIMIT_CORE, &res);
    res.rlim_cur = 0;
    setrlimit(RLIMIT_CORE, &res);
  }
  execvp(argv[4], argv + 4);
  fprintf(stderr, "%s: exec of '%s' failed (%s)\n", argv[0], argv[4],
          strerror(errno));
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x4,-0x8(%rbp)
mov    %al,-0x51(%rbp)
jl     126c <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xda9(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x4,-0x8(%rbp)
mov    %al,-0x52(%rbp)
jl     12aa <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x52(%rbp)
mov    -0x52(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x5,-0x8(%rbp)
jl     12d3 <main+0xb3>
cmpl   $0x0,-0x24(%rbp)
jne    1302 <main+0xe2>
cmpl   $0x0,-0x28(%rbp)
jne    1302 <main+0xe2>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1540 <main+0x320>
cmpl   $0x0,-0x24(%rbp)
je     13f8 <main+0x1d8>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    133a <main+0x11a>
lea    0xd87(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
jle    13f3 <main+0x1d3>
mov    -0x34(%rbp),%edi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
lea    -0x48(%rbp),%rdi
call   10c0 <times@plt>
movsd  -0x48(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
movsd  -0x50(%rbp),%xmm0
lea    0xd0e(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x38(%rbp),%edi
call   1100 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13dc <main+0x1bc>
mov    -0x38(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    1540 <main+0x320>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
mov    0x2bfc(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    13f8 <main+0x1d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    1440 <main+0x220>
mov    0x2b7d(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1120 <getrlimit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2b63(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1080 <setrlimit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    1490 <main+0x270>
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1120 <getrlimit@plt>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x30(%rbp)
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1080 <setrlimit@plt>
cmpq   $0x0,-0x18(%rbp)
jg     14a6 <main+0x286>
cmpq   $0x0,-0x20(%rbp)
jle    14d2 <main+0x2b2>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1120 <getrlimit@plt>
movq   $0x0,-0x30(%rbp)
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1080 <setrlimit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x20,%rsi
call   10f0 <execvp@plt>
mov    0x2ada(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x68(%rbp)
mov    0x2aaf(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    %rax,%r8
lea    0xba0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2a75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jl     126d <main+0x4d>
mov    %edi,%ebp
mov    0x18(%r14),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
mov    %eax,%ebx
mov    0x18(%r14),%rsi
lea    0xdad(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x4,%ebp
je     126d <main+0x4d>
test   %ebx,%ebx
je     129b <main+0x7b>
test   %eax,%eax
je     129b <main+0x7b>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd86(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebx,%ebx
je     12f5 <main+0xd5>
mov    0x8(%r14),%rdi
call   10b0 <atol@plt>
test   %rax,%rax
jle    1395 <main+0x175>
mov    %rax,%rbx
mov    0x2cdd(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1120 <getrlimit@plt>
mov    %rbx,0x10(%rsp)
mov    (%r15),%edi
mov    %rbp,%rsi
call   1080 <setrlimit@plt>
mov    0x10(%r14),%rdi
call   10b0 <atol@plt>
mov    %rax,%rbp
test   %rax,%rax
jg     13a6 <main+0x186>
jmp    13d1 <main+0x1b1>
xor    %eax,%eax
call   1140 <fork@plt>
cmp    $0xffffffff,%eax
je     1461 <main+0x241>
test   %eax,%eax
jle    129f <main+0x7f>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
lea    0x10(%rsp),%rdi
call   10c0 <times@plt>
movsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
movsd  0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
mov    0x2c4e(%rip),%rbx
mov    (%rbx),%edi
lea    0xd50(%rip),%rsi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
mov    0xc(%rsp),%edi
call   1100 <WIFEXITED@plt>
test   %rax,%rax
je     1445 <main+0x225>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
jmp    1290 <main+0x70>
mov    0x10(%r14),%rdi
call   10b0 <atol@plt>
mov    %rax,%rbp
test   %rax,%rax
jle    13fc <main+0x1dc>
mov    0x2c0b(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1120 <getrlimit@plt>
shl    $0x14,%rbp
mov    %rbp,0x10(%rsp)
mov    (%r15),%edi
mov    %rbx,%rsi
call   1080 <setrlimit@plt>
mov    0x2c08(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1120 <getrlimit@plt>
movq   $0x0,0x10(%rsp)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1080 <setrlimit@plt>
lea    0x20(%r14),%rsi
mov    0x20(%r14),%rdi
call   10f0 <execvp@plt>
mov    0x2bb8(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x20(%r14),%r14
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xc9f(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1287 <main+0x67>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x2b95(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1060 <kill@plt>
jmp    129f <main+0x7f>
lea    0xc46(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i64 }
%struct.tms = type { double, double }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.2 = [168 x i8] c"usage: %s <time limit in seconds> <virtual memory limit in MiB>\0A <show/hide cpu time: -s|-h> <command> <args>...\0A\0AZero sets no limit (keeps the actual limit)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@_SC_CLK_TCK = global i32 0
@stdout = global i32 0
@.str.4 = [26 x i8] c"why3cpulimit time : %f s\0A\00"
@SIGTERM = global i32 0
@RLIMIT_CPU = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_CORE = global i32 0
@.str.5 = [30 x i8] c"%s: exec of '%s' failed (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.rlimit
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.tms
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 4
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 3
%20 = load i8*, i8** %19
%21 = call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20, i32 3)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br label %24
24: ; preds = %17, %2
%25 = phi i1 [ false, %2 ], [ %23, %17 ]
%26 = zext i1 %25 to i32
store i32 %26, i32* %8
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 4
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 3)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
br label %36
36: ; preds = %29, %24
%37 = phi i1 [ false, %24 ], [ %35, %29 ]
%38 = zext i1 %37 to i32
store i32 %38, i32* %9
%39 = load i32, i32* %4
%40 = icmp slt i32 %39, 5
br i1 %40, label %47, label %41
41: ; preds = %36
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %54, label %44
44: ; preds = %41
%45 = load i32, i32* %9
%46 = icmp ne i32 %45, 0
br i1 %46, label %54, label %47
47: ; preds = %44, %36
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
store i32 %53, i32* %3
br label %157
54: ; preds = %44, %41
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %97
57: ; preds = %54
%58 = call i32 (...) @fork()
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %57
%66 = load i32, i32* %11
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %96
68: ; preds = %65
%69 = load i32, i32* %11
%70 = call i32 @waitpid(i32 %69, i32* %12, i32 0)
%71 = call i32 @times(%struct.tms* %13)
%72 = getelementptr inbounds %struct.tms, %struct.tms* %13, i32 0, i32 0
%73 = load double, double* %72
%74 = getelementptr inbounds %struct.tms, %struct.tms* %13, i32 0, i32 1
%75 = load double, double* %74
%76 = fadd double %73, %75
%77 = fadd double %76, 0.000000e+00
%78 = load i32, i32* @_SC_CLK_TCK
%79 = call double @sysconf(i32 %78)
%80 = fdiv double %77, %79
store double %80, double* %14
%81 = load i32, i32* @stdout
%82 = load double, double* %14
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %82)
%84 = load i32, i32* @stdout
%85 = call i32 @fflush(i32 %84)
%86 = load i32, i32* %12
%87 = call i64 @WIFEXITED(i32 %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %68
%90 = load i32, i32* %12
%91 = call i32 @WEXITSTATUS(i32 %90)
store i32 %91, i32* %3
br label %157
92: ; preds = %68
%93 = call i32 (...) @getpid()
%94 = load i32, i32* @SIGTERM
%95 = call i32 @kill(i32 %93, i32 %94)
br label %96
96: ; preds = %92, %65
br label %97
97: ; preds = %96, %54
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 1
%100 = load i8*, i8** %99
%101 = call i64 @atol(i8* %100)
store i64 %101, i64* %6
%102 = load i64, i64* %6
%103 = icmp sgt i64 %102, 0
br i1 %103, label %104, label %111
104: ; preds = %97
%105 = load i32, i32* @RLIMIT_CPU
%106 = call i32 @getrlimit(i32 %105, %struct.rlimit* %10)
%107 = load i64, i64* %6
%108 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
store i64 %107, i64* %108
%109 = load i32, i32* @RLIMIT_CPU
%110 = call i32 @setrlimit(i32 %109, %struct.rlimit* %10)
br label %111
111: ; preds = %104, %97
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 2
%114 = load i8*, i8** %113
%115 = call i64 @atol(i8* %114)
store i64 %115, i64* %7
%116 = load i64, i64* %7
%117 = icmp sgt i64 %116, 0
br i1 %117, label %118, label %127
118: ; preds = %111
%119 = load i32, i32* @RLIMIT_AS
%120 = call i32 @getrlimit(i32 %119, %struct.rlimit* %10)
%121 = load i64, i64* %7
%122 = mul nsw i64 %121, 1024
%123 = mul nsw i64 %122, 1024
%124 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
store i64 %123, i64* %124
%125 = load i32, i32* @RLIMIT_AS
%126 = call i32 @setrlimit(i32 %125, %struct.rlimit* %10)
br label %127
127: ; preds = %118, %111
%128 = load i64, i64* %6
%129 = icmp sgt i64 %128, 0
br i1 %129, label %133, label %130
130: ; preds = %127
%131 = load i64, i64* %7
%132 = icmp sgt i64 %131, 0
br i1 %132, label %133, label %139
133: ; preds = %130, %127
%134 = load i32, i32* @RLIMIT_CORE
%135 = call i32 @getrlimit(i32 %134, %struct.rlimit* %10)
%136 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
store i64 0, i64* %136
%137 = load i32, i32* @RLIMIT_CORE
%138 = call i32 @setrlimit(i32 %137, %struct.rlimit* %10)
br label %139
139: ; preds = %133, %130
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 4
%142 = load i8*, i8** %141
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 4
%145 = call i32 @execvp(i8* %142, i8** %144)
%146 = load i32, i32* @stderr
%147 = load i8**, i8*** %5
%148 = getelementptr inbounds i8*, i8** %147, i64 0
%149 = load i8*, i8** %148
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 4
%152 = load i8*, i8** %151
%153 = load i32, i32* @errno
%154 = call i8* @strerror(i32 %153)
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %149, i8* %152, i8* %154)
%156 = load i32, i32* @EXIT_FAILURE
store i32 %156, i32* %3
br label %157
157: ; preds = %139, %89, %47
%158 = load i32, i32* %3
ret i32 %158
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
%struct.tms = type { double, double }
@.str = [3 x i8] c"-s\00"
@.str.1 = [3 x i8] c"-h\00"
@stderr = global i32 0
@.str.2 = [168 x i8] c"usage: %s <time limit in seconds> <virtual memory limit in MiB>\0A <show/hide cpu time: -s|-h> <command> <args>...\0A\0AZero sets no limit (keeps the actual limit)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@_SC_CLK_TCK = global i32 0
@stdout = global i32 0
@.str.4 = [26 x i8] c"why3cpulimit time : %f s\0A\00"
@SIGTERM = global i32 0
@RLIMIT_CPU = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_CORE = global i32 0
@.str.5 = [30 x i8] c"%s: exec of '%s' failed (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.rlimit
%4 = alloca i32
%5 = alloca %struct.tms
%6 = bitcast %struct.rlimit* %3 to i8*
%7 = icmp sgt i32 %0, 3
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10, i32 3)
%12 = icmp eq i32 %11, 0
%13 = load i8*, i8** %9
%14 = tail call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 3)
%15 = icmp eq i32 %0, 4
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = icmp eq i32 %14, 0
%18 = select i1 %12, i1 true, i1 %17
br i1 %18, label %24, label %19
19: ; preds = %2, %16, %8
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([168 x i8], [168 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
br label %107
24: ; preds = %16
br i1 %12, label %25, label %62
25: ; preds = %24
%26 = tail call i32 (...) @fork()
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %25
%33 = icmp sgt i32 %26, 0
br i1 %33, label %34, label %62
34: ; preds = %32
%35 = bitcast i32* %4 to i8*
%36 = bitcast %struct.tms* %5 to i8*
%37 = call i32 @waitpid(i32 %26, i32* %4, i32 0)
%38 = call i32 @times(%struct.tms* %5)
%39 = getelementptr inbounds %struct.tms, %struct.tms* %5, i64 0, i32 0
%40 = load double, double* %39
%41 = getelementptr inbounds %struct.tms, %struct.tms* %5, i64 0, i32 1
%42 = load double, double* %41
%43 = fadd double %40, %42
%44 = fadd double %43, 0.000000e+00
%45 = load i32, i32* @_SC_CLK_TCK
%46 = call double @sysconf(i32 %45)
%47 = fdiv double %44, %46
%48 = load i32, i32* @stdout
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), double %47)
%50 = load i32, i32* @stdout
%51 = call i32 @fflush(i32 %50)
%52 = load i32, i32* %4
%53 = call i64 @WIFEXITED(i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %34
%56 = call i32 (...) @getpid()
%57 = load i32, i32* @SIGTERM
%58 = call i32 @kill(i32 %56, i32 %57)
br label %62
59: ; preds = %34
%60 = load i32, i32* %4
%61 = call i32 @WEXITSTATUS(i32 %60)
br label %107
62: ; preds = %32, %55, %24
%63 = getelementptr inbounds i8*, i8** %1, i64 1
%64 = load i8*, i8** %63
%65 = call i64 @atol(i8* %64)
%66 = icmp sgt i64 %65, 0
br i1 %66, label %67, label %77
67: ; preds = %62
%68 = load i32, i32* @RLIMIT_CPU
%69 = call i32 @getrlimit(i32 %68, %struct.rlimit* %3)
%70 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i64 %65, i64* %70
%71 = load i32, i32* @RLIMIT_CPU
%72 = call i32 @setrlimit(i32 %71, %struct.rlimit* %3)
%73 = getelementptr inbounds i8*, i8** %1, i64 2
%74 = load i8*, i8** %73
%75 = call i64 @atol(i8* %74)
%76 = icmp sgt i64 %75, 0
br i1 %76, label %82, label %90
77: ; preds = %62
%78 = getelementptr inbounds i8*, i8** %1, i64 2
%79 = load i8*, i8** %78
%80 = call i64 @atol(i8* %79)
%81 = icmp sgt i64 %80, 0
br i1 %81, label %82, label %96
82: ; preds = %77, %67
%83 = phi i64 [ %80, %77 ], [ %75, %67 ]
%84 = load i32, i32* @RLIMIT_AS
%85 = call i32 @getrlimit(i32 %84, %struct.rlimit* %3)
%86 = shl nsw i64 %83, 20
%87 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i64 %86, i64* %87
%88 = load i32, i32* @RLIMIT_AS
%89 = call i32 @setrlimit(i32 %88, %struct.rlimit* %3)
br label %90
90: ; preds = %67, %82
%91 = load i32, i32* @RLIMIT_CORE
%92 = call i32 @getrlimit(i32 %91, %struct.rlimit* %3)
%93 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i64 0, i64* %93
%94 = load i32, i32* @RLIMIT_CORE
%95 = call i32 @setrlimit(i32 %94, %struct.rlimit* %3)
br label %96
96: ; preds = %77, %90
%97 = getelementptr inbounds i8*, i8** %1, i64 4
%98 = load i8*, i8** %97
%99 = call i32 @execvp(i8* %98, i8** %97)
%100 = load i32, i32* @stderr
%101 = load i8*, i8** %1
%102 = load i8*, i8** %97
%103 = load i32, i32* @errno
%104 = call i8* @strerror(i32 %103)
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %101, i8* %102, i8* %104)
%106 = load i32, i32* @EXIT_FAILURE
br label %107
107: ; preds = %59, %96, %19
%108 = phi i32 [ %23, %19 ], [ %106, %96 ], [ %61, %59 ]
ret i32 %108
}