#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 CHAR_BIT;
void *__morecore(unsigned int);
void *align(size_t size) {
  void *result;
  unsigned int adj;
  result = __morecore(size);
  adj = (unsigned int)((char *)result - (char *)NULL) %
        (1 << ((CHAR_BIT * sizeof(size_t)) > 16 ? 12 : 9));
  if (adj != 0) {
    __morecore(adj = (1 << ((CHAR_BIT * sizeof(size_t)) > 16 ? 12 : 9)) - adj);
    result = (char *)result + adj;
  }
  return result;
}


x86 assembly (clang, -O0):
<align>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1030 <__morecore@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x0,%rax
mov    0x2ea6(%rip),%rcx
movslq (%rcx),%rsi
shl    $0x3,%rsi
mov    $0x9,%ecx
mov    $0xc,%edx
cmp    $0x10,%rsi
cmova  %edx,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ab <align+0x9b>
mov    0x2e6d(%rip),%rax
movslq (%rax),%rdx
shl    $0x3,%rdx
mov    $0x9,%ecx
mov    $0xc,%eax
cmp    $0x10,%rdx
cmova  %eax,%ecx
mov    $0x1,%edi
shl    %cl,%edi
sub    -0x14(%rbp),%edi
mov    %edi,-0x14(%rbp)
call   1030 <__morecore@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<align>:
push   %r14
push   %rbx
push   %rax
call   1030 <__morecore@plt>
mov    %rax,%r14
mov    0x2ebd(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
cmp    $0x11,%rax
mov    $0x1000,%eax
mov    $0x200,%ebx
cmovae %eax,%ebx
lea    -0x1(%rbx),%eax
and    %r14d,%eax
je     114f <align+0x3f>
sub    %eax,%ebx
mov    %ebx,%edi
call   1030 <__morecore@plt>
add    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i8* @align(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = trunc i64 %5 to i32
%7 = call i8* @__morecore(i32 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = ptrtoint i8* %8 to i64
%10 = sub i64 %9, 0
%11 = trunc i64 %10 to i32
%12 = load i32, i32* @CHAR_BIT
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = icmp ugt i64 %14, 16
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 12, i32 9
%18 = shl i32 1, %17
%19 = urem i32 %11, %18
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %1
%23 = load i32, i32* @CHAR_BIT
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = icmp ugt i64 %25, 16
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 12, i32 9
%29 = shl i32 1, %28
%30 = load i32, i32* %4
%31 = sub i32 %29, %30
store i32 %31, i32* %4
%32 = call i8* @__morecore(i32 %31)
%33 = load i8*, i8** %3
%34 = load i32, i32* %4
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8* %36, i8** %3
br label %37
37: ; preds = %22, %1
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i8* @align(i64 %0) {
%2 = trunc i64 %0 to i32
%3 = tail call i8* @__morecore(i32 %2)
%4 = ptrtoint i8* %3 to i64
%5 = trunc i64 %4 to i32
%6 = load i32, i32* @CHAR_BIT
%7 = sext i32 %6 to i64
%8 = shl nsw i64 %7, 3
%9 = icmp ugt i64 %8, 16
%10 = select i1 %9, i32 4096, i32 512
%11 = add nsw i32 %10, -1
%12 = and i32 %11, %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %1
%15 = sub nsw i32 %10, %12
%16 = tail call i8* @__morecore(i32 %15)
%17 = zext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %3, i64 %17
br label %19
19: ; preds = %14, %1
%20 = phi i8* [ %18, %14 ], [ %3, %1 ]
ret i8* %20
}