#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*/ panic(char *, ...);
int posix_memalign(void **, size_t, size_t);
__attribute__((visibility("hidden"))) void *xmalloc_aligned(size_t size,
                                                            size_t alignment) {
  int ret;
  void *ptr;
  if (size == 0)
    panic("xmalloc_aligned: zero size\n");
  ret = posix_memalign(&ptr, alignment, size);
  if (ret != 0)
    panic("xmalloc_aligned: out of memory (allocating %zu bytes)\n", size);
  return ptr;
}


x86 assembly (clang, -O0):
<xmalloc_aligned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1149 <xmalloc_aligned+0x29>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
call   1040 <posix_memalign@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1179 <xmalloc_aligned+0x59>
mov    -0x8(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xmalloc_aligned>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
jne    113d <xmalloc_aligned+0x1d>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <panic@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <posix_memalign@plt>
test   %eax,%eax
je     1160 <xmalloc_aligned+0x40>
lea    0xec6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <panic@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"xmalloc_aligned: zero size\0A\00"
@.str.1 = [55 x i8] c"xmalloc_aligned: out of memory (allocating %zu bytes)\0A\00"
define hidden i8* @xmalloc_aligned(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = load i64, i64* %4
%13 = load i64, i64* %3
%14 = call i32 @posix_memalign(i8** %6, i64 %12, i64 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i64, i64* %3
%19 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %17, %11
%21 = load i8*, i8** %6
ret i8* %21
}

LLVM IR (-O2):
@.str = [28 x i8] c"xmalloc_aligned: zero size\0A\00"
@.str.1 = [55 x i8] c"xmalloc_aligned: out of memory (allocating %zu bytes)\0A\00"
define hidden i8* @xmalloc_aligned(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = call i32 @posix_memalign(i8** %3, i64 %1, i64 %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i64 %0)
br label %13
13: ; preds = %11, %8
%14 = load i8*, i8** %3
ret i8* %14
}