#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 gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(unsigned long *, unsigned long *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sub_timeval(struct timeval *, struct timeval *);
int test_memcpy(unsigned long *usec) {
  struct timeval start, end;
  unsigned long val = 0;
  unsigned long i;
  int ret;
  ret = gettimeofday(&start, NULL);
  if (ret)
    goto err;
  for (i = 0; i < 9999999999UL; i++)
    memcpy(&val, &i, sizeof(long));
  ret = gettimeofday(&end, NULL);
  if (ret)
    goto err;
  sub_timeval(&end, &start);
  printf("memcpy(): sec %lu, usec %lu\n", end.tv_sec, end.tv_usec);
  *usec = end.tv_sec * 1000000 + end.tv_usec;
  if (val == 0)
    ret = -1;
  return ret;
err:
  perror("gettimeofday");
  return ret;
}


x86 assembly (clang, -O0):
<test_memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1183 <test_memcpy+0x33>
jmp    1231 <test_memcpy+0xe1>
movq   $0x0,-0x30(%rbp)
movabs $0x2540be3ff,%rax
cmp    %rax,-0x30(%rbp)
jae    11c2 <test_memcpy+0x72>
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    118b <test_memcpy+0x3b>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11e1 <test_memcpy+0x91>
jmp    1231 <test_memcpy+0xe1>
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <sub_timeval@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
imul   $0xf4240,-0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    1226 <test_memcpy+0xd6>
movl   $0xffffffff,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <test_memcpy+0xf3>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memcpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movq   $0x0,0x18(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %eax,%eax
jne    1222 <test_memcpy+0xd2>
movq   $0x0,0x10(%rsp)
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%rbx
movabs $0x2540be3ff,%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    0x10(%rsp),%rax
add    $0x1,%rax
mov    %rax,0x10(%rsp)
cmp    %rbp,%rax
jb     11a0 <test_memcpy+0x50>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %eax,%eax
jne    1222 <test_memcpy+0xd2>
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1030 <sub_timeval@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
mov    %rcx,(%r14)
cmpq   $0x1,0x18(%rsp)
sbb    %ebp,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
jmp    1215 <test_memcpy+0xc5>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [29 x i8] c"memcpy(): sec %lu, usec %lu\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
define i32 @test_memcpy(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i64* %0, i64** %3
store i64 0, i64* %6
%9 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
br label %47
13: ; preds = %1
store i64 0, i64* %7
br label %14
14: ; preds = %19, %13
%15 = load i64, i64* %7
%16 = icmp ult i64 %15, 9999999999
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 @memcpy(i64* %6, i64* %7, i32 8)
br label %19
19: ; preds = %17
%20 = load i64, i64* %7
%21 = add i64 %20, 1
store i64 %21, i64* %7
br label %14
22: ; preds = %14
%23 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %47
27: ; preds = %22
%28 = call i32 @sub_timeval(%struct.timeval* %5, %struct.timeval* %4)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %32)
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%35 = load i32, i32* %34
%36 = mul nsw i32 %35, 1000000
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%38 = load i32, i32* %37
%39 = add nsw i32 %36, %38
%40 = sext i32 %39 to i64
%41 = load i64*, i64** %3
store i64 %40, i64* %41
%42 = load i64, i64* %6
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %27
store i32 -1, i32* %8
br label %45
45: ; preds = %44, %27
%46 = load i32, i32* %8
store i32 %46, i32* %2
br label %50
47: ; preds = %26, %12
%48 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* %8
store i32 %49, i32* %2
br label %50
50: ; preds = %47, %45
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [29 x i8] c"memcpy(): sec %lu, usec %lu\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
define i32 @test_memcpy(i64* nocapture writeonly %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
%6 = bitcast %struct.timeval* %2 to i8*
%7 = bitcast %struct.timeval* %3 to i8*
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = bitcast i64* %5 to i8*
%10 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %36
12: ; preds = %1
store i64 0, i64* %5
br label %13
13: ; preds = %12, %13
%14 = call i32 @memcpy(i64* %4, i64* %5, i32 8)
%15 = load i64, i64* %5
%16 = add i64 %15, 1
store i64 %16, i64* %5
%17 = icmp ult i64 %16, 9999999999
br i1 %17, label %13, label %18
18: ; preds = %13
%19 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = call i32 @sub_timeval(%struct.timeval* %3, %struct.timeval* %2)
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %26)
%28 = load i32, i32* %23
%29 = mul nsw i32 %28, 1000000
%30 = load i32, i32* %25
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
store i64 %32, i64* %0
%33 = load i64, i64* %4
%34 = icmp eq i64 %33, 0
%35 = sext i1 %34 to i32
br label %39
36: ; preds = %18, %1
%37 = phi i32 [ %10, %1 ], [ %19, %18 ]
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %36, %21
%40 = phi i32 [ %37, %36 ], [ %35, %21 ]
ret i32 %40
}