#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 /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int i;
  struct timeval tv[100][2];
  int us = 0;
  if (argc == 2)
    us = atoi(argv[1]);
  for (i = 0; i < 100; i++) {
    gettimeofday(&tv[i][0], NULL);
    setsid();
    gettimeofday(&tv[i][1], NULL);
    if (us)
      usleep(us);
  }
  for (i = 0; i < 100; i++) {
    printf("%8ld%06ld :%02d appl\n", tv[i][0].tv_sec, tv[i][0].tv_usec, i);
    printf("%8ld%06ld :%02d prog\n", tv[i][1].tv_sec, tv[i][1].tv_usec, i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x670,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x664(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1190 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x664(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    120d <main+0xbd>
movslq -0x14(%rbp),%rax
lea    -0x660(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x0,%al
call   1050 <setsid@plt>
movslq -0x14(%rbp),%rax
lea    -0x660(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
add    $0x8,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmpl   $0x0,-0x664(%rbp)
je     11fa <main+0xaa>
mov    -0x664(%rbp),%edi
call   1070 <usleep@plt>
jmp    11ff <main+0xaf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x47>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    129d <main+0x14d>
movslq -0x14(%rbp),%rcx
lea    -0x660(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x4(%rax),%esi
movslq -0x14(%rbp),%rcx
lea    -0x660(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
lea    0xdaf(%rip),%rdi
call   1030 <printf@plt>
movslq -0x14(%rbp),%rcx
lea    -0x660(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0xc(%rax),%esi
movslq -0x14(%rbp),%rcx
lea    -0x660(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%edx
mov    -0x14(%rbp),%ecx
lea    0xd8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1214 <main+0xc4>
xor    %eax,%eax
add    $0x670,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x648,%rsp
xor    %r14d,%r14d
cmp    $0x2,%edi
jne    1171 <main+0x21>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    %rsp,%rbx
mov    $0x64,%ebp
jmp    118a <main+0x3a>
nopl   0x0(%rax,%rax,1)
add    $0x10,%rbx
add    $0xffffffffffffffff,%rbp
je     11b5 <main+0x65>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
call   1050 <setsid@plt>
lea    0x8(%rbx),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %r14d,%r14d
je     1180 <main+0x30>
mov    %r14d,%edi
call   1070 <usleep@plt>
jmp    1180 <main+0x30>
lea    0xc(%rsp),%rbp
xor    %ebx,%ebx
lea    0xe3d(%rip),%r14
lea    0xe4c(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%esi
mov    %r14,%rdi
mov    %ebx,%ecx
call   1030 <printf@plt>
mov    -0x4(%rbp),%edx
mov    0x0(%rbp),%esi
mov    %r15,%rdi
mov    %ebx,%ecx
call   1030 <printf@plt>
add    $0x1,%rbx
add    $0x10,%rbp
cmp    $0x64,%rbx
jne    11d0 <main+0x80>
xor    %eax,%eax
add    $0x648,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [22 x i8] c"%8ld%06ld :%02d appl\0A\00"
@.str.1 = [22 x i8] c"%8ld%06ld :%02d prog\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x [2 x %struct.timeval]]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
br label %16
16: ; preds = %11, %2
store i32 0, i32* %6
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %22
%24 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %23, i64 0, i64 0
%25 = call i32 @gettimeofday(%struct.timeval* %24, i32* null)
%26 = call i32 (...) @setsid()
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %28
%30 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %29, i64 0, i64 1
%31 = call i32 @gettimeofday(%struct.timeval* %30, i32* null)
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = load i32, i32* %8
%36 = call i32 @usleep(i32 %35)
br label %37
37: ; preds = %34, %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %17
41: ; preds = %17
store i32 0, i32* %6
br label %42
42: ; preds = %74, %41
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 100
br i1 %44, label %45, label %77
45: ; preds = %42
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %47
%49 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %48, i64 0, i64 0
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %53
%55 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %54, i64 0, i64 0
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = load i32, i32* %6
%59 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %51, i32 %57, i32 %58)
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %61
%63 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %62, i64 0, i64 1
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %63, i32 0, i32 1
%65 = load i32, i32* %64
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %7, i64 0, i64 %67
%69 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %68, i64 0, i64 1
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* %6
%73 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %65, i32 %71, i32 %72)
br label %74
74: ; preds = %45
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
br label %42
77: ; preds = %42
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [22 x i8] c"%8ld%06ld :%02d appl\0A\00"
@.str.1 = [22 x i8] c"%8ld%06ld :%02d prog\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x [2 x %struct.timeval]]
%4 = bitcast [100 x [2 x %struct.timeval]]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ %9, %6 ], [ 0, %2 ]
%12 = icmp eq i32 %11, 0
br label %13
13: ; preds = %10, %22
%14 = phi i64 [ 0, %10 ], [ %23, %22 ]
%15 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %14, i64 0
%16 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%17 = tail call i32 (...) @setsid()
%18 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %14, i64 1
%19 = call i32 @gettimeofday(%struct.timeval* %18, i32* null)
br i1 %12, label %22, label %20
20: ; preds = %13
%21 = tail call i32 @usleep(i32 %11)
br label %22
22: ; preds = %13, %20
%23 = add nuw nsw i64 %14, 1
%24 = icmp eq i64 %23, 100
br i1 %24, label %25, label %13
25: ; preds = %22, %25
%26 = phi i64 [ %38, %25 ], [ 0, %22 ]
%27 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %26, i64 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %26, i64 0, i32 0
%30 = load i32, i32* %29
%31 = trunc i64 %26 to i32
%32 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %30, i32 %31)
%33 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %26, i64 1, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds [100 x [2 x %struct.timeval]], [100 x [2 x %struct.timeval]]* %3, i64 0, i64 %26, i64 1, i32 0
%36 = load i32, i32* %35
%37 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %36, i32 %31)
%38 = add nuw nsw i64 %26, 1
%39 = icmp eq i64 %38, 100
br i1 %39, label %40, label %25
40: ; preds = %25
ret i32 0
}