#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;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned long *malloc(unsigned long);
int /*<<< orphan*/ stderr;
unsigned long *vector_alloc(unsigned long size) {
  unsigned long end = (size + (CHAR_BIT * sizeof(unsigned long)) - 1) /
                      (CHAR_BIT * sizeof(unsigned long));
  unsigned long *vector = malloc(end * sizeof(long));
  if (!vector) {
    fprintf(stderr, "Insufficient memory.\n");
    exit(EXIT_FAILURE);
  }
  return vector;
}


x86 assembly (clang, -O0):
<vector_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e99(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
sub    $0x1,%rax
mov    0x2e84(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <vector_alloc+0x7b>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_alloc>:
push   %rax
mov    0x2ea8(%rip),%rax
movslq (%rax),%rcx
lea    (%rdi,%rcx,8),%rax
add    $0xffffffffffffffff,%rax
shl    $0x3,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     115d <vector_alloc+0x2d>
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
jmp    1163 <vector_alloc+0x33>
xor    %edx,%edx
div    %ecx
mov    %eax,%edi
shl    $0x3,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1173 <vector_alloc+0x43>
pop    %rcx
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Insufficient memory.\0A\00"
@EXIT_FAILURE = global i32 0
define i64* @vector_alloc(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = load i32, i32* @CHAR_BIT
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = add i64 %5, %8
%10 = sub i64 %9, 1
%11 = load i32, i32* @CHAR_BIT
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = udiv i64 %10, %13
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = mul i64 %15, 8
%17 = call i64* @malloc(i64 %16)
store i64* %17, i64** %4
%18 = load i64*, i64** %4
%19 = icmp ne i64* %18, null
br i1 %19, label %25, label %20
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %1
%26 = load i64*, i64** %4
ret i64* %26
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Insufficient memory.\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i64* @vector_alloc(i64 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 3
%5 = add i64 %0, -1
%6 = add i64 %5, %4
%7 = udiv i64 %6, %4
%8 = shl i64 %7, 3
%9 = tail call i64* @malloc(i64 %8)
%10 = icmp eq i64* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
ret i64* %9
}