#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 */
scalar_t__ lockfree_align_test(char *);
scalar_t__ lockfree_basic_test(char *);
scalar_t__ lockfree_large_test(char *);
scalar_t__ lockfree_near_test(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ setmemrange(unsigned long, unsigned long);
int main(int argc, char *argv[]) {
  int rc = 0;
  unsigned long a4k, b4k, c4k;
  char a[(65536 + 65536)], b[(65536 + 65536)];
  char *source_address, *dest_address;
  memset(a, 0, (65536 + 65536));
  memset(b, 0, (65536 + 65536));
  a4k = (unsigned long)(a + (65536 - 1)) & ~(65536 - 1);
  b4k = (unsigned long)(b + (65536 - 1)) & ~(65536 - 1);
  if (a4k > b4k) {
    c4k = a4k;
    a4k = b4k;
    b4k = c4k;
  }
  source_address = (char *)a4k;
  dest_address = (char *)b4k;
  printf("source_address=%p, dest_address=%p\n", source_address, dest_address);
  rc += lockfree_basic_test(source_address);
  rc += lockfree_align_test(source_address);
  setmemrange(a4k, b4k + 65536);
  rc += lockfree_near_test(source_address);
  setmemrange(a4k, b4k + 65536);
  rc += lockfree_large_test(source_address);
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x20030(%rbp),%rdi
xor    %esi,%esi
mov    $0x20000,%edx
call   1090 <memset@plt>
lea    -0x40030(%rbp),%rdi
xor    %esi,%esi
mov    $0x20000,%edx
call   1090 <memset@plt>
lea    -0x20030(%rbp),%rax
add    $0xffff,%rax
and    $0xffffffffffff0000,%rax
mov    %rax,-0x20(%rbp)
lea    -0x40030(%rbp),%rax
add    $0xffff,%rax
and    $0xffffffffffff0000,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    120a <main+0x9a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40038(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40040(%rbp)
mov    -0x40038(%rbp),%rsi
mov    -0x40040(%rbp),%rdx
lea    0xdcb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40038(%rbp),%rdi
call   1030 <lockfree_basic_test@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x40038(%rbp),%rdi
call   1040 <lockfree_align_test@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x10000,%rsi
call   1080 <setmemrange@plt>
mov    -0x40038(%rbp),%rdi
call   1050 <lockfree_near_test@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x10000,%rsi
call   1080 <setmemrange@plt>
mov    -0x40038(%rbp),%rdi
call   1070 <lockfree_large_test@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x40040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40008,%rsp
lea    0x20000(%rsp),%rdi
xor    %esi,%esi
mov    $0x20000,%edx
call   1090 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x20000,%edx
call   1090 <memset@plt>
lea    0x2ffff(%rsp),%rax
and    $0xffffffffffff0000,%rax
lea    0xffff(%rsp),%rbx
and    $0xffffffffffff0000,%rbx
cmp    %rbx,%rax
mov    %rbx,%r14
cmova  %rax,%r14
cmovbe %rax,%rbx
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <lockfree_basic_test@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <lockfree_align_test@plt>
mov    %rax,%r12
add    %r15d,%r12d
add    $0x10000,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <setmemrange@plt>
mov    %rbx,%rdi
call   1050 <lockfree_near_test@plt>
mov    %rax,%r15
add    %r12d,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <setmemrange@plt>
mov    %rbx,%rdi
call   1070 <lockfree_large_test@plt>
add    %r15d,%eax
add    $0x40008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"source_address=%p, dest_address=%p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [131072 x i8]
%11 = alloca [131072 x i8]
%12 = alloca i8*
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%14 = getelementptr inbounds [131072 x i8], [131072 x i8]* %10, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 131072)
%16 = getelementptr inbounds [131072 x i8], [131072 x i8]* %11, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 131072)
%18 = getelementptr inbounds [131072 x i8], [131072 x i8]* %10, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 65535
%20 = ptrtoint i8* %19 to i64
%21 = and i64 %20, -65536
store i64 %21, i64* %7
%22 = getelementptr inbounds [131072 x i8], [131072 x i8]* %11, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 65535
%24 = ptrtoint i8* %23 to i64
%25 = and i64 %24, -65536
store i64 %25, i64* %8
%26 = load i64, i64* %7
%27 = load i64, i64* %8
%28 = icmp ugt i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %2
%30 = load i64, i64* %7
store i64 %30, i64* %9
%31 = load i64, i64* %8
store i64 %31, i64* %7
%32 = load i64, i64* %9
store i64 %32, i64* %8
br label %33
33: ; preds = %29, %2
%34 = load i64, i64* %7
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %12
%36 = load i64, i64* %8
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %13
%38 = load i8*, i8** %12
%39 = load i8*, i8** %13
%40 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %39)
%41 = load i8*, i8** %12
%42 = call i64 @lockfree_basic_test(i8* %41)
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %6
%47 = load i8*, i8** %12
%48 = call i64 @lockfree_align_test(i8* %47)
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %6
%53 = load i64, i64* %7
%54 = load i64, i64* %8
%55 = add i64 %54, 65536
%56 = call i32 @setmemrange(i64 %53, i64 %55)
%57 = load i8*, i8** %12
%58 = call i64 @lockfree_near_test(i8* %57)
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = add nsw i64 %60, %58
%62 = trunc i64 %61 to i32
store i32 %62, i32* %6
%63 = load i64, i64* %7
%64 = load i64, i64* %8
%65 = add i64 %64, 65536
%66 = call i32 @setmemrange(i64 %63, i64 %65)
%67 = load i8*, i8** %12
%68 = call i64 @lockfree_large_test(i8* %67)
%69 = load i32, i32* %6
%70 = sext i32 %69 to i64
%71 = add nsw i64 %70, %68
%72 = trunc i64 %71 to i32
store i32 %72, i32* %6
%73 = load i32, i32* %6
ret i32 %73
}

LLVM IR (-O2):
@.str = [36 x i8] c"source_address=%p, dest_address=%p\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [131072 x i8]
%4 = alloca [131072 x i8]
%5 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [131072 x i8], [131072 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i32 0, i32 131072)
%8 = call i32 @memset(i8* %6, i32 0, i32 131072)
%9 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 65535
%10 = ptrtoint i8* %9 to i64
%11 = and i64 %10, -65536
%12 = getelementptr inbounds [131072 x i8], [131072 x i8]* %4, i64 0, i64 65535
%13 = ptrtoint i8* %12 to i64
%14 = and i64 %13, -65536
%15 = icmp ugt i64 %11, %14
%16 = select i1 %15, i64 %11, i64 %14
%17 = select i1 %15, i64 %14, i64 %11
%18 = inttoptr i64 %17 to i8*
%19 = inttoptr i64 %16 to i8*
%20 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
%21 = call i64 @lockfree_basic_test(i8* %18)
%22 = call i64 @lockfree_align_test(i8* %18)
%23 = add i64 %22, %21
%24 = add i64 %16, 65536
%25 = call i32 @setmemrange(i64 %17, i64 %24)
%26 = call i64 @lockfree_near_test(i8* %18)
%27 = add i64 %23, %26
%28 = call i32 @setmemrange(i64 %17, i64 %24)
%29 = call i64 @lockfree_large_test(i8* %18)
%30 = add i64 %27, %29
%31 = trunc i64 %30 to i32
ret i32 %31
}