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

/* Variables and functions */
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");
    } 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    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a5 <main+0x65>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <main+0x2e>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
jne    122a <main+0xea>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe48(%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    1217 <main+0xd7>
mov    -0x28(%rbp),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1225 <main+0xe5>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1238 <main+0xf8>
lea    0xe14(%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    0xe9c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    1199 <main+0x49>
mov    %ebx,%r12d
lea    0xe8e(%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    1180 <main+0x30>
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %rax,%rax
je     11b1 <main+0x61>
lea    0xe81(%rip),%rdi
jmp    1201 <main+0xb1>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x100000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11fa <main+0xaa>
mov    %rax,%rbx
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe5a(%rip),%rdi
jmp    1201 <main+0xb1>
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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 = [15 x i8] c"Malloc Failed\0A\00"
@.str.6 = [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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %6
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* %6
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
%27 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %26
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %33)
%35 = call i8* @malloc(i32 1048576)
store i8* %35, i8** %8
%36 = load i8*, i8** %8
%37 = icmp ugt i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %29
%39 = load i8*, i8** %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %46
44: ; preds = %29
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
br label %49
47: ; preds = %26
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %47, %46
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 = [20 x i8] c"Gettimeofday Failed\00"
@str.7 = [14 x i8] c"Malloc Failed\00"
@str.8 = [5 x i8] c"Free\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 %31
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 %31, 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)
br label %31
31: ; preds = %16, %20, %28
%32 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.8, i64 0, i64 0), %28 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0), %20 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0), %16 ]
%33 = tail call i32 @puts(i8* dereferenceable(1) %32)
ret i32 0
}