#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*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int posix_memalign(void **, int, int);
int query_block_size();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ test_dcbzl_at(char *, char *, int);
int test_dcbzl(void) {
  int err;
  char *buffer = NULL;
  int buffer_size;
  int block_size;
  block_size = query_block_size();
  assert(block_size == 16 || block_size == 32 || block_size == 64 ||
         block_size == 128);
  buffer_size = 3 * block_size;
  err = posix_memalign((void **)&buffer, block_size, buffer_size);
  if (err) {
    fprintf(stderr, "posix_memalign() failed (err = %d [%s])\n", err,
            strerror(err));
    return err;
  }
  test_dcbzl_at(&buffer[block_size], buffer, block_size);
  fprintf(stdout,
          "Passed dcbzl test at aligned address within the test block.\n");
  test_dcbzl_at(&buffer[block_size + 1], buffer, block_size);
  fprintf(stdout, "Passed dcbzl test at un-aligned (1 modulo block_size) "
                  "address within the test block.\n");
  test_dcbzl_at(&buffer[2 * block_size - 1], buffer, block_size);
  fprintf(stdout, "Passed dcbzl test at un-aligned ((block_size - 1) modulo "
                  "block_size) address within the test block.\n");
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<test_dcbzl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <query_block_size@plt>
mov    %eax,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0x10,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11c4 <test_dcbzl+0x54>
mov    $0x1,%al
cmpl   $0x20,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11c4 <test_dcbzl+0x54>
mov    $0x1,%al
cmpl   $0x40,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     11c4 <test_dcbzl+0x54>
cmpl   $0x80,-0x18(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
imul   $0x3,-0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    -0x10(%rbp),%rdi
call   1080 <posix_memalign@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1230 <test_dcbzl+0xc0>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    %rax,%rcx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d5 <test_dcbzl+0x165>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <test_dcbzl_at@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <test_dcbzl_at@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <test_dcbzl_at@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_dcbzl>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1070 <query_block_size@plt>
mov    %eax,%ebx
lea    -0x10(%rbx),%eax
cmp    $0x30,%eax
ja     11a5 <test_dcbzl+0x35>
mov    $0x1,%edi
movabs $0x1000000010001,%rcx
bt     %rax,%rcx
jb     11b1 <test_dcbzl+0x41>
xor    %edi,%edi
cmp    $0x80,%ebx
sete   %dil
call   1040 <assert@plt>
lea    (%rbx,%rbx,2),%edx
mov    %rsp,%rdi
mov    %ebx,%esi
call   1080 <posix_memalign@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11f3 <test_dcbzl+0x83>
mov    0x2e10(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xe20(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1274 <test_dcbzl+0x104>
mov    (%rsp),%rsi
movslq %ebx,%r15
lea    (%rsi,%r15,1),%rdi
mov    %ebx,%edx
call   1060 <test_dcbzl_at@plt>
mov    0x2dcc(%rip),%r14
mov    (%r14),%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%rsi
lea    (%r15,%rsi,1),%rdi
add    $0x1,%rdi
mov    %ebx,%edx
call   1060 <test_dcbzl_at@plt>
mov    (%r14),%edi
lea    0xe2c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%rsi
mov    %ebx,%eax
add    %ebx,%eax
cltq
lea    (%rax,%rsi,1),%rdi
add    $0xffffffffffffffff,%rdi
mov    %ebx,%edx
call   1060 <test_dcbzl_at@plt>
mov    (%r14),%edi
lea    0xe58(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"posix_memalign() failed (err = %d [%s])\0A\00"
@stdout = global i32 0
@.str.1 = [61 x i8] c"Passed dcbzl test at aligned address within the test block.\0A\00"
@.str.2 = [86 x i8] c"Passed dcbzl test at un-aligned (1 modulo block_size) address within the test block.\0A\00"
@.str.3 = [101 x i8] c"Passed dcbzl test at un-aligned ((block_size - 1) modulo block_size) address within the test block.\0A\00"
define i32 @test_dcbzl() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* null, i8** %3
%6 = call i32 (...) @query_block_size()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 16
br i1 %8, label %18, label %9
9: ; preds = %0
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 32
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 64
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 128
br label %18
18: ; preds = %15, %12, %9, %0
%19 = phi i1 [ true, %12 ], [ true, %9 ], [ true, %0 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %5
%23 = mul nsw i32 3, %22
store i32 %23, i32* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = call i32 @posix_memalign(i8** %3, i32 %24, i32 %25)
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i32, i32* %2
%32 = load i32, i32* %2
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %31, i8* %33)
%35 = load i32, i32* %2
store i32 %35, i32* %1
br label %69
36: ; preds = %18
%37 = load i8*, i8** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %3
%42 = load i32, i32* %5
%43 = call i32 @test_dcbzl_at(i8* %40, i8* %41, i32 %42)
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%46 = load i8*, i8** %3
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
%51 = load i8*, i8** %3
%52 = load i32, i32* %5
%53 = call i32 @test_dcbzl_at(i8* %50, i8* %51, i32 %52)
%54 = load i32, i32* @stdout
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8*, i8** %3
%57 = load i32, i32* %5
%58 = mul nsw i32 2, %57
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %56, i64 %60
%62 = load i8*, i8** %3
%63 = load i32, i32* %5
%64 = call i32 @test_dcbzl_at(i8* %61, i8* %62, i32 %63)
%65 = load i32, i32* @stdout
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.3, i64 0, i64 0))
%67 = load i8*, i8** %3
%68 = call i32 @free(i8* %67)
store i32 0, i32* %1
br label %69
69: ; preds = %36, %29
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"posix_memalign() failed (err = %d [%s])\0A\00"
@stdout = global i32 0
@.str.1 = [61 x i8] c"Passed dcbzl test at aligned address within the test block.\0A\00"
@.str.2 = [86 x i8] c"Passed dcbzl test at un-aligned (1 modulo block_size) address within the test block.\0A\00"
@.str.3 = [101 x i8] c"Passed dcbzl test at un-aligned ((block_size - 1) modulo block_size) address within the test block.\0A\00"
define i32 @test_dcbzl() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = tail call i32 (...) @query_block_size()
switch i32 %3, label %4 [
i32 64, label %7
i32 32, label %7
i32 16, label %7
]
4: ; preds = %0
%5 = icmp eq i32 %3, 128
%6 = zext i1 %5 to i32
br label %7
7: ; preds = %0, %0, %0, %4
%8 = phi i32 [ 1, %0 ], [ %6, %4 ], [ 1, %0 ], [ 1, %0 ]
%9 = tail call i32 @assert(i32 %8)
%10 = mul nsw i32 %3, 3
%11 = call i32 @posix_memalign(i8** %1, i32 %3, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = call i8* @strerror(i32 %11)
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %15)
br label %41
17: ; preds = %7
%18 = load i8*, i8** %1
%19 = sext i32 %3 to i64
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = call i32 @test_dcbzl_at(i8* %20, i8* %18, i32 %3)
%22 = load i32, i32* @stdout
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %1
%25 = add nsw i32 %3, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = call i32 @test_dcbzl_at(i8* %27, i8* %24, i32 %3)
%29 = load i32, i32* @stdout
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.2, i64 0, i64 0))
%31 = load i8*, i8** %1
%32 = shl nsw i32 %3, 1
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = call i32 @test_dcbzl_at(i8* %35, i8* %31, i32 %3)
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.3, i64 0, i64 0))
%39 = load i8*, i8** %1
%40 = call i32 @free(i8* %39)
br label %41
41: ; preds = %17, %13
ret i32 %11
}