#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 */
char *Allocate(int, int);
int /*<<< orphan*/ CheckBuf(char *, int);
int /*<<< orphan*/ CheckZeroBuf(char *, int);
int /*<<< orphan*/ CopyWithXmm(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int main() {
  char *p1;
  char *p2;
  int i;
  p1 = Allocate(1024, 16);
  p2 = Allocate(1024, 16);
  printf("p1 = %p, p2 = %p\n", p1, p2);
  for (i = 0; i < 1024; i++)
    p1[i] = "abcdefghijklmnopqrstuvwxyz"[i % 26];
  memcpy(p2, p1, 1024);
  CheckBuf(p2, 1024);
  memset(p2, 0, 1024);
  CheckZeroBuf(p2, 1024);
  CopyWithXmm(p2, p1, 1024);
  CheckBuf(p2, 1024);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x400,%edi
mov    $0x10,%esi
call   1070 <Allocate@plt>
mov    %rax,-0x10(%rbp)
mov    $0x400,%edi
mov    $0x10,%esi
call   1070 <Allocate@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jge    11fe <main+0x8e>
mov    -0x1c(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe30(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c0 <main+0x50>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1090 <CheckBuf@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1040 <CheckZeroBuf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1080 <CopyWithXmm@plt>
mov    -0x18(%rbp),%rdi
mov    $0x400,%esi
call   1090 <CheckBuf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x400,%edi
mov    $0x10,%esi
call   1070 <Allocate@plt>
mov    %rax,%rbx
mov    $0x400,%edi
mov    $0x10,%esi
call   1070 <Allocate@plt>
mov    %rax,%r14
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %ecx,%ecx
movabs $0x4ec4ec4ec4ec4ec5,%rsi
ec c4 4e
lea    0xe55(%rip),%rdi
nopl   (%rax)
mov    %rcx,%rax
mul    %rsi
shr    $0x3,%rdx
imul   $0xffffffffffffffe6,%rdx,%rax
add    %rdi,%rax
movzwl (%rcx,%rax,1),%eax
mov    %ax,(%rbx,%rcx,1)
add    $0x2,%rcx
cmp    $0x400,%rcx
jne    11c0 <main+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <memcpy@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   1090 <CheckBuf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <CheckZeroBuf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <CopyWithXmm@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   1090 <CheckBuf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"p1 = %p, p2 = %p\0A\00"
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i8* @Allocate(i32 1024, i32 16)
store i8* %5, i8** %2
%6 = call i8* @Allocate(i32 1024, i32 16)
store i8* %6, i8** %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %3
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
store i32 0, i32* %4
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1024
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %4
%15 = srem i32 %14, 26
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [27 x i8], [27 x i8]* @.str.1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = load i8*, i8** %2
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %10
26: ; preds = %10
%27 = load i8*, i8** %3
%28 = load i8*, i8** %2
%29 = call i32 @memcpy(i8* %27, i8* %28, i32 1024)
%30 = load i8*, i8** %3
%31 = call i32 @CheckBuf(i8* %30, i32 1024)
%32 = load i8*, i8** %3
%33 = call i32 @memset(i8* %32, i32 0, i32 1024)
%34 = load i8*, i8** %3
%35 = call i32 @CheckZeroBuf(i8* %34, i32 1024)
%36 = load i8*, i8** %3
%37 = load i8*, i8** %2
%38 = call i32 @CopyWithXmm(i8* %36, i8* %37, i32 1024)
%39 = load i8*, i8** %3
%40 = call i32 @CheckBuf(i8* %39, i32 1024)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"p1 = %p, p2 = %p\0A\00"
@.str.1 = [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
define i32 @main() {
%1 = tail call i8* @Allocate(i32 1024, i32 16)
%2 = tail call i8* @Allocate(i32 1024, i32 16)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ 0, %0 ], [ %19, %4 ]
%6 = trunc i64 %5 to i16
%7 = urem i16 %6, 26
%8 = zext i16 %7 to i64
%9 = getelementptr inbounds [27 x i8], [27 x i8]* @.str.1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 %10, i8* %11
%12 = or i64 %5, 1
%13 = trunc i64 %12 to i16
%14 = urem i16 %13, 26
%15 = zext i16 %14 to i64
%16 = getelementptr inbounds [27 x i8], [27 x i8]* @.str.1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %17, i8* %18
%19 = add nuw nsw i64 %5, 2
%20 = icmp eq i64 %19, 1024
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = tail call i32 @memcpy(i8* %2, i8* %1, i32 1024)
%23 = tail call i32 @CheckBuf(i8* %2, i32 1024)
%24 = tail call i32 @memset(i8* %2, i32 0, i32 1024)
%25 = tail call i32 @CheckZeroBuf(i8* %2, i32 1024)
%26 = tail call i32 @CopyWithXmm(i8* %2, i8* %1, i32 1024)
%27 = tail call i32 @CheckBuf(i8* %2, i32 1024)
ret i32 0
}