#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 u_int;
struct timeval {
  long tv_sec;
  long tv_usec;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int errno;
int execl(char *, char *, char *, char *, char *, char *, int /*<<< orphan*/ *);
int execv(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, ...);
int get_attach_status(int, scalar_t__);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, scalar_t__);
int /*<<< orphan*/ stderr;
int wait_for_replay_group(int, scalar_t__);
int waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct timeval tv_start, tv_attach, tv_tool_done, tv_done;
  char cpids[80], tmpdir[80], lscmd[80];
  char *dirname;
  char *pin_tool;
  pid_t cpid, mpid, ppid;
  int fd, rc, status;
  int next_child = 0, i;
  size_t n = 1024;
  FILE *fp;
  if (argc < 3) {
    print_usage();
    return -1;
  }
  dirname = argv[1];
  pin_tool = argv[2];
  fd = open("/dev/spec0", O_RDWR);
  if (fd < 0) {
    perror("open /dev/spec0");
    return fd;
  }
  gettimeofday(&tv_start, NULL);
  cpid = fork();
  if (cpid == 0) {
    rc = execl("./resume", "resume", "-p", dirname, "--pthread",
               "../eglibc-2.15/prefix/lib", NULL);
    fprintf(stderr, "execl of resume failed, rc=%d, errno=%d\n", rc, errno);
    return -1;
  }
  do {
    rc = get_attach_status(fd, cpid);
  } while (rc <= 0);
  gettimeofday(&tv_attach, NULL);
  mpid = fork();
  if (mpid == 0) {
    const char *args[256];
    char tool_path[256];
    sprintf(tool_path, "../pin_tools/obj-ia32/%s", pin_tool);
    u_int argcnt = 0;
    args[argcnt++] = "pin";
    args[argcnt++] = "-pid";
    sprintf(cpids, "%d", cpid);
    args[argcnt++] = cpids;
    args[argcnt++] = "-t";
    args[argcnt++] = tool_path;
    if (argc > 3) {
      printf("adding extra args\n");
      for (i = 3; i < argc; ++i) {
        args[argcnt++] = argv[i];
        printf("%s\n", args[argcnt - 1]);
      }
    }
    args[argcnt++] = NULL;
    rc = execv("../../../pin/pin", (char **)args);
    fprintf(stderr, "execv of pin tool failed, rc=%d, errno=%d\n", rc, errno);
    return -1;
  }
  rc = wait_for_replay_group(fd, cpid);
  rc = waitpid(cpid, &status, 0);
  if (rc < 0) {
    fprintf(stderr, "waitpid returns %d, errno %d for pid %d\n", rc, errno,
            cpid);
  }
  gettimeofday(&tv_tool_done, NULL);
  printf("TOOL finished\n");
  gettimeofday(&tv_done, NULL);
  close(fd);
  printf("Start time: %ld.%06ld\n", tv_start.tv_sec, tv_start.tv_usec);
  printf("Attach time: %ld.%06ld\n", tv_attach.tv_sec, tv_attach.tv_usec);
  printf("End time: %ld.%06ld\n", tv_done.tv_sec, tv_done.tv_usec);
  long diff_usec = tv_done.tv_usec - tv_start.tv_usec;
  long carryover = 0;
  if (diff_usec < 0) {
    carryover = -1;
    diff_usec = 1 - diff_usec;
  }
  long diff_sec = tv_done.tv_sec - tv_start.tv_sec - carryover;
  printf("Start -> End: %ld.%06ld\n", diff_sec, diff_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xac0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x178(%rbp)
movq   $0x400,-0x188(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    122b <main+0x4b>
mov    $0x0,%al
call   10d0 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4e0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x148(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x150(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    0xdac(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x16c(%rbp)
cmpl   $0x0,-0x16c(%rbp)
jge    128b <main+0xab>
lea    0xd88(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x16c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16c0 <main+0x4e0>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    1325 <main+0x145>
mov    -0x148(%rbp),%rcx
lea    0xd4e(%rip),%rdi
lea    0xd49(%rip),%rsi
lea    0xd49(%rip),%rdx
lea    0xd45(%rip),%r8
lea    0xd48(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   10e0 <execl@plt>
mov    %eax,-0x170(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    -0x170(%rbp),%edx
mov    0x2cc7(%rip),%rax
mov    (%rax),%ecx
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4e0>
jmp    132a <main+0x14a>
mov    -0x16c(%rbp),%edi
mov    -0x158(%rbp),%rsi
call   10c0 <get_attach_status@plt>
mov    %eax,-0x170(%rbp)
cmpl   $0x0,-0x170(%rbp)
jle    132a <main+0x14a>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x160(%rbp)
cmpq   $0x0,-0x160(%rbp)
jne    155f <main+0x37f>
lea    -0xa90(%rbp),%rdi
mov    -0x150(%rbp),%rdx
lea    0xcdc(%rip),%rsi
call   10b0 <sprintf@plt>
movl   $0x0,-0xa94(%rbp)
mov    -0xa94(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xa94(%rbp)
cltq
lea    0xcfb(%rip),%rcx
mov    %rcx,-0x990(%rbp,%rax,8)
ff
mov    -0xa94(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xa94(%rbp)
cltq
lea    0xcaa(%rip),%rcx
mov    %rcx,-0x990(%rbp,%rax,8)
ff
lea    -0xa0(%rbp),%rdi
mov    -0x158(%rbp),%rdx
lea    0xc92(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0xa0(%rbp),%rcx
mov    -0xa94(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa94(%rbp)
cltq
mov    %rcx,-0x990(%rbp,%rax,8)
ff
mov    -0xa94(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xa94(%rbp)
cltq
lea    0xc54(%rip),%rcx
mov    %rcx,-0x990(%rbp,%rax,8)
ff
lea    -0xa90(%rbp),%rcx
mov    -0xa94(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa94(%rbp)
cltq
mov    %rcx,-0x990(%rbp,%rax,8)
ff
cmpl   $0x3,-0x8(%rbp)
jle    14f5 <main+0x315>
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x17c(%rbp)
mov    -0x17c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14f0 <main+0x310>
mov    -0x10(%rbp),%rax
movslq -0x17c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0xa94(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xa94(%rbp)
cltq
mov    %rcx,-0x990(%rbp,%rax,8)
ff
mov    -0xa94(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x990(%rbp,%rax,8),%rsi
ff
lea    0xbcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x17c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x17c(%rbp)
jmp    1482 <main+0x2a2>
jmp    14f5 <main+0x315>
mov    -0xa94(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xa94(%rbp)
cltq
movq   $0x0,-0x990(%rbp,%rax,8)
lea    -0x990(%rbp),%rsi
lea    0xb82(%rip),%rdi
call   10f0 <execv@plt>
mov    %eax,-0x170(%rbp)
mov    0x2aa4(%rip),%rax
mov    (%rax),%edi
mov    -0x170(%rbp),%edx
mov    0x2a8d(%rip),%rax
mov    (%rax),%ecx
lea    0xb69(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16c0 <main+0x4e0>
mov    -0x16c(%rbp),%edi
mov    -0x158(%rbp),%rsi
call   1070 <wait_for_replay_group@plt>
mov    %eax,-0x170(%rbp)
mov    -0x158(%rbp),%rdi
lea    -0x174(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    %eax,-0x170(%rbp)
cmpl   $0x0,-0x170(%rbp)
jge    15cc <main+0x3ec>
mov    0x2a32(%rip),%rax
mov    (%rax),%edi
mov    -0x170(%rbp),%edx
mov    0x2a1b(%rip),%rax
mov    (%rax),%ecx
mov    -0x158(%rbp),%r8
lea    0xb1b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    0xb29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x16c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xb0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xb0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xb0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0xaa0(%rbp)
movq   $0x0,-0xaa8(%rbp)
cmpq   $0x0,-0xaa0(%rbp)
jge    1687 <main+0x4a7>
movq   $0xffffffffffffffff,-0xaa8(%rbp)
ff ff ff ff
mov    $0x1,%eax
sub    -0xaa0(%rbp),%rax
mov    %rax,-0xaa0(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x20(%rbp),%rax
sub    -0xaa8(%rbp),%rax
mov    %rax,-0xab0(%rbp)
mov    -0xab0(%rbp),%rsi
mov    -0xaa0(%rbp),%rdx
lea    0xaaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xac0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x988,%rsp
cmp    $0x2,%edi
jg     1212 <main+0x22>
xor    %eax,%eax
call   10e0 <print_usage@plt>
jmp    14e9 <main+0x2f9>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%r13
mov    0x10(%rsi),%r12
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
lea    0xdd5(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1504 <main+0x314>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
je     138c <main+0x19c>
mov    %rax,%rbx
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
call   10d0 <get_attach_status@plt>
test   %eax,%eax
jle    1260 <main+0x70>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
je     13dd <main+0x1ed>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <wait_for_replay_group@plt>
lea    0x30(%rsp),%rsi
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %edx,%edx
call   1090 <waitpid@plt>
test   %eax,%eax
jns    12cf <main+0xdf>
mov    0x2d27(%rip),%rcx
mov    (%rcx),%edi
mov    0x2d16(%rip),%rcx
mov    (%rcx),%ecx
lea    0xe06(%rip),%rsi
mov    %eax,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x180(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
lea    0x80(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x20(%rsp),%r15
mov    0x28(%rsp),%r12
lea    0xde1(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x80(%rsp),%rbx
mov    0x88(%rsp),%rbp
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
sub    %r12,%rbp
mov    $0x1,%edx
sub    %rbp,%rdx
test   %rbp,%rbp
cmovns %rbp,%rdx
shr    $0x3f,%rbp
sub    %r15,%rbx
add    %rbp,%rbx
lea    0xdb9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    14ef <main+0x2ff>
movq   $0x0,(%rsp)
lea    0xc75(%rip),%rdi
lea    0xc70(%rip),%rsi
lea    0xc70(%rip),%rdx
lea    0xc6c(%rip),%r8
lea    0xc6f(%rip),%r9
mov    %r13,%rcx
call   10f0 <execl@plt>
mov    0x2c12(%rip),%rcx
mov    (%rcx),%edi
mov    0x2c01(%rip),%rcx
mov    (%rcx),%ecx
lea    0xc68(%rip),%rsi
jmp    14e0 <main+0x2f0>
lea    0xc85(%rip),%rsi
lea    0x80(%rsp),%r13
mov    %r13,%rdi
mov    %r12,%rdx
call   10c0 <sprintf@plt>
lea    0xc9c(%rip),%rax
mov    %rax,0x180(%rsp)
lea    0xc75(%rip),%rax
mov    %rax,0x188(%rsp)
lea    0xc6b(%rip),%rsi
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
mov    %rbp,0x190(%rsp)
lea    0xc4f(%rip),%rax
mov    %rax,0x198(%rsp)
mov    %r13,0x1a0(%rsp)
mov    $0x5,%ebx
cmp    $0x4,%r14d
jl     14a7 <main+0x2b7>
lea    0xd00(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
mov    $0x3,%r14d
sub    %rax,%r14
mov    $0x5,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x10(%r15,%rbp,8),%rdi
lea    0x1(%rbp),%rbx
mov    %rdi,0x180(%rsp,%rbp,8)
call   1030 <puts@plt>
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
mov    %rbx,%rbp
cmp    $0x5,%rax
jne    1480 <main+0x290>
movq   $0x0,0x180(%rsp,%rbx,8)
lea    0xbd3(%rip),%rdi
lea    0x180(%rsp),%rsi
call   1100 <execv@plt>
mov    0x2b0a(%rip),%rcx
mov    (%rcx),%edi
mov    0x2af9(%rip),%rcx
mov    (%rcx),%ecx
lea    0xbbe(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x988,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaf5(%rip),%rdi
call   10b0 <perror@plt>
mov    %ebp,%r14d
jmp    14ef <main+0x2ff>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [11 x i8] c"/dev/spec0\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/spec0\00"
@.str.2 = [9 x i8] c"./resume\00"
@.str.3 = [7 x i8] c"resume\00"
@.str.4 = [3 x i8] c"-p\00"
@.str.5 = [10 x i8] c"--pthread\00"
@.str.6 = [26 x i8] c"../eglibc-2.15/prefix/lib\00"
@stderr = global i32 0
@.str.7 = [41 x i8] c"execl of resume failed, rc=%d, errno=%d\0A\00"
@errno = global i32 0
@.str.8 = [25 x i8] c"../pin_tools/obj-ia32/%s\00"
@.str.9 = [4 x i8] c"pin\00"
@.str.10 = [5 x i8] c"-pid\00"
@.str.11 = [3 x i8] c"%d\00"
@.str.12 = [3 x i8] c"-t\00"
@.str.13 = [19 x i8] c"adding extra args\0A\00"
@.str.14 = [4 x i8] c"%s\0A\00"
@.str.15 = [17 x i8] c"../../../pin/pin\00"
@.str.16 = [43 x i8] c"execv of pin tool failed, rc=%d, errno=%d\0A\00"
@.str.17 = [41 x i8] c"waitpid returns %d, errno %d for pid %d\0A\00"
@.str.18 = [15 x i8] c"TOOL finished\0A\00"
@.str.19 = [23 x i8] c"Start time: %ld.%06ld\0A\00"
@.str.20 = [24 x i8] c"Attach time: %ld.%06ld\0A\00"
@.str.21 = [21 x i8] c"End time: %ld.%06ld\0A\00"
@.str.22 = [25 x i8] c"Start -> End: %ld.%06ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
%12 = alloca [80 x i8]
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i64
%24 = alloca i32*
%25 = alloca [256 x i8*]
%26 = alloca [256 x i8]
%27 = alloca i32
%28 = alloca i64
%29 = alloca i64
%30 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %21
store i64 1024, i64* %23
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 3
br i1 %32, label %33, label %35
33: ; preds = %2
%34 = call i32 (...) @print_usage()
store i32 -1, i32* %3
br label %199
35: ; preds = %2
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
store i8* %38, i8** %13
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
store i8* %41, i8** %14
%42 = load i32, i32* @O_RDWR
%43 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %42)
store i32 %43, i32* %18
%44 = load i32, i32* %18
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %35
%47 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* %18
store i32 %48, i32* %3
br label %199
49: ; preds = %35
%50 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%51 = call i64 (...) @fork()
store i64 %51, i64* %15
%52 = load i64, i64* %15
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %49
%55 = load i8*, i8** %13
%56 = call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %55, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32* null)
store i32 %56, i32* %19
%57 = load i32, i32* @stderr
%58 = load i32, i32* %19
%59 = load i32, i32* @errno
%60 = call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %58, i32 %59)
store i32 -1, i32* %3
br label %199
61: ; preds = %49
br label %62
62: ; preds = %66, %61
%63 = load i32, i32* %18
%64 = load i64, i64* %15
%65 = call i32 @get_attach_status(i32 %63, i64 %64)
store i32 %65, i32* %19
br label %66
66: ; preds = %62
%67 = load i32, i32* %19
%68 = icmp sle i32 %67, 0
br i1 %68, label %62, label %69
69: ; preds = %66
%70 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%71 = call i64 (...) @fork()
store i64 %71, i64* %16
%72 = load i64, i64* %16
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %143
74: ; preds = %69
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %26, i64 0, i64 0
%76 = load i8*, i8** %14
%77 = ptrtoint i8* %76 to i64
%78 = call i32 @sprintf(i8* %75, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i64 %77)
store i32 0, i32* %27
%79 = load i32, i32* %27
%80 = add nsw i32 %79, 1
store i32 %80, i32* %27
%81 = sext i32 %79 to i64
%82 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %81
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %82
%83 = load i32, i32* %27
%84 = add nsw i32 %83, 1
store i32 %84, i32* %27
%85 = sext i32 %83 to i64
%86 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %85
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** %86
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%88 = load i64, i64* %15
%89 = call i32 @sprintf(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 %88)
%90 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%91 = load i32, i32* %27
%92 = add nsw i32 %91, 1
store i32 %92, i32* %27
%93 = sext i32 %91 to i64
%94 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %93
store i8* %90, i8** %94
%95 = load i32, i32* %27
%96 = add nsw i32 %95, 1
store i32 %96, i32* %27
%97 = sext i32 %95 to i64
%98 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %97
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8** %98
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %26, i64 0, i64 0
%100 = load i32, i32* %27
%101 = add nsw i32 %100, 1
store i32 %101, i32* %27
%102 = sext i32 %100 to i64
%103 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %102
store i8* %99, i8** %103
%104 = load i32, i32* %4
%105 = icmp sgt i32 %104, 3
br i1 %105, label %106, label %132
106: ; preds = %74
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
store i32 3, i32* %22
br label %108
108: ; preds = %128, %106
%109 = load i32, i32* %22
%110 = load i32, i32* %4
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %131
112: ; preds = %108
%113 = load i8**, i8*** %5
%114 = load i32, i32* %22
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8*, i8** %113, i64 %115
%117 = load i8*, i8** %116
%118 = load i32, i32* %27
%119 = add nsw i32 %118, 1
store i32 %119, i32* %27
%120 = sext i32 %118 to i64
%121 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %120
store i8* %117, i8** %121
%122 = load i32, i32* %27
%123 = sub nsw i32 %122, 1
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %124
%126 = load i8*, i8** %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8* %126)
br label %128
128: ; preds = %112
%129 = load i32, i32* %22
%130 = add nsw i32 %129, 1
store i32 %130, i32* %22
br label %108
131: ; preds = %108
br label %132
132: ; preds = %131, %74
%133 = load i32, i32* %27
%134 = add nsw i32 %133, 1
store i32 %134, i32* %27
%135 = sext i32 %133 to i64
%136 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 %135
store i8* null, i8** %136
%137 = getelementptr inbounds [256 x i8*], [256 x i8*]* %25, i64 0, i64 0
%138 = call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i8** %137)
store i32 %138, i32* %19
%139 = load i32, i32* @stderr
%140 = load i32, i32* %19
%141 = load i32, i32* @errno
%142 = call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %140, i32 %141)
store i32 -1, i32* %3
br label %199
143: ; preds = %69
%144 = load i32, i32* %18
%145 = load i64, i64* %15
%146 = call i32 @wait_for_replay_group(i32 %144, i64 %145)
store i32 %146, i32* %19
%147 = load i64, i64* %15
%148 = call i32 @waitpid(i64 %147, i32* %20, i32 0)
store i32 %148, i32* %19
%149 = load i32, i32* %19
%150 = icmp slt i32 %149, 0
br i1 %150, label %151, label %157
151: ; preds = %143
%152 = load i32, i32* @stderr
%153 = load i32, i32* %19
%154 = load i32, i32* @errno
%155 = load i64, i64* %15
%156 = call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0), i32 %153, i32 %154, i64 %155)
br label %157
157: ; preds = %151, %143
%158 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.18, i64 0, i64 0))
%160 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%161 = load i32, i32* %18
%162 = call i32 @close(i32 %161)
%163 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%164 = load i64, i64* %163
%165 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%166 = load i64, i64* %165
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i64 %164, i64 %166)
%168 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%169 = load i64, i64* %168
%170 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%171 = load i64, i64* %170
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.20, i64 0, i64 0), i64 %169, i64 %171)
%173 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%174 = load i64, i64* %173
%175 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%176 = load i64, i64* %175
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0), i64 %174, i64 %176)
%178 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%179 = load i64, i64* %178
%180 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%181 = load i64, i64* %180
%182 = sub nsw i64 %179, %181
store i64 %182, i64* %28
store i64 0, i64* %29
%183 = load i64, i64* %28
%184 = icmp slt i64 %183, 0
br i1 %184, label %185, label %188
185: ; preds = %157
store i64 -1, i64* %29
%186 = load i64, i64* %28
%187 = sub nsw i64 1, %186
store i64 %187, i64* %28
br label %188
188: ; preds = %185, %157
%189 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%190 = load i64, i64* %189
%191 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%192 = load i64, i64* %191
%193 = sub nsw i64 %190, %192
%194 = load i64, i64* %29
%195 = sub nsw i64 %193, %194
store i64 %195, i64* %30
%196 = load i64, i64* %30
%197 = load i64, i64* %28
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.22, i64 0, i64 0), i64 %196, i64 %197)
store i32 0, i32* %3
br label %199
199: ; preds = %188, %132, %54, %46, %33
%200 = load i32, i32* %3
ret i32 %200
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [11 x i8] c"/dev/spec0\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/spec0\00"
@.str.2 = [9 x i8] c"./resume\00"
@.str.3 = [7 x i8] c"resume\00"
@.str.4 = [3 x i8] c"-p\00"
@.str.5 = [10 x i8] c"--pthread\00"
@.str.6 = [26 x i8] c"../eglibc-2.15/prefix/lib\00"
@stderr = global i32 0
@.str.7 = [41 x i8] c"execl of resume failed, rc=%d, errno=%d\0A\00"
@errno = global i32 0
@.str.8 = [25 x i8] c"../pin_tools/obj-ia32/%s\00"
@.str.9 = [4 x i8] c"pin\00"
@.str.10 = [5 x i8] c"-pid\00"
@.str.11 = [3 x i8] c"%d\00"
@.str.12 = [3 x i8] c"-t\00"
@.str.15 = [17 x i8] c"../../../pin/pin\00"
@.str.16 = [43 x i8] c"execv of pin tool failed, rc=%d, errno=%d\0A\00"
@.str.17 = [41 x i8] c"waitpid returns %d, errno %d for pid %d\0A\00"
@.str.19 = [23 x i8] c"Start time: %ld.%06ld\0A\00"
@.str.20 = [24 x i8] c"Attach time: %ld.%06ld\0A\00"
@.str.21 = [21 x i8] c"End time: %ld.%06ld\0A\00"
@.str.22 = [25 x i8] c"Start -> End: %ld.%06ld\0A\00"
@str = [14 x i8] c"TOOL finished\00"
@str.23 = [18 x i8] c"adding extra args\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca [256 x i8*]
%10 = alloca [256 x i8]
%11 = bitcast %struct.timeval* %3 to i8*
%12 = bitcast %struct.timeval* %4 to i8*
%13 = bitcast %struct.timeval* %5 to i8*
%14 = bitcast %struct.timeval* %6 to i8*
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%16 = bitcast i32* %8 to i8*
%17 = icmp slt i32 %0, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 (...) @print_usage()
br label %116
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %116
30: ; preds = %20
%31 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%32 = tail call i64 (...) @fork()
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = tail call i32 @execl(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32* null)
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = tail call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %37)
br label %116
39: ; preds = %30, %39
%40 = tail call i32 @get_attach_status(i32 %26, i64 %32)
%41 = icmp slt i32 %40, 1
br i1 %41, label %39, label %42
42: ; preds = %39
%43 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%44 = tail call i64 (...) @fork()
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %80
46: ; preds = %42
%47 = bitcast [256 x i8*]* %9 to i8*
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%49 = ptrtoint i8* %24 to i64
%50 = call i32 @sprintf(i8* %48, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i64 %49)
%51 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %51
%52 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** %52
%53 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i64 %32)
%54 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 2
store i8* %15, i8** %54
%55 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i8** %55
%56 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 4
store i8* %48, i8** %56
%57 = icmp sgt i32 %0, 3
br i1 %57, label %58, label %73
58: ; preds = %46
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.23, i64 0, i64 0))
%60 = zext i32 %0 to i64
br label %61
61: ; preds = %58, %61
%62 = phi i64 [ 3, %58 ], [ %69, %61 ]
%63 = phi i64 [ 5, %58 ], [ %66, %61 ]
%64 = getelementptr inbounds i8*, i8** %1, i64 %62
%65 = load i8*, i8** %64
%66 = add nuw nsw i64 %63, 1
%67 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 %63
store i8* %65, i8** %67
%68 = call i32 @puts(i8* dereferenceable(1) %65)
%69 = add nuw nsw i64 %62, 1
%70 = icmp eq i64 %69, %60
br i1 %70, label %71, label %61
71: ; preds = %61
%72 = and i64 %66, 4294967295
br label %73
73: ; preds = %71, %46
%74 = phi i64 [ 5, %46 ], [ %72, %71 ]
%75 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 %74
store i8* null, i8** %75
%76 = call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i8** %51)
%77 = load i32, i32* @stderr
%78 = load i32, i32* @errno
%79 = call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.16, i64 0, i64 0), i32 %76, i32 %78)
br label %116
80: ; preds = %42
%81 = tail call i32 @wait_for_replay_group(i32 %26, i64 %32)
%82 = call i32 @waitpid(i64 %32, i32* %8, i32 0)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i32 (i32, i8*, i32, i32, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.17, i64 0, i64 0), i32 %82, i32 %86, i64 %32)
br label %88
88: ; preds = %84, %80
%89 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%91 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%92 = call i32 @close(i32 %26)
%93 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%94 = load i64, i64* %93
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%96 = load i64, i64* %95
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0), i64 %94, i64 %96)
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%99 = load i64, i64* %98
%100 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%101 = load i64, i64* %100
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.20, i64 0, i64 0), i64 %99, i64 %101)
%103 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%104 = load i64, i64* %103
%105 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%106 = load i64, i64* %105
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0), i64 %104, i64 %106)
%108 = sub nsw i64 %106, %96
%109 = icmp slt i64 %108, 0
%110 = sub nsw i64 1, %108
%111 = select i1 %109, i64 %110, i64 %108
%112 = lshr i64 %108, 63
%113 = sub i64 %104, %94
%114 = add i64 %113, %112
%115 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.22, i64 0, i64 0), i64 %114, i64 %111)
br label %116
116: ; preds = %88, %73, %34, %28, %18
%117 = phi i32 [ -1, %18 ], [ %26, %28 ], [ -1, %34 ], [ -1, %73 ], [ 0, %88 ]
ret i32 %117
}