#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*/ time_t;
typedef int /*<<< orphan*/ sub_shell;
struct stat {
  int /*<<< orphan*/ st_mtime;
};
typedef int /*<<< orphan*/ startenv;
typedef int /*<<< orphan*/ filebuf;

/* Variables and functions */
int /*<<< orphan*/ errno;
int execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char *get_preloader(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strtol(char *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  time_t test;
  char *errptr;
  char **sub_argv;
  int sub_argc;
  int r;
  char filebuf[32];
  char startenv[32];
  char *sub_shell[] = {"/bin/bash", "-i", NULL};
  if (argc < 2) {
    fprintf(stderr, "usage %s <timestamp> [program [args...]]\n", argv[0]);
    return 1;
  }
  snprintf(startenv, sizeof(startenv), "%ld", time(NULL));
  setenv("TIMEBOX_INIT", startenv, 1);
  test = strtol(argv[1], &errptr, 0);
  if (*errptr != 0) {
    struct stat sb;
    if (stat(argv[1], &sb) == 0) {
      snprintf(filebuf, sizeof(filebuf), "%ld", sb.st_mtime);
      argv[1] = filebuf;
    } else {
      fprintf(stderr, "%s: %s: invalid unix timestamp.\n", argv[0], argv[1]);
      return 2;
    }
  }
  setenv("LD_PRELOAD", get_preloader(argv[0]), 1);
  setenv("TIMEBOX_TIME", argv[1], 1);
  if (argc < 3) {
    sub_argv = sub_shell;
    sub_argc = sizeof(sub_shell) / sizeof(sub_shell[0]);
  } else {
    sub_argv = argv + 2;
    sub_argc = argc - 2;
  }
  if ((r = execvp(sub_argv[0], sub_argv)) < 0) {
    fprintf(stderr, "%s: %s: cannot exec: %s\n", argv[0], sub_argv[0],
            strerror(errno));
    return 3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c40(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0x2c3a(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    0x2c34(%rip),%rax
mov    %rax,-0x80(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1204 <main+0x74>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ea <main+0x25a>
lea    -0x70(%rbp),%rax
mov    %rax,-0xa0(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%ecx
mov    $0x20,%esi
lea    0xe0a(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rsi
lea    0xdfe(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12ee <main+0x15e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x98(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    12b7 <main+0x127>
lea    -0x50(%rbp),%rdi
mov    -0x98(%rbp),%ecx
mov    $0x20,%esi
lea    0xd96(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x50(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    12e9 <main+0x159>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13ea <main+0x25a>
jmp    12ee <main+0x15e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <get_preloader@plt>
mov    %rax,%rsi
lea    0xd65(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd57(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1348 <main+0x1b8>
lea    -0x90(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x3,-0x2c(%rbp)
jmp    135d <main+0x1cd>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <execvp@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    13e3 <main+0x253>
mov    0x2c58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa8(%rbp)
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    %rax,%r8
lea    0xcb1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    13ea <main+0x25a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
mov    0x2c5c(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2c40(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x1,%edi
jg     11df <main+0x4f>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r14d
jmp    1320 <main+0x190>
mov    %edi,%r15d
xor    %r14d,%r14d
xor    %edi,%edi
call   1090 <time@plt>
lea    0xe44(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
lea    0xe2d(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     128f <main+0xff>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     126f <main+0xdf>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%r14d
jmp    1320 <main+0x190>
mov    (%rsp),%ecx
lea    0xdbe(%rip),%rdx
lea    0x50(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
mov    %rbp,0x8(%rbx)
mov    (%rbx),%rdi
call   1050 <get_preloader@plt>
lea    0xdcb(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    0x8(%rbx),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
lea    0x10(%rbx),%rax
cmp    $0x3,%r15d
lea    0x10(%rsp),%rbp
cmovae %rax,%rbp
mov    0x0(%rbp),%rdi
mov    %rbp,%rsi
call   10a0 <execvp@plt>
test   %eax,%eax
jns    1320 <main+0x190>
mov    0x2cf0(%rip),%rax
mov    (%rax),%r14d
mov    (%rbx),%rbx
mov    0x0(%rbp),%rbp
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd7a(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%r14d
mov    %r14d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [3 x i8] c"-i\00"
@__const.main.sub_shell = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.2 = [42 x i8] c"usage %s <timestamp> [program [args...]]\0A\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [13 x i8] c"TIMEBOX_INIT\00"
@.str.5 = [33 x i8] c"%s: %s: invalid unix timestamp.\0A\00"
@.str.6 = [11 x i8] c"LD_PRELOAD\00"
@.str.7 = [13 x i8] c"TIMEBOX_TIME\00"
@.str.8 = [25 x i8] c"%s: %s: cannot exec: %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 i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca [32 x i8]
%12 = alloca [32 x i8]
%13 = alloca [3 x i8*]
%14 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [3 x i8*]* %13 to i8*
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %100
24: ; preds = %2
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%26 = call i32 @time(i32* null)
%27 = call i32 @snprintf(i8* %25, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%29 = call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32 1)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strtol(i8* %32, i8** %7, i32 0)
store i32 %33, i32* %6
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %62
38: ; preds = %24
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i64 @stat(i8* %41, %struct.stat* %14)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %38
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%46 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @snprintf(i8* %45, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
store i8* %49, i8** %51
br label %61
52: ; preds = %38
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %59)
store i32 2, i32* %3
br label %100
61: ; preds = %44
br label %62
62: ; preds = %61, %24
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i8* @get_preloader(i8* %65)
%67 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %66, i32 1)
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %70, i32 1)
%72 = load i32, i32* %4
%73 = icmp slt i32 %72, 3
br i1 %73, label %74, label %76
74: ; preds = %62
%75 = getelementptr inbounds [3 x i8*], [3 x i8*]* %13, i64 0, i64 0
store i8** %75, i8*** %8
store i32 3, i32* %9
br label %81
76: ; preds = %62
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 2
store i8** %78, i8*** %8
%79 = load i32, i32* %4
%80 = sub nsw i32 %79, 2
store i32 %80, i32* %9
br label %81
81: ; preds = %76, %74
%82 = load i8**, i8*** %8
%83 = getelementptr inbounds i8*, i8** %82, i64 0
%84 = load i8*, i8** %83
%85 = load i8**, i8*** %8
%86 = call i32 @execvp(i8* %84, i8** %85)
store i32 %86, i32* %10
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %99
88: ; preds = %81
%89 = load i32, i32* @stderr
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 0
%92 = load i8*, i8** %91
%93 = load i8**, i8*** %8
%94 = getelementptr inbounds i8*, i8** %93, i64 0
%95 = load i8*, i8** %94
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %92, i8* %95, i8* %97)
store i32 3, i32* %3
br label %100
99: ; preds = %81
store i32 0, i32* %3
br label %100
100: ; preds = %99, %88, %52, %18
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/bin/bash\00"
@.str.1 = [3 x i8] c"-i\00"
@__const.main.sub_shell = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.2 = [42 x i8] c"usage %s <timestamp> [program [args...]]\0A\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [13 x i8] c"TIMEBOX_INIT\00"
@.str.5 = [33 x i8] c"%s: %s: invalid unix timestamp.\0A\00"
@.str.6 = [11 x i8] c"LD_PRELOAD\00"
@.str.7 = [13 x i8] c"TIMEBOX_TIME\00"
@.str.8 = [25 x i8] c"%s: %s: cannot exec: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca [3 x i8*]
%7 = alloca %struct.stat
%8 = bitcast i8** %3 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%11 = bitcast [3 x i8*]* %6 to i8*
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %61
17: ; preds = %2
%18 = tail call i32 @time(i32* null)
%19 = call i32 @snprintf(i8* %10, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32 1)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i8** %3, i32 0)
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %41, label %27
27: ; preds = %17
%28 = bitcast %struct.stat* %7 to i8*
%29 = load i8*, i8** %21
%30 = call i64 @stat(i8* %29, %struct.stat* %7)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @snprintf(i8* %9, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
store i8* %9, i8** %21
br label %41
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %1
%39 = load i8*, i8** %21
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8* %39)
br label %61
41: ; preds = %32, %17
%42 = load i8*, i8** %1
%43 = call i8* @get_preloader(i8* %42)
%44 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %43, i32 1)
%45 = load i8*, i8** %21
%46 = call i32 @setenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %45, i32 1)
%47 = icmp ult i32 %0, 3
%48 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%49 = getelementptr inbounds i8*, i8** %1, i64 2
%50 = select i1 %47, i8** %48, i8** %49
%51 = load i8*, i8** %50
%52 = call i32 @execvp(i8* %51, i8** %50)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %41
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %1
%57 = load i8*, i8** %50
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %56, i8* %57, i8* %59)
br label %61
61: ; preds = %36, %41, %54, %13
%62 = phi i32 [ 1, %13 ], [ 3, %54 ], [ 2, %36 ], [ 0, %41 ]
ret i32 %62
}