#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 */
scalar_t__ halloc(int);
int *allocRecord(int size, int descriptor) {
  int i;
  int *p, *a;
  p = a = (int *)halloc(size + sizeof(int));
  for (i = sizeof(int); i < size; i += sizeof(int))
    *p++ = 0;
  a[0] = descriptor;
  return a;
}


x86 assembly (clang, -O0):
<allocRecord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
add    $0x4,%rax
mov    %eax,%edi
call   1030 <halloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    116d <allocRecord+0x5d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0x0,(%rax)
movslq -0xc(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0xc(%rbp)
jmp    113c <allocRecord+0x2c>
mov    -0x8(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocRecord>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x4(%rbx),%edi
call   1040 <halloc@plt>
mov    %rax,%rbp
cmp    $0x5,%ebx
jl     1150 <allocRecord+0x30>
add    $0xfffffffb,%ebx
and    $0xfffffffc,%ebx
add    $0x4,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r14d,0x0(%rbp)
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32* @allocRecord(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = add i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @halloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %7
store i32* %13, i32** %6
store i32 4, i32* %5
br label %14
14: ; preds = %21, %2
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i32 1
store i32* %20, i32** %6
store i32 0, i32* %19
br label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = add i64 %23, 4
%25 = trunc i64 %24 to i32
store i32 %25, i32* %5
br label %14
26: ; preds = %14
%27 = load i32, i32* %4
%28 = load i32*, i32** %7
%29 = getelementptr inbounds i32, i32* %28, i64 0
store i32 %27, i32* %29
%30 = load i32*, i32** %7
ret i32* %30
}

LLVM IR (-O2):
define i32* @allocRecord(i32 %0, i32 %1) {
%3 = add i32 %0, 4
%4 = tail call i64 @halloc(i32 %3)
%5 = inttoptr i64 %4 to i32*
%6 = icmp sgt i32 %0, 4
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = inttoptr i64 %4 to i8*
%9 = add nsw i32 %0, -5
%10 = and i32 %9, -4
%11 = zext i32 %10 to i64
%12 = add nuw nsw i64 %11, 4
br label %13
13: ; preds = %7, %2
store i32 %1, i32* %5
ret i32* %5
}