#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, float);
int test_deref(unsigned long *);
int test_memcpy(unsigned long *);
int main(void) {
  int j, ret;
  float overhead;
  for (j = 0; j < 3; j++) {
    unsigned long memcpy_usec, deref_usec;
    ret = test_memcpy(&memcpy_usec);
    if (ret)
      goto err;
    ret = test_deref(&deref_usec);
    if (ret)
      goto err;
    overhead = (float)memcpy_usec * 100 / (float)deref_usec - 100;
    printf("memcpy() overhead: %.1f%%\n", overhead);
  }
  return 0;
err:
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1254 <main+0x124>
lea    -0x18(%rbp),%rdi
call   1030 <test_memcpy@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     116b <main+0x3b>
jmp    1260 <main+0x130>
lea    -0x20(%rbp),%rdi
call   1040 <test_deref@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1186 <main+0x56>
jmp    1260 <main+0x130>
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x28(%rbp)
test   %rax,%rax
movss  %xmm0,-0x24(%rbp)
js     11c3 <main+0x93>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  0xe30(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x30(%rbp)
test   %rax,%rax
movss  %xmm0,-0x2c(%rbp)
js     1216 <main+0xe6>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x34(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xdd4(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <main+0x16>
movl   $0x0,-0x4(%rbp)
jmp    1267 <main+0x137>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1030 <test_memcpy@plt>
test   %eax,%eax
jne    127c <main+0x14c>
lea    0x8(%rsp),%rdi
call   1040 <test_deref@plt>
test   %eax,%eax
jne    127c <main+0x14c>
mov    0x10(%rsp),%rax
test   %rax,%rax
js     1169 <main+0x39>
cvtsi2ss %rax,%xmm0
jmp    117e <main+0x4e>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
mulss  0xe7a(%rip),%xmm0
mov    0x8(%rsp),%rax
test   %rax,%rax
js     1197 <main+0x67>
cvtsi2ss %rax,%xmm1
jmp    11ac <main+0x7c>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
addss  0xe4c(%rip),%xmm0
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
call   1030 <test_memcpy@plt>
test   %eax,%eax
jne    127c <main+0x14c>
lea    0x8(%rsp),%rdi
call   1040 <test_deref@plt>
test   %eax,%eax
jne    127c <main+0x14c>
mov    0x10(%rsp),%rax
test   %rax,%rax
js     11fc <main+0xcc>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
jmp    1214 <main+0xe4>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
mulss  0xde4(%rip),%xmm0
mov    0x8(%rsp),%rax
test   %rax,%rax
js     1230 <main+0x100>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
jmp    1248 <main+0x118>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
addss  0xdb0(%rip),%xmm0
lea    0xdad(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%rdi
call   1030 <test_memcpy@plt>
test   %eax,%eax
jne    127c <main+0x14c>
lea    0x8(%rsp),%rdi
call   1040 <test_deref@plt>
test   %eax,%eax
je     1286 <main+0x156>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
mov    0x10(%rsp),%rax
test   %rax,%rax
js     129a <main+0x16a>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
jmp    12b2 <main+0x182>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
mulss  0xd46(%rip),%xmm0
mov    0x8(%rsp),%rax
test   %rax,%rax
js     12ce <main+0x19e>
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
jmp    12e6 <main+0x1b6>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
addss  0xd12(%rip),%xmm0
lea    0xd0f(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"memcpy() overhead: %.1f%%\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %30, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %33
10: ; preds = %7
%11 = call i32 @test_memcpy(i64* %5)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br label %34
15: ; preds = %10
%16 = call i32 @test_deref(i64* %6)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %34
20: ; preds = %15
%21 = load i64, i64* %5
%22 = uitofp i64 %21 to float
%23 = fmul float %22, 1.000000e+02
%24 = load i64, i64* %6
%25 = uitofp i64 %24 to float
%26 = fdiv float %23, %25
%27 = fsub float %26, 1.000000e+02
store float %27, float* %4
%28 = load float, float* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), float %28)
br label %30
30: ; preds = %20
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %7
33: ; preds = %7
store i32 0, i32* %1
br label %35
34: ; preds = %19, %14
store i32 -1, i32* %1
br label %35
35: ; preds = %34, %33
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [27 x i8] c"memcpy() overhead: %.1f%%\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 @test_memcpy(i64* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %47
7: ; preds = %0
%8 = call i32 @test_deref(i64* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %47
10: ; preds = %7
%11 = load i64, i64* %1
%12 = uitofp i64 %11 to float
%13 = fmul float %12, 1.000000e+02
%14 = load i64, i64* %2
%15 = uitofp i64 %14 to float
%16 = fdiv float %13, %15
%17 = fadd float %16, -1.000000e+02
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), float %17)
%19 = call i32 @test_memcpy(i64* %1)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %47
21: ; preds = %10
%22 = call i32 @test_deref(i64* %2)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %47
24: ; preds = %21
%25 = load i64, i64* %1
%26 = uitofp i64 %25 to float
%27 = fmul float %26, 1.000000e+02
%28 = load i64, i64* %2
%29 = uitofp i64 %28 to float
%30 = fdiv float %27, %29
%31 = fadd float %30, -1.000000e+02
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), float %31)
%33 = call i32 @test_memcpy(i64* %1)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %47
35: ; preds = %24
%36 = call i32 @test_deref(i64* %2)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = load i64, i64* %1
%40 = uitofp i64 %39 to float
%41 = fmul float %40, 1.000000e+02
%42 = load i64, i64* %2
%43 = uitofp i64 %42 to float
%44 = fdiv float %41, %43
%45 = fadd float %44, -1.000000e+02
%46 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), float %45)
br label %48
47: ; preds = %35, %24, %21, %10, %0, %7
br label %48
48: ; preds = %38, %47
%49 = phi i32 [ -1, %47 ], [ 0, %38 ]
ret i32 %49
}