#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 atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
int fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ stderr;
double tick();
int /*<<< orphan*/ xmemcpy(char *, char *, int);
int main(int argc, char **argv) {
  if (argc < 3)
    return fputs("Usage: xmemcpy <reps> <bytes>\n", stderr);
  int nreps = atoi(argv[1]);
  int nbytes = atoi(argv[2]);
  if (nbytes > 9000)
    return fputs("nbytes too big\n", stderr);
  int i;
  static char src[9999], dst[9999];
  double t0 = tick();
  for (i = 0; i < nreps; ++i)
    memcpy(dst + (i & 63), src + (i & 127), nbytes);
  double t1 = tick();
  for (i = 0; i < nreps; ++i)
    xmemcpy(dst + (i & 63), src + (i & 127), nbytes);
  double t2 = tick();
  fprintf(stderr, "%.4g %.4g\n", t1 - t0, t2 - t1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119d <main+0x3d>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1050 <fputs@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <main+0x175>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2328,-0x18(%rbp)
jle    11e7 <main+0x87>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1050 <fputs@plt>
mov    %eax,-0x4(%rbp)
jmp    12d5 <main+0x175>
mov    $0x0,%al
call   1040 <tick@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1240 <main+0xe0>
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
cltq
lea    0x556b(%rip),%rdi
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
and    $0x7f,%eax
cltq
lea    0x2e49(%rip),%rsi
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fa <main+0x9a>
mov    $0x0,%al
call   1040 <tick@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1299 <main+0x139>
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
cltq
lea    0x5512(%rip),%rdi
add    %rax,%rdi
mov    -0x1c(%rbp),%eax
and    $0x7f,%eax
cltq
lea    0x2df0(%rip),%rsi
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <xmemcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1253 <main+0xf3>
mov    $0x0,%al
call   1040 <tick@plt>
movsd  %xmm0,-0x38(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x30(%rbp),%xmm1
lea    0xd66(%rip),%rsi
call   1060 <fprintf@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   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jg     1183 <main+0x23>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
jmp    11b2 <main+0x52>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%rbp),%rdi
call   1080 <atoi@plt>
cmp    $0x2329,%eax
jl     11c3 <main+0x63>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fputs@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <tick@plt>
test   %r12d,%r12d
movsd  %xmm0,0x8(%rsp)
jle    1251 <main+0xf1>
lea    0x55a0(%rip),%r14
lea    0x2e89(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
and    $0x3f,%edi
add    %r14,%rdi
mov    %ebx,%esi
and    $0x7f,%esi
add    %r15,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    11f0 <main+0x90>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <tick@plt>
test   %r12d,%r12d
movsd  %xmm0,(%rsp)
jle    125d <main+0xfd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
and    $0x3f,%edi
add    %r14,%rdi
mov    %ebx,%esi
and    $0x7f,%esi
add    %r15,%rsi
mov    %ebp,%edx
call   1030 <xmemcpy@plt>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1230 <main+0xd0>
jmp    125d <main+0xfd>
xor    %eax,%eax
call   1040 <tick@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <tick@plt>
movapd %xmm0,%xmm1
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
movsd  (%rsp),%xmm0
subsd  %xmm0,%xmm1
subsd  0x8(%rsp),%xmm0
lea    0xda8(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Usage: xmemcpy <reps> <bytes>\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"nbytes too big\0A\00"
@main.src = internal global [9999 x i8] zeroinitializer
@main.dst = internal global [9999 x i8] zeroinitializer
@.str.2 = [11 x i8] c"%.4g %.4g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %3
br label %81
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp sgt i32 %26, 9000
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = load i32, i32* @stderr
%30 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 %30, i32* %3
br label %81
31: ; preds = %17
%32 = call double (...) @tick()
store double %32, double* %9
store i32 0, i32* %8
br label %33
33: ; preds = %48, %31
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %51
37: ; preds = %33
%38 = load i32, i32* %8
%39 = and i32 %38, 63
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* getelementptr inbounds ([9999 x i8], [9999 x i8]* @main.dst, i64 0, i64 0), i64 %40
%42 = load i32, i32* %8
%43 = and i32 %42, 127
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* getelementptr inbounds ([9999 x i8], [9999 x i8]* @main.src, i64 0, i64 0), i64 %44
%46 = load i32, i32* %7
%47 = call i32 @memcpy(i8* %41, i8* %45, i32 %46)
br label %48
48: ; preds = %37
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %33
51: ; preds = %33
%52 = call double (...) @tick()
store double %52, double* %10
store i32 0, i32* %8
br label %53
53: ; preds = %68, %51
%54 = load i32, i32* %8
%55 = load i32, i32* %6
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %71
57: ; preds = %53
%58 = load i32, i32* %8
%59 = and i32 %58, 63
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* getelementptr inbounds ([9999 x i8], [9999 x i8]* @main.dst, i64 0, i64 0), i64 %60
%62 = load i32, i32* %8
%63 = and i32 %62, 127
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* getelementptr inbounds ([9999 x i8], [9999 x i8]* @main.src, i64 0, i64 0), i64 %64
%66 = load i32, i32* %7
%67 = call i32 @xmemcpy(i8* %61, i8* %65, i32 %66)
br label %68
68: ; preds = %57
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %53
71: ; preds = %53
%72 = call double (...) @tick()
store double %72, double* %11
%73 = load i32, i32* @stderr
%74 = load double, double* %10
%75 = load double, double* %9
%76 = fsub double %74, %75
%77 = load double, double* %11
%78 = load double, double* %10
%79 = fsub double %77, %78
%80 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %76, double %79)
store i32 0, i32* %3
br label %81
81: ; preds = %71, %28, %14
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [31 x i8] c"Usage: xmemcpy <reps> <bytes>\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"nbytes too big\0A\00"
@main.src = internal global [9999 x i8] zeroinitializer
@main.dst = internal global [9999 x i8] zeroinitializer
@.str.2 = [11 x i8] c"%.4g %.4g\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = icmp sgt i32 %13, 9000
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = tail call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %54
18: ; preds = %7
%19 = tail call double (...) @tick()
%20 = icmp sgt i32 %10, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call double (...) @tick()
br label %47
23: ; preds = %18, %23
%24 = phi i32 [ %32, %23 ], [ 0, %18 ]
%25 = and i32 %24, 63
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [9999 x i8], [9999 x i8]* @main.dst, i64 0, i64 %26
%28 = and i32 %24, 127
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [9999 x i8], [9999 x i8]* @main.src, i64 0, i64 %29
%31 = tail call i32 @memcpy(i8* %27, i8* %30, i32 %13)
%32 = add nuw nsw i32 %24, 1
%33 = icmp eq i32 %32, %10
br i1 %33, label %34, label %23
34: ; preds = %23
%35 = tail call double (...) @tick()
br i1 %20, label %36, label %47
36: ; preds = %34, %36
%37 = phi i32 [ %45, %36 ], [ 0, %34 ]
%38 = and i32 %37, 63
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [9999 x i8], [9999 x i8]* @main.dst, i64 0, i64 %39
%41 = and i32 %37, 127
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [9999 x i8], [9999 x i8]* @main.src, i64 0, i64 %42
%44 = tail call i32 @xmemcpy(i8* %40, i8* %43, i32 %13)
%45 = add nuw nsw i32 %37, 1
%46 = icmp eq i32 %45, %10
br i1 %46, label %47, label %36
47: ; preds = %36, %21, %34
%48 = phi double [ %22, %21 ], [ %35, %34 ], [ %35, %36 ]
%49 = tail call double (...) @tick()
%50 = load i32, i32* @stderr
%51 = fsub double %48, %19
%52 = fsub double %49, %48
%53 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), double %51, double %52)
br label %54
54: ; preds = %15, %47, %4
%55 = phi i32 [ %6, %4 ], [ %17, %15 ], [ 0, %47 ]
ret i32 %55
}