#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 EINVAL;
int errno;
void *memalign(size_t, size_t);
int posix_memalign(void **ptrptr, size_t boundary, size_t size) {
  if (boundary < sizeof(void *))
    return EINVAL;
  *ptrptr = memalign(boundary, size);
  return *ptrptr ? 0 : errno;
}


x86 assembly (clang, -O0):
<posix_memalign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x8,-0x18(%rbp)
jae    1140 <posix_memalign+0x30>
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <posix_memalign+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <memalign@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     116f <posix_memalign+0x5f>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <posix_memalign+0x6b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<posix_memalign>:
push   %rbx
cmp    $0x7,%rsi
ja     1120 <posix_memalign+0x10>
mov    0x2eba(%rip),%rax
jmp    1142 <posix_memalign+0x32>
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <memalign@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
xor    %eax,%eax
test   %rcx,%rcx
jne    1144 <posix_memalign+0x34>
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @posix_memalign(i8** %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %6
%9 = icmp ult i64 %8, 8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = load i32, i32* @EINVAL
store i32 %11, i32* %4
br label %25
12: ; preds = %3
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = call i8* @memalign(i64 %13, i64 %14)
%16 = load i8**, i8*** %5
store i8* %15, i8** %16
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %12
br label %23
21: ; preds = %12
%22 = load i32, i32* @errno
br label %23
23: ; preds = %21, %20
%24 = phi i32 [ 0, %20 ], [ %22, %21 ]
store i32 %24, i32* %4
br label %25
25: ; preds = %23, %10
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @posix_memalign(i8** nocapture writeonly %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %1, 8
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = load i32, i32* @EINVAL
br label %12
7: ; preds = %3
%8 = tail call i8* @memalign(i64 %1, i64 %2)
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
%10 = load i32, i32* @errno
%11 = select i1 %9, i32 %10, i32 0
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ %6, %5 ], [ %11, %7 ]
ret i32 %13
}