#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 timezone {
  int dummy;
};
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ run_test(char *, char *);
int /*<<< orphan*/ run_test_d(char *, char *);
int main() {
  struct timeval start, end;
  struct timezone tz;
  static char to[(1024 * 4)] __attribute((aligned(4)));
  static char from[(1024 * 4)] __attribute((aligned(4)));
  unsigned long last = 0;
  char *pto, *pfrom;
  memset(from, 1, (1024 * 4));
  gettimeofday(&start, &tz);
  run_test(to, from);
  gettimeofday(&end, &tz);
  last =
      (end.tv_sec - start.tv_sec) * 1000 + (end.tv_usec - start.tv_usec) / 1000;
  printf("test last %ld ms\n", last);
  if (last)
    printf("performance is %ldMB/s\n", (unsigned long)((1024 * 4) * 102400) /
                                           (last * (1024 * 1024 / 1000)));
  pto = (char *)malloc((1024 * 4));
  if (pto == NULL) {
    printf("malloc fail 1\n");
    return -1;
  }
  pfrom = (char *)malloc((1024 * 4));
  if (pfrom == NULL) {
    printf("malloc fail 2 \n");
    return -1;
  }
  memset(from, 1, (1024 * 4));
  gettimeofday(&start, &tz);
  run_test_d(pto, pfrom);
  gettimeofday(&end, &tz);
  last =
      (end.tv_sec - start.tv_sec) * 1000 + (end.tv_usec - start.tv_usec) / 1000;
  printf("dynamic test last %ld ms\n", last);
  if (last)
    printf("dynamic performance is %ld MB/s\n",
           (unsigned long)((1024 * 4) * 102400) /
               (last * (1024 * 1024 / 1000)));
  if (pto)
    free(pto);
  if (pfrom)
    free(pfrom);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0x3ece(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gettimeofday@plt>
lea    0x2eab(%rip),%rdi
lea    0x3ea4(%rip),%rsi
call   1070 <run_test@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     1234 <main+0xc4>
imul   $0x418,-0x28(%rbp),%rcx
mov    $0x19000000,%eax
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1267 <main+0xf7>
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1370 <main+0x200>
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    129a <main+0x12a>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1370 <main+0x200>
lea    0x3dbb(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <run_test_d@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     1341 <main+0x1d1>
imul   $0x418,-0x28(%rbp),%rcx
mov    $0x19000000,%eax
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
je     1355 <main+0x1e5>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     1369 <main+0x1f9>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x3ed3(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1060 <gettimeofday@plt>
lea    0x2ea8(%rip),%rdi
mov    %rbx,%rsi
call   1080 <run_test@plt>
mov    %rsp,%rdi
mov    %rbp,%rsi
call   1060 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
sub    0xc(%rsp),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rbx
lea    0xe19(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
je     1242 <main+0xc2>
imul   $0x418,%rbx,%rcx
cmp    $0x19000000,%rcx
ja     1232 <main+0xb2>
mov    $0x19000000,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    1234 <main+0xb4>
xor    %esi,%esi
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1311 <main+0x191>
mov    %rax,%r15
mov    $0x1000,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     131a <main+0x19a>
mov    %rax,%r14
lea    0x3def(%rip),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <gettimeofday@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10a0 <run_test_d@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1060 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
sub    0xc(%rsp),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rbx
lea    0xd34(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
je     133d <main+0x1bd>
imul   $0x418,%rbx,%rcx
cmp    $0x19000000,%rcx
ja     132d <main+0x1ad>
mov    $0x19000000,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
jmp    132f <main+0x1af>
lea    0xd4a(%rip),%rdi
jmp    1321 <main+0x1a1>
lea    0xd32(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
jmp    134d <main+0x1cd>
xor    %esi,%esi
lea    0xcfc(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@main.to = internal global [4096 x i8] zeroinitializer
@main.from = internal global [4096 x i8] zeroinitializer
@.str = [18 x i8] c"test last %ld ms\0A\00"
@.str.1 = [24 x i8] c"performance is %ldMB/s\0A\00"
@.str.2 = [15 x i8] c"malloc fail 1\0A\00"
@.str.3 = [16 x i8] c"malloc fail 2 \0A\00"
@.str.4 = [26 x i8] c"dynamic test last %ld ms\0A\00"
@.str.5 = [33 x i8] c"dynamic performance is %ld MB/s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
store i64 0, i64* %5
%8 = call i32 @memset(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0), i32 1, i32 4096)
%9 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %4)
%10 = call i32 @run_test(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.to, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0))
%11 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %19, %21
%23 = sdiv i32 %22, 1000
%24 = add nsw i32 %17, %23
%25 = sext i32 %24 to i64
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %26)
%28 = load i64, i64* %5
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %0
%31 = load i64, i64* %5
%32 = mul i64 %31, 1048
%33 = udiv i64 419430400, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %30, %0
%36 = call i64 @malloc(i32 4096)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %92
42: ; preds = %35
%43 = call i64 @malloc(i32 4096)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %7
%45 = load i8*, i8** %7
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %92
49: ; preds = %42
%50 = call i32 @memset(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0), i32 1, i32 4096)
%51 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %4)
%52 = load i8*, i8** %6
%53 = load i8*, i8** %7
%54 = call i32 @run_test_d(i8* %52, i8* %53)
%55 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%56 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%59 = load i32, i32* %58
%60 = sub nsw i32 %57, %59
%61 = mul nsw i32 %60, 1000
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%63 = load i32, i32* %62
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%65 = load i32, i32* %64
%66 = sub nsw i32 %63, %65
%67 = sdiv i32 %66, 1000
%68 = add nsw i32 %61, %67
%69 = sext i32 %68 to i64
store i64 %69, i64* %5
%70 = load i64, i64* %5
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 %70)
%72 = load i64, i64* %5
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %49
%75 = load i64, i64* %5
%76 = mul i64 %75, 1048
%77 = udiv i64 419430400, %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %77)
br label %79
79: ; preds = %74, %49
%80 = load i8*, i8** %6
%81 = icmp ne i8* %80, null
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i8*, i8** %6
%84 = call i32 @free(i8* %83)
br label %85
85: ; preds = %82, %79
%86 = load i8*, i8** %7
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = load i8*, i8** %7
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %88, %85
store i32 0, i32* %1
br label %92
92: ; preds = %91, %47, %40
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@main.to = internal global [4096 x i8] zeroinitializer
@main.from = internal global [4096 x i8] zeroinitializer
@.str = [18 x i8] c"test last %ld ms\0A\00"
@.str.1 = [24 x i8] c"performance is %ldMB/s\0A\00"
@.str.4 = [26 x i8] c"dynamic test last %ld ms\0A\00"
@.str.5 = [33 x i8] c"dynamic performance is %ld MB/s\0A\00"
@str = [15 x i8] c"malloc fail 2 \00"
@str.6 = [14 x i8] c"malloc fail 1\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timezone* %3 to i8*
%7 = tail call i32 @memset(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0), i32 1, i32 4096)
%8 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %3)
%9 = tail call i32 @run_test(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.to, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0))
%10 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = sub nsw i32 %12, %14
%16 = mul nsw i32 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%20 = load i32, i32* %19
%21 = sub nsw i32 %18, %20
%22 = sdiv i32 %21, 1000
%23 = add nsw i32 %22, %16
%24 = sext i32 %23 to i64
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = icmp eq i32 %23, 0
br i1 %26, label %31, label %27
27: ; preds = %0
%28 = mul nsw i64 %24, 1048
%29 = udiv i64 419430400, %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %29)
br label %31
31: ; preds = %27, %0
%32 = tail call i64 @malloc(i32 4096)
%33 = inttoptr i64 %32 to i8*
%34 = icmp eq i64 %32, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %67
37: ; preds = %31
%38 = tail call i64 @malloc(i32 4096)
%39 = inttoptr i64 %38 to i8*
%40 = icmp eq i64 %38, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %67
43: ; preds = %37
%44 = tail call i32 @memset(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @main.from, i64 0, i64 0), i32 1, i32 4096)
%45 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %3)
%46 = tail call i32 @run_test_d(i8* %33, i8* %39)
%47 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%48 = load i32, i32* %11
%49 = load i32, i32* %13
%50 = sub nsw i32 %48, %49
%51 = mul nsw i32 %50, 1000
%52 = load i32, i32* %17
%53 = load i32, i32* %19
%54 = sub nsw i32 %52, %53
%55 = sdiv i32 %54, 1000
%56 = add nsw i32 %55, %51
%57 = sext i32 %56 to i64
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 %57)
%59 = icmp eq i32 %56, 0
br i1 %59, label %64, label %60
60: ; preds = %43
%61 = mul nsw i64 %57, 1048
%62 = udiv i64 419430400, %61
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %62)
br label %64
64: ; preds = %43, %60
%65 = tail call i32 @free(i8* %33)
%66 = tail call i32 @free(i8* %39)
br label %67
67: ; preds = %64, %41, %35
%68 = phi i32 [ -1, %35 ], [ -1, %41 ], [ 0, %64 ]
ret i32 %68
}