#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*/ check_assert(int, char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t const);
int posix_memalign(void **, int, size_t const);
void *cache_line_aligned_calloc(const size_t alloc_size) {
  const size_t aligned_size = ((alloc_size + 64 - 1) / 64) * 64;
  void *buffer = NULL;
  int rc;
  rc = posix_memalign(&buffer, 64, aligned_size);
  check_assert(rc == 0, "rc == 0");
  memset(buffer, 0, aligned_size);
  return buffer;
}


x86 assembly (clang, -O0):
<cache_line_aligned_calloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rax
sub    $0x1,%rax
shr    $0x6,%rax
shl    $0x6,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    $0x40,%esi
call   1050 <posix_memalign@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe7c(%rip),%rsi
call   1040 <check_assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_line_aligned_calloc>:
push   %rbx
sub    $0x10,%rsp
lea    0x3f(%rdi),%rbx
and    $0xffffffffffffffc0,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1050 <posix_memalign@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
lea    0xe99(%rip),%rsi
call   1040 <check_assert@plt>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"rc == 0\00"
define i8* @cache_line_aligned_calloc(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = add i64 %6, 64
%8 = sub i64 %7, 1
%9 = udiv i64 %8, 64
%10 = mul i64 %9, 64
store i64 %10, i64* %3
store i8* null, i8** %4
%11 = load i64, i64* %3
%12 = call i32 @posix_memalign(i8** %4, i32 64, i64 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @check_assert(i32 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = load i64, i64* %3
%19 = call i32 @memset(i8* %17, i32 0, i64 %18)
%20 = load i8*, i8** %4
ret i8* %20
}

LLVM IR (-O2):
@.str = [8 x i8] c"rc == 0\00"
define i8* @cache_line_aligned_calloc(i64 %0) {
%2 = alloca i8*
%3 = add i64 %0, 63
%4 = and i64 %3, -64
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = call i32 @posix_memalign(i8** %2, i32 64, i64 %4)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @check_assert(i32 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %2
%11 = call i32 @memset(i8* %10, i32 0, i64 %4)
%12 = load i8*, i8** %2
ret i8* %12
}