#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 size;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int posix_memalign(void **, int, int);
int /*<<< orphan*/ stderr;
int cmalloc(void **ptr, int size) {
  int rc = -1;
  size = (((size) + (16) - 1) & ~((16) - 1));
  rc = posix_memalign(ptr, 16, size);
  if (rc < 0 || *ptr == NULL) {
    fprintf(stderr, "alloc error\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x10,%eax
sub    $0x1,%eax
and    $0xfffffff0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x10,%esi
call   1040 <posix_memalign@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1171 <cmalloc+0x51>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1192 <cmalloc+0x72>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <cmalloc+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmalloc>:
push   %rbx
mov    %rdi,%rbx
lea    0xf(%rsi),%edx
and    $0xfffffff0,%edx
mov    $0x10,%esi
call   1040 <posix_memalign@plt>
test   %eax,%eax
js     1142 <cmalloc+0x22>
xor    %eax,%eax
cmpq   $0x0,(%rbx)
je     1142 <cmalloc+0x22>
pop    %rbx
ret
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"alloc error\0A\00"
define i32 @cmalloc(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 -1, i32* %6
%7 = load i32, i32* %5
%8 = add nsw i32 %7, 16
%9 = sub nsw i32 %8, 1
%10 = and i32 %9, -16
store i32 %10, i32* %5
%11 = load i8**, i8*** %4
%12 = load i32, i32* %5
%13 = call i32 @posix_memalign(i8** %11, i32 16, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16, %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
23: ; preds = %16
store i32 0, i32* %3
br label %24
24: ; preds = %23, %20
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"alloc error\0A\00"
define i32 @cmalloc(i8** %0, i32 %1) {
%3 = add nsw i32 %1, 15
%4 = and i32 %3, -16
%5 = tail call i32 @posix_memalign(i8** %0, i32 16, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %7, %10
%14 = phi i32 [ -1, %10 ], [ 0, %7 ]
ret i32 %14
}