#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 */
typedef int ptrdiff_t;

/* Variables and functions */
size_t SIZE_MAX;
scalar_t__ malloc(unsigned long long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/,
                          unsigned long long);
scalar_t__ rand();
unsigned char *alignedcalloc(unsigned long long len) {
  unsigned char *aligned;
  unsigned char *unaligned;
  size_t i;
  if (SIZE_MAX - (size_t)256U < len ||
      (unaligned = (unsigned char *)malloc(len + (size_t)256U)) == NULL) {
    return NULL;
  }
  for (i = (size_t)0U; i < len + (size_t)256U; ++i) {
    unaligned[i] = (unsigned char)rand();
  }
  aligned = unaligned + 64;
  aligned += (ptrdiff_t)63 & (-(ptrdiff_t)aligned);
  memset(aligned, 0, len);
  return aligned;
}


x86 assembly (clang, -O0):
<alignedcalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
sub    $0x100,%rax
cmp    -0x10(%rbp),%rax
jb     1174 <alignedcalloc+0x44>
mov    -0x10(%rbp),%rdi
add    $0x100,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1181 <alignedcalloc+0x51>
movq   $0x0,-0x8(%rbp)
jmp    1202 <alignedcalloc+0xd2>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x100,%rcx
cmp    %rcx,%rax
jae    11c6 <alignedcalloc+0x96>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1189 <alignedcalloc+0x59>
mov    -0x20(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
xor    %ecx,%ecx
sub    %eax,%ecx
and    $0x3f,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alignedcalloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e99(%rip),%rax
mov    $0xffffffffffffff00,%rcx
add    (%rax),%rcx
cmp    %rdi,%rcx
jb     11a4 <alignedcalloc+0x74>
mov    %rdi,%r14
lea    0x100(%rdi),%r12
mov    %r12,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     11a4 <alignedcalloc+0x74>
mov    %rax,%r15
test   %r12,%r12
je     1184 <alignedcalloc+0x54>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1050 <rand@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <alignedcalloc+0x40>
lea    0x40(%r15),%rax
neg    %eax
and    $0x3f,%eax
lea    (%r15,%rax,1),%rbx
add    $0x40,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
jmp    11a6 <alignedcalloc+0x76>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIZE_MAX = global i64 0
define i8* @alignedcalloc(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i64 %0, i64* %3
%7 = load i64, i64* @SIZE_MAX
%8 = sub i64 %7, 256
%9 = load i64, i64* %3
%10 = icmp ult i64 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %1
%12 = load i64, i64* %3
%13 = add i64 %12, 256
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %11, %1
store i8* null, i8** %2
br label %47
18: ; preds = %11
store i64 0, i64* %6
br label %19
19: ; preds = %30, %18
%20 = load i64, i64* %6
%21 = load i64, i64* %3
%22 = add i64 %21, 256
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = call i64 (...) @rand()
%26 = trunc i64 %25 to i8
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %24
%31 = load i64, i64* %6
%32 = add i64 %31, 1
store i64 %32, i64* %6
br label %19
33: ; preds = %19
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 64
store i8* %35, i8** %4
%36 = load i8*, i8** %4
%37 = ptrtoint i8* %36 to i32
%38 = sub nsw i32 0, %37
%39 = and i32 63, %38
%40 = load i8*, i8** %4
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = load i64, i64* %3
%45 = call i32 @memset(i8* %43, i32 0, i64 %44)
%46 = load i8*, i8** %4
store i8* %46, i8** %2
br label %47
47: ; preds = %33, %17
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
@SIZE_MAX = global i64 0
define i8* @alignedcalloc(i64 %0) {
%2 = load i64, i64* @SIZE_MAX
%3 = add i64 %2, -256
%4 = icmp ult i64 %3, %0
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = add i64 %0, 256
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %26, label %10
10: ; preds = %5
%11 = icmp eq i64 %6, 0
br i1 %11, label %19, label %12
12: ; preds = %10, %12
%13 = phi i64 [ %17, %12 ], [ 0, %10 ]
%14 = tail call i64 (...) @rand()
%15 = trunc i64 %14 to i8
%16 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 %15, i8* %16
%17 = add nuw i64 %13, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %19, label %12
19: ; preds = %12, %10
%20 = getelementptr inbounds i8, i8* %8, i64 64
%21 = ptrtoint i8* %20 to i64
%22 = sub i64 0, %21
%23 = and i64 %22, 63
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = tail call i32 @memset(i8* %24, i32 0, i64 %0)
br label %26
26: ; preds = %1, %5, %19
%27 = phi i8* [ %24, %19 ], [ null, %5 ], [ null, %1 ]
ret i8* %27
}