#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 /*<<< orphan*/ ushort;

/* Variables and functions */
int /*<<< orphan*/ nrerror(char *);
scalar_t__ realloc(int /*<<< orphan*/ *, size_t);
ushort *realloc_usvector(ushort *v, long nl, long nh, long n) {
  v += nl;
  v -= 0;
  v = (ushort *)realloc(v, (size_t)((nh - nl + 1 + n + 0) * sizeof(ushort)));
  if (!v)
    nrerror("allocation failure in realloc usvector()");
  return v - nl + 0;
}


x86 assembly (clang, -O0):
<realloc_usvector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    -0x10(%rbp),%rsi
add    $0x1,%rsi
add    -0x20(%rbp),%rsi
add    $0x0,%rsi
shl    $0x2,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118c <realloc_usvector+0x6c>
lea    0xe79(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
sub    -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<realloc_usvector>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    (%rdi,%rsi,4),%rdi
sub    %rsi,%rdx
add    %rcx,%rdx
lea    0x4(,%rdx,4),%rsi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1152 <realloc_usvector+0x32>
lea    0xeb3(%rip),%rdi
call   1030 <nrerror@plt>
shl    $0x2,%r14
sub    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [41 x i8] c"allocation failure in realloc usvector()\00"
define i32* @realloc_usvector(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%9 = load i64, i64* %6
%10 = load i32*, i32** %5
%11 = getelementptr inbounds i32, i32* %10, i64 %9
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 0
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = sub nsw i64 %15, %16
%18 = add nsw i64 %17, 1
%19 = load i64, i64* %8
%20 = add nsw i64 %18, %19
%21 = add nsw i64 %20, 0
%22 = mul i64 %21, 4
%23 = call i64 @realloc(i32* %14, i64 %22)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = icmp ne i32* %25, null
br i1 %26, label %29, label %27
27: ; preds = %4
%28 = call i32 @nrerror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %4
%30 = load i32*, i32** %5
%31 = load i64, i64* %6
%32 = sub i64 0, %31
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = getelementptr inbounds i32, i32* %33, i64 0
ret i32* %34
}

LLVM IR (-O2):
@.str = [41 x i8] c"allocation failure in realloc usvector()\00"
define i32* @realloc_usvector(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = getelementptr inbounds i32, i32* %0, i64 %1
%6 = sub i64 1, %1
%7 = add i64 %6, %2
%8 = add i64 %7, %3
%9 = shl i64 %8, 2
%10 = tail call i64 @realloc(i32* %5, i64 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @nrerror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
%15 = sub i64 0, %1
%16 = inttoptr i64 %10 to i32*
%17 = getelementptr inbounds i32, i32* %16, i64 %15
ret i32* %17
}