#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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
void *xrealloc(void *, unsigned int);
void *xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) {
  int mask = 1 << (unsigned char)sizeof_and_shift;
  if (!(idx & (mask - 1))) {
    sizeof_and_shift >>= 8;
    vector = xrealloc(vector, sizeof_and_shift * (idx + mask + 1));
    memset((char *)vector + (sizeof_and_shift * idx), 0,
           sizeof_and_shift * (mask + 1));
  }
  return vector;
}


x86 assembly (clang, -O0):
<xrealloc_vector_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
movzbl %al,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    119e <xrealloc_vector_helper+0x7e>
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    $0x1,%eax
imul   %eax,%esi
call   1030 <xrealloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%eax
add    $0x1,%eax
imul   %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc_vector_helper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    $0x1,%eax
mov    %ebp,%ecx
shl    %cl,%eax
mov    %rdi,%r14
lea    -0x1(%rax),%ecx
test   %edx,%ecx
jne    1173 <xrealloc_vector_helper+0x53>
mov    %edx,%ebx
shr    $0x8,%ebp
mov    %eax,%r15d
add    $0x1,%r15d
lea    (%rax,%rbx,1),%esi
add    $0x1,%esi
imul   %ebp,%esi
mov    %r14,%rdi
call   1030 <xrealloc@plt>
mov    %rax,%r14
imul   %ebp,%ebx
add    %rax,%rbx
imul   %ebp,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @xrealloc_vector_helper(i8* %0, i32 %1, i32 %2) {
%4 = and i32 %1, 255
%5 = shl nuw i32 1, %4
%6 = add nsw i32 %5, -1
%7 = and i32 %6, %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = lshr i32 %1, 8
%11 = add nuw i32 %5, 1
%12 = add i32 %11, %2
%13 = mul i32 %12, %10
%14 = tail call i8* @xrealloc(i8* %0, i32 %13)
%15 = mul i32 %10, %2
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = mul i32 %11, %10
%19 = tail call i32 @memset(i8* %17, i32 0, i32 %18)
br label %20
20: ; preds = %9, %3
%21 = phi i8* [ %0, %3 ], [ %14, %9 ]
ret i8* %21
}