#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*/ memcpy(void *, void *, size_t);
double mysecond();
int /*<<< orphan*/ printf(char *, double, size_t);
void char_copy3(uintptr_t rbuf, uintptr_t sbuf, size_t size) {
  size_t offset = 0;
  size_t block_size = 12288;
  double t = mysecond();
  while (offset < size) {
    size_t left = size - offset;
    memcpy((void *)(rbuf + offset), (void *)(sbuf + offset),
           (left < block_size ? left : block_size));
    offset += block_size;
  }
  t = mysecond() - t;
  printf("Blocked copy : AFTER Triad elapsed : %f size bytes : %lu \n", t,
         size);
}


x86 assembly (clang, -O0):
<char_copy3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x3000,-0x28(%rbp)
mov    $0x0,%al
call   1030 <mysecond@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11d7 <char_copy3+0xa7>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ad <char_copy3+0x7d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11b5 <char_copy3+0x85>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1160 <char_copy3+0x30>
mov    $0x0,%al
call   1030 <mysecond@plt>
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_copy3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <mysecond@plt>
movsd  %xmm0,(%rsp)
test   %r14,%r14
je     1197 <char_copy3+0x67>
xor    %ebx,%ebx
mov    $0x3000,%r13d
mov    %r14,%rdx
mov    %r14,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r12,%rbx,1),%rdi
lea    (%r15,%rbx,1),%rsi
sub    $0x3000,%rbp
cmovae %r13,%rdx
call   1050 <memcpy@plt>
add    $0x3000,%rbx
mov    %rbp,%rdx
cmp    %r14,%rbx
jb     1170 <char_copy3+0x40>
xor    %eax,%eax
call   1030 <mysecond@plt>
subsd  (%rsp),%xmm0
lea    0xe56(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"Blocked copy : AFTER Triad elapsed : %f size bytes : %lu \0A\00"
define void @char_copy3(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 12288, i64* %8
%11 = call double (...) @mysecond()
store double %11, double* %9
br label %12
12: ; preds = %35, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = sub i64 %17, %18
store i64 %19, i64* %10
%20 = load i64, i64* %4
%21 = load i64, i64* %7
%22 = add i64 %20, %21
%23 = inttoptr i64 %22 to i8*
%24 = load i64, i64* %5
%25 = load i64, i64* %7
%26 = add i64 %24, %25
%27 = inttoptr i64 %26 to i8*
%28 = load i64, i64* %10
%29 = load i64, i64* %8
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %16
%32 = load i64, i64* %10
br label %35
33: ; preds = %16
%34 = load i64, i64* %8
br label %35
35: ; preds = %33, %31
%36 = phi i64 [ %32, %31 ], [ %34, %33 ]
%37 = call i32 @memcpy(i8* %23, i8* %27, i64 %36)
%38 = load i64, i64* %8
%39 = load i64, i64* %7
%40 = add i64 %39, %38
store i64 %40, i64* %7
br label %12
41: ; preds = %12
%42 = call double (...) @mysecond()
%43 = load double, double* %9
%44 = fsub double %42, %43
store double %44, double* %9
%45 = load double, double* %9
%46 = load i64, i64* %6
%47 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), double %45, i64 %46)
ret void
}

LLVM IR (-O2):
@.str = [59 x i8] c"Blocked copy : AFTER Triad elapsed : %f size bytes : %lu \0A\00"
define void @char_copy3(i64 %0, i64 %1, i64 %2) {
%4 = tail call double (...) @mysecond()
%5 = icmp eq i64 %2, 0
br i1 %5, label %18, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %16, %6 ], [ 0, %3 ]
%8 = sub i64 %2, %7
%9 = add i64 %7, %0
%10 = inttoptr i64 %9 to i8*
%11 = add i64 %7, %1
%12 = inttoptr i64 %11 to i8*
%13 = icmp ult i64 %8, 12288
%14 = select i1 %13, i64 %8, i64 12288
%15 = tail call i32 @memcpy(i8* %10, i8* %12, i64 %14)
%16 = add i64 %7, 12288
%17 = icmp ult i64 %16, %2
br i1 %17, label %6, label %18
18: ; preds = %6, %3
%19 = tail call double (...) @mysecond()
%20 = fsub double %19, %4
%21 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), double %20, i64 %2)
ret void
}