#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;
};
typedef int pid_t;

/* Variables and functions */
int fork();
int /*<<< orphan*/ free(void *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  printf("Test %d\n", argc);
  int i;
  for (i = 0; i < argc; i++) {
    printf("%d: %s\n", i, argv[i]);
  }
  struct timeval tv;
  if (gettimeofday(&tv, NULL) == 0) {
    printf("Gettimeofday %d %d\n", tv.tv_sec, tv.tv_usec);
    void *test = malloc(1024 * 1024);
    if (test > 0) {
      printf("Malloc %x\n", test);
      free(test);
      printf("Free\n");
      pid_t pid = fork();
      if (pid == 0) {
        printf("Fork Parent\n");
      } else if (pid > 0) {
        printf("Fork Child %d\n", pid);
      } else {
        printf("Fork Failed\n");
      }
    } else {
      printf("Malloc Failed\n");
    }
  } else {
    printf("Gettimeofday Failed\n");
  }
  return 0;
}


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)
mov    -0x8(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b5 <main+0x65>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <main+0x2e>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
jne    1294 <main+0x144>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    1281 <main+0x131>
mov    -0x28(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1249 <main+0xf9>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127c <main+0x12c>
cmpl   $0x0,-0x2c(%rbp)
jle    1269 <main+0x119>
mov    -0x2c(%rbp),%esi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1277 <main+0x127>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127c <main+0x12c>
jmp    128f <main+0x13f>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a2 <main+0x152>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe8c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    11a9 <main+0x49>
mov    %ebx,%r12d
lea    0xe7e(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <main+0x30>
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
je     11d2 <main+0x72>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x100000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     123d <main+0xdd>
mov    %rax,%rbx
lea    0xe25(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe48(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1249 <main+0xe9>
jle    1255 <main+0xf5>
lea    0xdfe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c4 <main+0x64>
lea    0xe0f(%rip),%rdi
jmp    11bf <main+0x5f>
lea    0xe22(%rip),%rdi
jmp    11bf <main+0x5f>
lea    0xe0a(%rip),%rdi
jmp    11bf <main+0x5f>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [9 x i8] c"Test %d\0A\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
@.str.2 = [20 x i8] c"Gettimeofday %d %d\0A\00"
@.str.3 = [11 x i8] c"Malloc %x\0A\00"
@.str.4 = [6 x i8] c"Free\0A\00"
@.str.5 = [13 x i8] c"Fork Parent\0A\00"
@.str.6 = [15 x i8] c"Fork Child %d\0A\00"
@.str.7 = [13 x i8] c"Fork Failed\0A\00"
@.str.8 = [15 x i8] c"Malloc Failed\0A\00"
@.str.9 = [21 x i8] c"Gettimeofday Failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 0, i32* %6
br label %12
12: ; preds = %24, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load i32, i32* %6
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %22)
br label %24
24: ; preds = %16
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %12
27: ; preds = %12
%28 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %63
30: ; preds = %27
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %34)
%36 = call i8* @malloc(i32 1048576)
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = icmp ugt i8* %37, null
br i1 %38, label %39, label %60
39: ; preds = %30
%40 = load i8*, i8** %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 (...) @fork()
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %59
50: ; preds = %39
%51 = load i32, i32* %9
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %54)
br label %58
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
br label %59
59: ; preds = %58, %48
br label %62
60: ; preds = %30
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %62
62: ; preds = %60, %59
br label %65
63: ; preds = %27
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
br label %65
65: ; preds = %63, %62
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [9 x i8] c"Test %d\0A\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
@.str.2 = [20 x i8] c"Gettimeofday %d %d\0A\00"
@.str.3 = [11 x i8] c"Malloc %x\0A\00"
@.str.6 = [15 x i8] c"Fork Child %d\0A\00"
@str = [20 x i8] c"Gettimeofday Failed\00"
@str.10 = [14 x i8] c"Malloc Failed\00"
@str.11 = [5 x i8] c"Free\00"
@str.12 = [12 x i8] c"Fork Failed\00"
@str.13 = [12 x i8] c"Fork Parent\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = trunc i64 %9 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %12, i8* %11)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = bitcast %struct.timeval* %3 to i8*
%18 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %24)
%26 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%27 = icmp eq i8* %26, null
br i1 %27, label %42, label %28
28: ; preds = %20
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%30 = tail call i32 @free(i8* %26)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.11, i64 0, i64 0))
%32 = tail call i32 (...) @fork()
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
br label %46
36: ; preds = %28
%37 = icmp sgt i32 %32, 0
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %32)
br label %46
40: ; preds = %36
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
br label %46
42: ; preds = %20
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %46
44: ; preds = %16
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %42, %38, %40, %34, %44
ret i32 0
}