#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ malloc(int);
uint32_t alloc_traced_array(uint32_t traced_size_in_words,
                            uint32_t context_len) {
  uint32_t size;
  uint32_t ptr;
  if (traced_size_in_words > 0)
    size = traced_size_in_words + 1;
  else
    size = traced_size_in_words + 2;
  ptr = (uint32_t)malloc(size * sizeof(uint32_t));
  *(uint32_t *)ptr = ((traced_size_in_words & 0x1fffffff) | 0x40000000);
  *((uint32_t *)ptr + 1) = 0;
  return ptr;
}


x86 assembly (clang, -O0):
<alloc_traced_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1136 <alloc_traced_array+0x26>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <alloc_traced_array+0x2f>
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
and    $0x1fffffff,%ecx
or     $0x40000000,%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_traced_array>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
test   %edi,%edi
setle  %al
add    %edi,%eax
lea    0x4(,%rax,4),%edi
call   1030 <malloc@plt>
and    $0x1fffffff,%ebx
or     $0x40000000,%ebx
cltq
mov    %ebx,(%rax)
movl   $0x0,0x4(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @alloc_traced_array(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 1
%4 = select i1 %3, i32 2, i32 1
%5 = add nsw i32 %4, %0
%6 = shl i32 %5, 2
%7 = tail call i32 @malloc(i32 %6)
%8 = and i32 %0, 536870911
%9 = or i32 %8, 1073741824
%10 = sext i32 %7 to i64
%11 = inttoptr i64 %10 to i32*
store i32 %9, i32* %11
%12 = getelementptr inbounds i32, i32* %11, i64 1
store i32 0, i32* %12
ret i32 %7
}