#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_usec;
};

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ child_code(int, int);
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ parent_code();
int /*<<< orphan*/ printf(char *, int);
int random();
int /*<<< orphan*/ srandom(int);
int main(int argc, char *argv[]) {
  assert(argc == 2);
  int parent_pid = getpid();
  printf("Before: my pid is %d\n", parent_pid);
  for (int i = 0; i < atoi(argv[1]); ++i) {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    srandom(tv.tv_usec);
    printf("tv_usec: %ld\n", tv.tv_usec);
    child_code(parent_pid, random() % 10 + 1);
  }
  for (int i = 0; i < atoi(argv[1]); ++i) {
    parent_code();
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    124b <main+0xbb>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x20(%rbp),%edi
call   1030 <srandom@plt>
mov    -0x20(%rbp),%esi
lea    0xe00(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1080 <random@plt>
mov    -0x2c(%rbp),%edi
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x1,%esi
call   10b0 <child_code@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d7 <main+0x47>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1287 <main+0xf7>
mov    $0x0,%al
call   10a0 <parent_code@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1252 <main+0xc2>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1070 <assert@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r12d
lea    0xe42(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x8(%r13),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    1253 <main+0xc3>
mov    %rsp,%r14
lea    0xe37(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    (%rsp),%ebp
mov    %ebp,%edi
call   1030 <srandom@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <random@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%esi
add    $0x1,%esi
mov    %r12d,%edi
call   10b0 <child_code@plt>
add    $0x1,%ebx
mov    0x8(%r13),%rbp
mov    %rbp,%rdi
call   1090 <atoi@plt>
cmp    %eax,%ebx
jl     11f0 <main+0x60>
mov    %rbp,%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    1287 <main+0xf7>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <parent_code@plt>
add    $0x1,%ebx
mov    0x8(%r13),%rdi
call   1090 <atoi@plt>
cmp    %eax,%ebx
jl     1270 <main+0xe0>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [22 x i8] c"Before: my pid is %d\0A\00"
@.str.1 = [14 x i8] c"tv_usec: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 (...) @getpid()
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 0, i32* %7
br label %17
17: ; preds = %37, %2
%18 = load i32, i32* %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = icmp slt i32 %18, %22
br i1 %23, label %24, label %40
24: ; preds = %17
%25 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @srandom(i32 %27)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %6
%33 = call i32 (...) @random()
%34 = srem i32 %33, 10
%35 = add nsw i32 %34, 1
%36 = call i32 @child_code(i32 %32, i32 %35)
br label %37
37: ; preds = %24
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %17
40: ; preds = %17
store i32 0, i32* %9
br label %41
41: ; preds = %50, %40
%42 = load i32, i32* %9
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
%47 = icmp slt i32 %42, %46
br i1 %47, label %48, label %53
48: ; preds = %41
%49 = call i32 (...) @parent_code()
br label %50
50: ; preds = %48
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %41
53: ; preds = %41
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [22 x i8] c"Before: my pid is %d\0A\00"
@.str.1 = [14 x i8] c"tv_usec: %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = icmp eq i32 %0, 2
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = bitcast %struct.timeval* %3 to i8*
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
br label %20
16: ; preds = %20, %2
%17 = phi i8* [ %10, %2 ], [ %31, %20 ]
%18 = tail call i32 @atoi(i8* %17)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %36, label %34
20: ; preds = %13, %20
%21 = phi i32 [ 0, %13 ], [ %30, %20 ]
%22 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%23 = load i32, i32* %15
%24 = tail call i32 @srandom(i32 %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%26 = tail call i32 (...) @random()
%27 = srem i32 %26, 10
%28 = add nsw i32 %27, 1
%29 = tail call i32 @child_code(i32 %7, i32 %28)
%30 = add nuw nsw i32 %21, 1
%31 = load i8*, i8** %9
%32 = tail call i32 @atoi(i8* %31)
%33 = icmp slt i32 %30, %32
br i1 %33, label %20, label %16
34: ; preds = %36, %16
%35 = load i32, i32* @EXIT_SUCCESS
ret i32 %35
36: ; preds = %16, %36
%37 = phi i32 [ %39, %36 ], [ 0, %16 ]
%38 = tail call i32 (...) @parent_code()
%39 = add nuw nsw i32 %37, 1
%40 = load i8*, i8** %9
%41 = tail call i32 @atoi(i8* %40)
%42 = icmp slt i32 %39, %41
br i1 %42, label %36, label %34
}