#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*/ nrerror(char *);
scalar_t__ realloc(short *, size_t);
short *realloc_svector(short *v, long nl, long nh, long n) {
  v += nl;
  v -= 0;
  v = (short *)realloc(v, (size_t)((nh - nl + 1 + n + 0) * sizeof(short)));
  if (!v)
    nrerror("allocation failure in realloc svector()");
  return v - nl + 0;
}


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

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

LLVM IR (-O0):
@.str = [40 x i8] c"allocation failure in realloc svector()\00"
define i16* @realloc_svector(i16* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i16*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i16* %0, i16** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%9 = load i64, i64* %6
%10 = load i16*, i16** %5
%11 = getelementptr inbounds i16, i16* %10, i64 %9
store i16* %11, i16** %5
%12 = load i16*, i16** %5
%13 = getelementptr inbounds i16, i16* %12, i64 0
store i16* %13, i16** %5
%14 = load i16*, i16** %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, 2
%23 = call i64 @realloc(i16* %14, i64 %22)
%24 = inttoptr i64 %23 to i16*
store i16* %24, i16** %5
%25 = load i16*, i16** %5
%26 = icmp ne i16* %25, null
br i1 %26, label %29, label %27
27: ; preds = %4
%28 = call i32 @nrerror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %4
%30 = load i16*, i16** %5
%31 = load i64, i64* %6
%32 = sub i64 0, %31
%33 = getelementptr inbounds i16, i16* %30, i64 %32
%34 = getelementptr inbounds i16, i16* %33, i64 0
ret i16* %34
}

LLVM IR (-O2):
@.str = [40 x i8] c"allocation failure in realloc svector()\00"
define i16* @realloc_svector(i16* %0, i64 %1, i64 %2, i64 %3) {
%5 = getelementptr inbounds i16, i16* %0, i64 %1
%6 = sub i64 1, %1
%7 = add i64 %6, %2
%8 = add i64 %7, %3
%9 = shl i64 %8, 1
%10 = tail call i64 @realloc(i16* %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 ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %4
%15 = sub i64 0, %1
%16 = inttoptr i64 %10 to i16*
%17 = getelementptr inbounds i16, i16* %16, i64 %15
ret i16* %17
}