#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*/ do_one(char *, char *, unsigned long, unsigned long,
                          unsigned long, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
char *memalign(int, int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ stderr;
int test_copy_loop(void) {
  char *src, *dst, *redzone, *fill;
  unsigned long len, src_off, dst_off;
  unsigned long i;
  src = memalign((8192 + 16 + 2 * 128), (8192 + 16 + 2 * 128));
  dst = memalign((8192 + 16 + 2 * 128), (8192 + 16 + 2 * 128));
  redzone = malloc((8192 + 16 + 2 * 128));
  fill = malloc((8192 + 16 + 2 * 128));
  if (!src || !dst || !redzone || !fill) {
    fprintf(stderr, "malloc failed\n");
    exit(1);
  }
  memset(redzone, 0xa5, (8192 + 16 + 2 * 128));
  for (i = 0; i < (8192 + 16 + 2 * 128); i++)
    fill[i] = i & 0xff;
  for (len = 1; len < 8192; len++) {
    for (src_off = 0; src_off < 16; src_off++) {
      for (dst_off = 0; dst_off < 16; dst_off++) {
        do_one(src, dst, src_off, dst_off, len, redzone, fill);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_copy_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x2110,%esi
mov    %esi,%edi
call   1050 <memalign@plt>
mov    %rax,-0x8(%rbp)
mov    $0x2110,%esi
mov    %esi,%edi
call   1050 <memalign@plt>
mov    %rax,-0x10(%rbp)
mov    $0x2110,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x2110,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d0 <test_copy_loop+0x70>
cmpq   $0x0,-0x10(%rbp)
je     11d0 <test_copy_loop+0x70>
cmpq   $0x0,-0x18(%rbp)
je     11d0 <test_copy_loop+0x70>
cmpq   $0x0,-0x20(%rbp)
jne    11ef <test_copy_loop+0x8f>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    $0xa5,%esi
mov    $0x2110,%edx
call   1030 <memset@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x2110,-0x40(%rbp)
jae    1240 <test_copy_loop+0xe0>
mov    -0x40(%rbp),%rax
and    $0xff,%rax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    120a <test_copy_loop+0xaa>
movq   $0x1,-0x28(%rbp)
cmpq   $0x2000,-0x28(%rbp)
jae    12de <test_copy_loop+0x17e>
movq   $0x0,-0x30(%rbp)
cmpq   $0x10,-0x30(%rbp)
jae    12c8 <test_copy_loop+0x168>
movq   $0x0,-0x38(%rbp)
cmpq   $0x10,-0x38(%rbp)
jae    12b2 <test_copy_loop+0x152>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1070 <do_one@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1271 <test_copy_loop+0x111>
jmp    12b7 <test_copy_loop+0x157>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    125e <test_copy_loop+0xfe>
jmp    12cd <test_copy_loop+0x16d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1248 <test_copy_loop+0xe8>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_copy_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x2110,%edi
mov    $0x2110,%esi
call   1050 <memalign@plt>
mov    %rax,%r14
mov    $0x2110,%edi
mov    $0x2110,%esi
call   1050 <memalign@plt>
mov    %rax,%r15
mov    $0x2110,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x2110,%edi
call   1060 <malloc@plt>
test   %r14,%r14
je     14cd <test_copy_loop+0x36d>
test   %r15,%r15
je     14cd <test_copy_loop+0x36d>
test   %r12,%r12
je     14cd <test_copy_loop+0x36d>
mov    %rax,%r13
test   %rax,%rax
je     14cd <test_copy_loop+0x36d>
mov    %r12,%rdi
mov    $0xa5,%esi
mov    $0x2110,%edx
call   1030 <memset@plt>
movdqa 0xe19(%rip),%xmm2
mov    $0x70,%eax
movdqa 0xe1b(%rip),%xmm8
movdqa 0xe22(%rip),%xmm9
movdqa 0xe2a(%rip),%xmm3
movdqa 0xe32(%rip),%xmm4
movdqa 0xe3a(%rip),%xmm5
movdqa 0xe42(%rip),%xmm6
movdqa 0xe4a(%rip),%xmm7
movdqa 0xe52(%rip),%xmm1
xchg   %ax,%ax
movdqu %xmm2,-0x70(%r13,%rax,1)
cmp    $0x2170,%rax
je     12b7 <test_copy_loop+0x157>
movdqa %xmm2,%xmm0
paddb  %xmm8,%xmm0
movdqu %xmm0,-0x60(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm9,%xmm0
movdqu %xmm0,-0x50(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm3,%xmm0
movdqu %xmm0,-0x40(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm4,%xmm0
movdqu %xmm0,-0x30(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm5,%xmm0
movdqu %xmm0,-0x20(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm6,%xmm0
movdqu %xmm0,-0x10(%r13,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm7,%xmm0
movdqu %xmm0,0x0(%r13,%rax,1)
pxor   %xmm1,%xmm2
sub    $0xffffffffffffff80,%rax
jmp    1230 <test_copy_loop+0xd0>
mov    $0x1,%ebx
nopl   0x0(%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x1,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x2,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x3,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x4,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x5,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x6,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x7,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x8,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0x9,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xa,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xb,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xc,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xd,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xe,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
mov    %r13,(%rsp)
mov    $0xf,%ecx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%r8
mov    %r12,%r9
call   1070 <do_one@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
jne    12d0 <test_copy_loop+0x170>
add    $0x1,%rbx
cmp    $0x2000,%rbx
jne    12c0 <test_copy_loop+0x160>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b0c(%rip),%rax
mov    (%rax),%edi
lea    0xbb3(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
define i32 @test_copy_loop() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = call i8* @memalign(i32 8464, i32 8464)
store i8* %9, i8** %1
%10 = call i8* @memalign(i32 8464, i32 8464)
store i8* %10, i8** %2
%11 = call i8* @malloc(i32 8464)
store i8* %11, i8** %3
%12 = call i8* @malloc(i32 8464)
store i8* %12, i8** %4
%13 = load i8*, i8** %1
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %28, label %24
24: ; preds = %21, %18, %15, %0
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = load i8*, i8** %3
%30 = call i32 @memset(i8* %29, i32 165, i32 8464)
store i64 0, i64* %8
br label %31
31: ; preds = %41, %28
%32 = load i64, i64* %8
%33 = icmp ult i64 %32, 8464
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i64, i64* %8
%36 = and i64 %35, 255
%37 = trunc i64 %36 to i8
%38 = load i8*, i8** %4
%39 = load i64, i64* %8
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %34
%42 = load i64, i64* %8
%43 = add i64 %42, 1
store i64 %43, i64* %8
br label %31
44: ; preds = %31
store i64 1, i64* %5
br label %45
45: ; preds = %73, %44
%46 = load i64, i64* %5
%47 = icmp ult i64 %46, 8192
br i1 %47, label %48, label %76
48: ; preds = %45
store i64 0, i64* %6
br label %49
49: ; preds = %69, %48
%50 = load i64, i64* %6
%51 = icmp ult i64 %50, 16
br i1 %51, label %52, label %72
52: ; preds = %49
store i64 0, i64* %7
br label %53
53: ; preds = %65, %52
%54 = load i64, i64* %7
%55 = icmp ult i64 %54, 16
br i1 %55, label %56, label %68
56: ; preds = %53
%57 = load i8*, i8** %1
%58 = load i8*, i8** %2
%59 = load i64, i64* %6
%60 = load i64, i64* %7
%61 = load i64, i64* %5
%62 = load i8*, i8** %3
%63 = load i8*, i8** %4
%64 = call i32 @do_one(i8* %57, i8* %58, i64 %59, i64 %60, i64 %61, i8* %62, i8* %63)
br label %65
65: ; preds = %56
%66 = load i64, i64* %7
%67 = add i64 %66, 1
store i64 %67, i64* %7
br label %53
68: ; preds = %53
br label %69
69: ; preds = %68
%70 = load i64, i64* %6
%71 = add i64 %70, 1
store i64 %71, i64* %6
br label %49
72: ; preds = %49
br label %73
73: ; preds = %72
%74 = load i64, i64* %5
%75 = add i64 %74, 1
store i64 %75, i64* %5
br label %45
76: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
define i32 @test_copy_loop() {
%1 = tail call dereferenceable_or_null(8464) i8* @memalign(i32 8464, i32 8464)
%2 = tail call dereferenceable_or_null(8464) i8* @memalign(i32 8464, i32 8464)
%3 = tail call dereferenceable_or_null(8464) i8* @malloc(i32 8464)
%4 = tail call dereferenceable_or_null(8464) i8* @malloc(i32 8464)
%5 = icmp ne i8* %1, null
%6 = icmp ne i8* %2, null
%7 = and i1 %5, %6
%8 = icmp ne i8* %3, null
%9 = and i1 %7, %8
%10 = icmp ne i8* %4, null
%11 = and i1 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = tail call i32 @memset(i8* %3, i32 165, i32 8464)
br label %18
18: ; preds = %25, %16
%19 = phi i64 [ 0, %16 ], [ %53, %25 ]
%20 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %16 ], [ %54, %25 ]
%21 = getelementptr inbounds i8, i8* %4, i64 %19
%22 = bitcast i8* %21 to <16 x i8>*
store <16 x i8> %20, <16 x i8>* %22
%23 = or i64 %19, 16
%24 = icmp eq i64 %23, 8464
br i1 %24, label %55, label %25
25: ; preds = %18
%26 = add <16 x i8> %20, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%27 = getelementptr inbounds i8, i8* %4, i64 %23
%28 = bitcast i8* %27 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %28
%29 = or i64 %19, 32
%30 = add <16 x i8> %20, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%31 = getelementptr inbounds i8, i8* %4, i64 %29
%32 = bitcast i8* %31 to <16 x i8>*
store <16 x i8> %30, <16 x i8>* %32
%33 = or i64 %19, 48
%34 = add <16 x i8> %20, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%35 = getelementptr inbounds i8, i8* %4, i64 %33
%36 = bitcast i8* %35 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %36
%37 = or i64 %19, 64
%38 = add <16 x i8> %20, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%39 = getelementptr inbounds i8, i8* %4, i64 %37
%40 = bitcast i8* %39 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %40
%41 = or i64 %19, 80
%42 = add <16 x i8> %20, <i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80>
%43 = getelementptr inbounds i8, i8* %4, i64 %41
%44 = bitcast i8* %43 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %44
%45 = or i64 %19, 96
%46 = add <16 x i8> %20, <i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96>
%47 = getelementptr inbounds i8, i8* %4, i64 %45
%48 = bitcast i8* %47 to <16 x i8>*
store <16 x i8> %46, <16 x i8>* %48
%49 = or i64 %19, 112
%50 = add <16 x i8> %20, <i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112>
%51 = getelementptr inbounds i8, i8* %4, i64 %49
%52 = bitcast i8* %51 to <16 x i8>*
store <16 x i8> %50, <16 x i8>* %52
%53 = add nuw nsw i64 %19, 128
%54 = xor <16 x i8> %20, <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
br label %18
55: ; preds = %18, %77
%56 = phi i64 [ %78, %77 ], [ 1, %18 ]
br label %57
57: ; preds = %55, %57
%58 = phi i64 [ 0, %55 ], [ %75, %57 ]
%59 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 0, i64 %56, i8* %3, i8* %4)
%60 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 1, i64 %56, i8* %3, i8* %4)
%61 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 2, i64 %56, i8* %3, i8* %4)
%62 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 3, i64 %56, i8* %3, i8* %4)
%63 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 4, i64 %56, i8* %3, i8* %4)
%64 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 5, i64 %56, i8* %3, i8* %4)
%65 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 6, i64 %56, i8* %3, i8* %4)
%66 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 7, i64 %56, i8* %3, i8* %4)
%67 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 8, i64 %56, i8* %3, i8* %4)
%68 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 9, i64 %56, i8* %3, i8* %4)
%69 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 10, i64 %56, i8* %3, i8* %4)
%70 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 11, i64 %56, i8* %3, i8* %4)
%71 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 12, i64 %56, i8* %3, i8* %4)
%72 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 13, i64 %56, i8* %3, i8* %4)
%73 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 14, i64 %56, i8* %3, i8* %4)
%74 = tail call i32 @do_one(i8* %1, i8* %2, i64 %58, i64 15, i64 %56, i8* %3, i8* %4)
%75 = add nuw nsw i64 %58, 1
%76 = icmp eq i64 %75, 16
br i1 %76, label %77, label %57
77: ; preds = %57
%78 = add nuw nsw i64 %56, 1
%79 = icmp eq i64 %78, 8192
br i1 %79, label %80, label %55
80: ; preds = %77
ret i32 0
}