#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 timeval {
  int tv_sec;
  int tv_usec;
};
struct rlimit {
  int rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ RLIMIT_CPU;
int /*<<< orphan*/ RLIMIT_FSIZE;
int /*<<< orphan*/ RLIMIT_NOFILE;
int /*<<< orphan*/ SIGKILL;
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ execl(char *, char *, char *, char *, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ killpg(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i;
  int child;
  int status;
  int tle;
  struct rlimit cpu, mem, file, fcnt;
  int wall;
  struct timeval start_time, current_time;
  char *cmd;
  int sec, usec;
  wall = 180;
  cpu.rlim_cur = 60;
  mem.rlim_cur = 512;
  file.rlim_cur = 1 << 14;
  fcnt.rlim_cur = fcnt.rlim_max = 128;
  if (!(argc & 1))
    usage();
  cmd = NULL;
  for (i = 1; i + 1 < argc; i += 2) {
    if (!strcmp("-m", argv[i]))
      sscanf(argv[i + 1], "%d", &mem.rlim_cur);
    else if (!strcmp("-c", argv[i]))
      sscanf(argv[i + 1], "%d", &cpu.rlim_cur);
    else if (!strcmp("-w", argv[i]))
      sscanf(argv[i + 1], "%d", &wall);
    else if (!strcmp("-f", argv[i]))
      sscanf(argv[i + 1], "%d", &file.rlim_cur);
    else if (!strcmp("-x", argv[i]))
      cmd = argv[i + 1];
    else
      usage();
  }
  if (cmd == NULL)
    usage();
  if (wall > cpu.rlim_cur)
    wall = cpu.rlim_cur;
  mem.rlim_cur <<= 20;
  file.rlim_cur <<= 10;
  cpu.rlim_max = cpu.rlim_cur;
  mem.rlim_max = mem.rlim_cur;
  file.rlim_max = file.rlim_cur;
  setrlimit(RLIMIT_CPU, &cpu);
  setrlimit(RLIMIT_AS, &mem);
  setrlimit(RLIMIT_FSIZE, &file);
  setrlimit(RLIMIT_NOFILE, &fcnt);
  child = fork();
  if (child == -1) {
    fprintf(stderr, "can't fork.");
    return 2;
  }
  if (child == 0) {
    setsid();
    execl("/bin/sh", "sh", "-c", cmd, (char *)0);
    perror("Can't execute");
    return 3;
  }
  gettimeofday(&start_time, NULL);
  while (!waitpid(child, &status, WNOHANG)) {
    usleep(25000);
    gettimeofday(&current_time, NULL);
    sec = current_time.tv_sec - start_time.tv_sec;
    usec = current_time.tv_usec - start_time.tv_usec;
    if (sec > wall || (sec == wall && usec > 0)) {
      fprintf(stderr, "Hanged\n");
      if (killpg(child, SIGKILL))
        fprintf(stderr, "Failed to kill");
    }
    usleep(50000);
  }
  if (WIFSIGNALED(status))
    return 4;
  return 0;
}


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)
movl   $0xb4,-0x44(%rbp)
movl   $0x3c,-0x28(%rbp)
movl   $0x200,-0x30(%rbp)
movl   $0x4000,-0x38(%rbp)
movl   $0x80,-0x3c(%rbp)
movl   $0x80,-0x40(%rbp)
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1236 <main+0x56>
mov    $0x0,%al
call   10b0 <usage@plt>
movq   $0x0,-0x60(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    13d9 <main+0x1f9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd99(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    129b <main+0xbb>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x30(%rbp),%rdx
lea    0xd72(%rip),%rsi
call   1090 <sscanf@plt>
jmp    13c6 <main+0x1e6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd58(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12e2 <main+0x102>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x28(%rbp),%rdx
lea    0xd2b(%rip),%rsi
call   1090 <sscanf@plt>
jmp    13c1 <main+0x1e1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd14(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1329 <main+0x149>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xce8(%rip),%rsi
lea    -0x44(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    13bc <main+0x1dc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcd0(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1370 <main+0x190>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x38(%rbp),%rdx
lea    0xc9d(%rip),%rsi
call   1090 <sscanf@plt>
jmp    13b7 <main+0x1d7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc8c(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    13ab <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x60(%rbp)
jmp    13b2 <main+0x1d2>
mov    $0x0,%al
call   10b0 <usage@plt>
jmp    13b7 <main+0x1d7>
jmp    13bc <main+0x1dc>
jmp    13c1 <main+0x1e1>
jmp    13c6 <main+0x1e6>
jmp    13cb <main+0x1eb>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1245 <main+0x65>
cmpq   $0x0,-0x60(%rbp)
jne    13eb <main+0x20b>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    -0x44(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    13fd <main+0x21d>
mov    -0x28(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x30(%rbp)
mov    -0x38(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   10a0 <setrlimit@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    149e <main+0x2be>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
lea    0xb85(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    15ea <main+0x40a>
cmpl   $0x0,-0x18(%rbp)
jne    14ea <main+0x30a>
mov    $0x0,%al
call   1040 <setsid@plt>
mov    -0x60(%rbp),%rcx
lea    0xb64(%rip),%rdi
lea    0xb62(%rip),%rsi
lea    0xb3e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   10e0 <execl@plt>
lea    0xb4d(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    15ea <main+0x40a>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%edi
mov    0x2adf(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rsi
call   10c0 <waitpid@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1521 <main+0x341>
jmp    15c5 <main+0x3e5>
mov    $0x61a8,%edi
call   1100 <usleep@plt>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x58(%rbp),%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x54(%rbp),%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     156c <main+0x38c>
mov    -0x64(%rbp),%eax
cmp    -0x44(%rbp),%eax
jne    15b6 <main+0x3d6>
cmpl   $0x0,-0x68(%rbp)
jle    15b6 <main+0x3d6>
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
lea    0xab8(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%edi
mov    0x2a35(%rip),%rax
mov    (%rax),%esi
call   1080 <killpg@plt>
cmp    $0x0,%rax
je     15b1 <main+0x3d1>
mov    0x2a2d(%rip),%rax
mov    (%rax),%edi
lea    0xa90(%rip),%rsi
call   1070 <fprintf@plt>
jmp    15b6 <main+0x3d6>
mov    $0xc350,%edi
call   1100 <usleep@plt>
jmp    14f7 <main+0x317>
mov    -0x1c(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     15e3 <main+0x403>
movl   $0x4,-0x4(%rbp)
jmp    15ea <main+0x40a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0xb4,0x4(%rsp)
movl   $0x3c,0x28(%rsp)
movl   $0x200,0x10(%rsp)
movl   $0x4000,0x8(%rsp)
movabs $0x8000000080,%rax
mov    %rax,0x40(%rsp)
test   $0x1,%bpl
jne    122f <main+0x4f>
xor    %eax,%eax
call   10b0 <usage@plt>
cmp    $0x3,%ebp
jl     133b <main+0x15b>
mov    $0x2,%r14d
lea    0xdbb(%rip),%r15
lea    0xdb7(%rip),%r12
xor    %eax,%eax
mov    %rax,0x20(%rsp)
jmp    127e <main+0x9e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
lea    0x10(%rsp),%rdx
call   1090 <sscanf@plt>
add    $0x2,%r14
cmp    %ebp,%r14d
jge    1331 <main+0x151>
mov    -0x8(%rbx,%r14,8),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1260 <main+0x80>
lea    0xd6d(%rip),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12f0 <main+0x110>
lea    0xd5d(%rip),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1301 <main+0x121>
lea    0xd4d(%rip),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1312 <main+0x132>
lea    0xd3d(%rip),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1323 <main+0x143>
xor    %eax,%eax
call   10b0 <usage@plt>
jmp    1271 <main+0x91>
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
lea    0x28(%rsp),%rdx
jmp    126c <main+0x8c>
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
lea    0x4(%rsp),%rdx
jmp    126c <main+0x8c>
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
lea    0x8(%rsp),%rdx
jmp    126c <main+0x8c>
mov    (%rbx,%r14,8),%rax
mov    %rax,0x20(%rsp)
jmp    1271 <main+0x91>
mov    0x20(%rsp),%rbp
test   %rbp,%rbp
jne    1344 <main+0x164>
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <usage@plt>
mov    0x28(%rsp),%eax
cmp    %eax,0x4(%rsp)
jle    1352 <main+0x172>
mov    %eax,0x4(%rsp)
mov    0x10(%rsp),%ecx
shl    $0x14,%ecx
mov    %ecx,0x10(%rsp)
mov    0x8(%rsp),%edx
shl    $0xa,%edx
mov    %edx,0x8(%rsp)
mov    %eax,0x2c(%rsp)
mov    %ecx,0x14(%rsp)
mov    %edx,0xc(%rsp)
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0x28(%rsp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   10a0 <setrlimit@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%edi
lea    0x40(%rsp),%rsi
call   10a0 <setrlimit@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     1416 <main+0x236>
mov    %eax,%ebx
test   %eax,%eax
je     14de <main+0x2fe>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2bf7(%rip),%r13
mov    0x0(%r13),%edx
lea    0x1c(%rsp),%rsi
mov    %ebx,%edi
call   10c0 <waitpid@plt>
test   %eax,%eax
je     143f <main+0x25f>
mov    0x1c(%rsp),%edi
call   1050 <WIFSIGNALED@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
shl    $0x2,%eax
jmp    1430 <main+0x250>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    0xbec(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x38(%rsp),%r15d
mov    0x3c(%rsp),%eax
mov    %eax,0x20(%rsp)
lea    0x30(%rsp),%r12
mov    0x2b78(%rip),%r14
lea    0x1c(%rsp),%rbp
jmp    147c <main+0x29c>
nop
mov    $0xc350,%edi
call   1100 <usleep@plt>
mov    0x0(%r13),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   10c0 <waitpid@plt>
test   %eax,%eax
jne    13fd <main+0x21d>
mov    $0x61a8,%edi
call   1100 <usleep@plt>
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x30(%rsp),%eax
sub    %r15d,%eax
cmp    0x4(%rsp),%eax
jg     14a9 <main+0x2c9>
jne    1460 <main+0x280>
mov    0x20(%rsp),%eax
cmp    %eax,0x34(%rsp)
jle    1460 <main+0x280>
mov    (%r14),%edi
lea    0xb81(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2b01(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1080 <killpg@plt>
test   %rax,%rax
je     1460 <main+0x280>
mov    (%r14),%edi
lea    0xb65(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1460 <main+0x280>
xor    %eax,%eax
call   1040 <setsid@plt>
lea    0xb32(%rip),%rdi
lea    0xb30(%rip),%rsi
lea    0xb0c(%rip),%rdx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   10e0 <execl@plt>
lea    0xb1a(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x3,%eax
jmp    1430 <main+0x250>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"-m\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [3 x i8] c"-w\00"
@.str.4 = [3 x i8] c"-f\00"
@.str.5 = [3 x i8] c"-x\00"
@RLIMIT_CPU = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_FSIZE = global i32 0
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str.6 = [12 x i8] c"can't fork.\00"
@.str.7 = [8 x i8] c"/bin/sh\00"
@.str.8 = [3 x i8] c"sh\00"
@.str.9 = [14 x i8] c"Can't execute\00"
@WNOHANG = global i32 0
@.str.10 = [8 x i8] c"Hanged\0A\00"
@SIGKILL = global i32 0
@.str.11 = [15 x i8] c"Failed to kill\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.rlimit
%11 = alloca %struct.rlimit
%12 = alloca %struct.rlimit
%13 = alloca %struct.rlimit
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca %struct.timeval
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 180, i32* %14
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
store i32 60, i32* %20
%21 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 0
store i32 512, i32* %21
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
store i32 16384, i32* %22
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %13, i32 0, i32 1
store i32 128, i32* %23
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %13, i32 0, i32 0
store i32 128, i32* %24
%25 = load i32, i32* %4
%26 = and i32 %25, 1
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %2
%29 = call i32 (...) @usage()
br label %30
30: ; preds = %28, %2
store i8* null, i8** %17
store i32 1, i32* %6
br label %31
31: ; preds = %125, %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %128
36: ; preds = %31
%37 = load i8**, i8*** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %53, label %44
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
%50 = load i8*, i8** %49
%51 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 0
%52 = call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %51)
br label %124
53: ; preds = %36
%54 = load i8**, i8*** %5
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %70, label %61
61: ; preds = %53
%62 = load i8**, i8*** %5
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %62, i64 %65
%67 = load i8*, i8** %66
%68 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%69 = call i32 @sscanf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %68)
br label %123
70: ; preds = %53
%71 = load i8**, i8*** %5
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %86, label %78
78: ; preds = %70
%79 = load i8**, i8*** %5
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8*, i8** %79, i64 %82
%84 = load i8*, i8** %83
%85 = call i32 @sscanf(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
br label %122
86: ; preds = %70
%87 = load i8**, i8*** %5
%88 = load i32, i32* %6
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
%91 = load i8*, i8** %90
%92 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %91)
%93 = icmp ne i32 %92, 0
br i1 %93, label %103, label %94
94: ; preds = %86
%95 = load i8**, i8*** %5
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %95, i64 %98
%100 = load i8*, i8** %99
%101 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
%102 = call i32 @sscanf(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %101)
br label %121
103: ; preds = %86
%104 = load i8**, i8*** %5
%105 = load i32, i32* %6
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8*, i8** %104, i64 %106
%108 = load i8*, i8** %107
%109 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %108)
%110 = icmp ne i32 %109, 0
br i1 %110, label %118, label %111
111: ; preds = %103
%112 = load i8**, i8*** %5
%113 = load i32, i32* %6
%114 = add nsw i32 %113, 1
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8*, i8** %112, i64 %115
%117 = load i8*, i8** %116
store i8* %117, i8** %17
br label %120
118: ; preds = %103
%119 = call i32 (...) @usage()
br label %120
120: ; preds = %118, %111
br label %121
121: ; preds = %120, %94
br label %122
122: ; preds = %121, %78
br label %123
123: ; preds = %122, %61
br label %124
124: ; preds = %123, %44
br label %125
125: ; preds = %124
%126 = load i32, i32* %6
%127 = add nsw i32 %126, 2
store i32 %127, i32* %6
br label %31
128: ; preds = %31
%129 = load i8*, i8** %17
%130 = icmp eq i8* %129, null
br i1 %130, label %131, label %133
131: ; preds = %128
%132 = call i32 (...) @usage()
br label %133
133: ; preds = %131, %128
%134 = load i32, i32* %14
%135 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%136 = load i32, i32* %135
%137 = icmp sgt i32 %134, %136
br i1 %137, label %138, label %141
138: ; preds = %133
%139 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%140 = load i32, i32* %139
store i32 %140, i32* %14
br label %141
141: ; preds = %138, %133
%142 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 0
%143 = load i32, i32* %142
%144 = shl i32 %143, 20
store i32 %144, i32* %142
%145 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
%146 = load i32, i32* %145
%147 = shl i32 %146, 10
store i32 %147, i32* %145
%148 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 0
%149 = load i32, i32* %148
%150 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i32 0, i32 1
store i32 %149, i32* %150
%151 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 0
%152 = load i32, i32* %151
%153 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 1
store i32 %152, i32* %153
%154 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 0
%155 = load i32, i32* %154
%156 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 1
store i32 %155, i32* %156
%157 = load i32, i32* @RLIMIT_CPU
%158 = call i32 @setrlimit(i32 %157, %struct.rlimit* %10)
%159 = load i32, i32* @RLIMIT_AS
%160 = call i32 @setrlimit(i32 %159, %struct.rlimit* %11)
%161 = load i32, i32* @RLIMIT_FSIZE
%162 = call i32 @setrlimit(i32 %161, %struct.rlimit* %12)
%163 = load i32, i32* @RLIMIT_NOFILE
%164 = call i32 @setrlimit(i32 %163, %struct.rlimit* %13)
%165 = call i32 (...) @fork()
store i32 %165, i32* %7
%166 = load i32, i32* %7
%167 = icmp eq i32 %166, -1
br i1 %167, label %168, label %171
168: ; preds = %141
%169 = load i32, i32* @stderr
%170 = call i32 @fprintf(i32 %169, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %229
171: ; preds = %141
%172 = load i32, i32* %7
%173 = icmp eq i32 %172, 0
br i1 %173, label %174, label %179
174: ; preds = %171
%175 = call i32 (...) @setsid()
%176 = load i8*, i8** %17
%177 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %176, i8* null)
%178 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 3, i32* %3
br label %229
179: ; preds = %171
%180 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
br label %181
181: ; preds = %221, %179
%182 = load i32, i32* %7
%183 = load i32, i32* @WNOHANG
%184 = call i32 @waitpid(i32 %182, i32* %8, i32 %183)
%185 = icmp ne i32 %184, 0
%186 = xor i1 %185, true
br i1 %186, label %187, label %223
187: ; preds = %181
%188 = call i32 @usleep(i32 25000)
%189 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%190 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%191 = load i32, i32* %190
%192 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%193 = load i32, i32* %192
%194 = sub nsw i32 %191, %193
store i32 %194, i32* %18
%195 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%196 = load i32, i32* %195
%197 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%198 = load i32, i32* %197
%199 = sub nsw i32 %196, %198
store i32 %199, i32* %19
%200 = load i32, i32* %18
%201 = load i32, i32* %14
%202 = icmp sgt i32 %200, %201
br i1 %202, label %210, label %203
203: ; preds = %187
%204 = load i32, i32* %18
%205 = load i32, i32* %14
%206 = icmp eq i32 %204, %205
br i1 %206, label %207, label %221
207: ; preds = %203
%208 = load i32, i32* %19
%209 = icmp sgt i32 %208, 0
br i1 %209, label %210, label %221
210: ; preds = %207, %187
%211 = load i32, i32* @stderr
%212 = call i32 @fprintf(i32 %211, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%213 = load i32, i32* %7
%214 = load i32, i32* @SIGKILL
%215 = call i64 @killpg(i32 %213, i32 %214)
%216 = icmp ne i64 %215, 0
br i1 %216, label %217, label %220
217: ; preds = %210
%218 = load i32, i32* @stderr
%219 = call i32 @fprintf(i32 %218, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %220
220: ; preds = %217, %210
br label %221
221: ; preds = %220, %207, %203
%222 = call i32 @usleep(i32 50000)
br label %181
223: ; preds = %181
%224 = load i32, i32* %8
%225 = call i64 @WIFSIGNALED(i32 %224)
%226 = icmp ne i64 %225, 0
br i1 %226, label %227, label %228
227: ; preds = %223
store i32 4, i32* %3
br label %229
228: ; preds = %223
store i32 0, i32* %3
br label %229
229: ; preds = %228, %227, %174, %168
%230 = load i32, i32* %3
ret i32 %230
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"-m\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [3 x i8] c"-w\00"
@.str.4 = [3 x i8] c"-f\00"
@.str.5 = [3 x i8] c"-x\00"
@RLIMIT_CPU = global i32 0
@RLIMIT_AS = global i32 0
@RLIMIT_FSIZE = global i32 0
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str.6 = [12 x i8] c"can't fork.\00"
@.str.7 = [8 x i8] c"/bin/sh\00"
@.str.8 = [3 x i8] c"sh\00"
@.str.9 = [14 x i8] c"Can't execute\00"
@WNOHANG = global i32 0
@.str.10 = [8 x i8] c"Hanged\0A\00"
@SIGKILL = global i32 0
@.str.11 = [15 x i8] c"Failed to kill\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.rlimit
%5 = alloca %struct.rlimit
%6 = alloca %struct.rlimit
%7 = alloca %struct.rlimit
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = bitcast i32* %3 to i8*
%12 = bitcast %struct.rlimit* %4 to i8*
%13 = bitcast %struct.rlimit* %5 to i8*
%14 = bitcast %struct.rlimit* %6 to i8*
%15 = bitcast %struct.rlimit* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = bitcast %struct.timeval* %9 to i8*
%18 = bitcast %struct.timeval* %10 to i8*
store i32 180, i32* %8
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
store i32 60, i32* %19
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 0
store i32 512, i32* %20
%21 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i64 0, i32 0
store i32 16384, i32* %21
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i64 0, i32 1
store i32 128, i32* %22
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i64 0, i32 0
store i32 128, i32* %23
%24 = and i32 %0, 1
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = tail call i32 (...) @usage()
br label %28
28: ; preds = %26, %2
%29 = icmp sgt i32 %0, 2
br i1 %29, label %30, label %80
30: ; preds = %28, %71
%31 = phi i64 [ %73, %71 ], [ 1, %28 ]
%32 = phi i64 [ %74, %71 ], [ 2, %28 ]
%33 = phi i8* [ %72, %71 ], [ null, %28 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %31
%35 = load i8*, i8** %34
%36 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = getelementptr inbounds i8*, i8** %1, i64 %32
%40 = load i8*, i8** %39
%41 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %71
42: ; preds = %30
%43 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %35)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = getelementptr inbounds i8*, i8** %1, i64 %32
%47 = load i8*, i8** %46
%48 = call i32 @sscanf(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
br label %71
49: ; preds = %42
%50 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(1) %35)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = getelementptr inbounds i8*, i8** %1, i64 %32
%54 = load i8*, i8** %53
%55 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
br label %71
56: ; preds = %49
%57 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* dereferenceable(1) %35)
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = getelementptr inbounds i8*, i8** %1, i64 %32
%61 = load i8*, i8** %60
%62 = call i32 @sscanf(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %71
63: ; preds = %56
%64 = call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* dereferenceable(1) %35)
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = getelementptr inbounds i8*, i8** %1, i64 %32
%68 = load i8*, i8** %67
br label %71
69: ; preds = %63
%70 = call i32 (...) @usage()
br label %71
71: ; preds = %38, %52, %66, %69, %59, %45
%72 = phi i8* [ %33, %69 ], [ %68, %66 ], [ %33, %59 ], [ %33, %52 ], [ %33, %45 ], [ %33, %38 ]
%73 = add nuw i64 %31, 2
%74 = add i64 %32, 2
%75 = trunc i64 %31 to i32
%76 = add i32 %75, 3
%77 = icmp slt i32 %76, %0
br i1 %77, label %30, label %78
78: ; preds = %71
%79 = icmp eq i8* %72, null
br i1 %79, label %80, label %82
80: ; preds = %28, %78
%81 = call i32 (...) @usage()
br label %82
82: ; preds = %80, %78
%83 = phi i8* [ null, %80 ], [ %72, %78 ]
%84 = load i32, i32* %8
%85 = load i32, i32* %19
%86 = icmp sgt i32 %84, %85
br i1 %86, label %87, label %88
87: ; preds = %82
store i32 %85, i32* %8
br label %88
88: ; preds = %87, %82
%89 = load i32, i32* %20
%90 = shl i32 %89, 20
store i32 %90, i32* %20
%91 = load i32, i32* %21
%92 = shl i32 %91, 10
store i32 %92, i32* %21
%93 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 1
store i32 %85, i32* %93
%94 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 1
store i32 %90, i32* %94
%95 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i64 0, i32 1
store i32 %92, i32* %95
%96 = load i32, i32* @RLIMIT_CPU
%97 = call i32 @setrlimit(i32 %96, %struct.rlimit* %4)
%98 = load i32, i32* @RLIMIT_AS
%99 = call i32 @setrlimit(i32 %98, %struct.rlimit* %5)
%100 = load i32, i32* @RLIMIT_FSIZE
%101 = call i32 @setrlimit(i32 %100, %struct.rlimit* %6)
%102 = load i32, i32* @RLIMIT_NOFILE
%103 = call i32 @setrlimit(i32 %102, %struct.rlimit* %7)
%104 = call i32 (...) @fork()
switch i32 %104, label %112 [
i32 -1, label %105
i32 0, label %108
]
105: ; preds = %88
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %155
108: ; preds = %88
%109 = call i32 (...) @setsid()
%110 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %83, i8* null)
%111 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %155
112: ; preds = %88
%113 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%114 = load i32, i32* @WNOHANG
%115 = call i32 @waitpid(i32 %104, i32* %3, i32 %114)
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %150
117: ; preds = %112
%118 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
%119 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%120 = load i32, i32* %119
%121 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
%122 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%123 = load i32, i32* %122
br label %124
124: ; preds = %117, %145
%125 = call i32 @usleep(i32 25000)
%126 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%127 = load i32, i32* %118
%128 = sub nsw i32 %127, %120
%129 = load i32, i32* %8
%130 = icmp sgt i32 %128, %129
br i1 %130, label %136, label %131
131: ; preds = %124
%132 = load i32, i32* %121
%133 = icmp eq i32 %128, %129
%134 = icmp sgt i32 %132, %123
%135 = select i1 %133, i1 %134, i1 false
br i1 %135, label %136, label %145
136: ; preds = %131, %124
%137 = load i32, i32* @stderr
%138 = call i32 @fprintf(i32 %137, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%139 = load i32, i32* @SIGKILL
%140 = call i64 @killpg(i32 %104, i32 %139)
%141 = icmp eq i64 %140, 0
br i1 %141, label %145, label %142
142: ; preds = %136
%143 = load i32, i32* @stderr
%144 = call i32 @fprintf(i32 %143, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %145
145: ; preds = %136, %142, %131
%146 = call i32 @usleep(i32 50000)
%147 = load i32, i32* @WNOHANG
%148 = call i32 @waitpid(i32 %104, i32* %3, i32 %147)
%149 = icmp eq i32 %148, 0
br i1 %149, label %124, label %150
150: ; preds = %145, %112
%151 = load i32, i32* %3
%152 = call i64 @WIFSIGNALED(i32 %151)
%153 = icmp eq i64 %152, 0
%154 = select i1 %153, i32 0, i32 4
br label %155
155: ; preds = %150, %108, %105
%156 = phi i32 [ 2, %105 ], [ 3, %108 ], [ %154, %150 ]
ret i32 %156
}