#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 */
size_t element_length(char);
int /*<<< orphan*/ memset(char *, int, long);
void *realloc(void *, size_t);
void *vector_realloc(void *v, long n_alt, long n_neu, char type) {
  void *u;
  size_t el;
  el = element_length(type);
  u = realloc(v, (size_t)((n_neu + 1) * el));
  if (n_neu > n_alt)
    memset(((char *)u) + (n_alt + 1) * el, 0x00, (n_neu - n_alt) * el);
  return u;
}


x86 assembly (clang, -O0):
<vector_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1050 <element_length@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
imul   -0x30(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jle    11a6 <vector_realloc+0x76>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
add    $0x1,%rax
imul   -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
sub    -0x10(%rbp),%rdx
imul   -0x30(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_realloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %ecx,%edi
call   1050 <element_length@plt>
mov    %rax,%r12
lea    0x1(%rbx),%rsi
imul   %rax,%rsi
mov    %r15,%rdi
call   1040 <realloc@plt>
mov    %rax,%r15
sub    %r14,%rbx
jle    117f <vector_realloc+0x4f>
add    $0x1,%r14
imul   %r12,%r14
mov    %r15,%rdi
add    %r14,%rdi
imul   %r12,%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @vector_realloc(i8* nocapture %0, i64 %1, i64 %2, i8 signext %3) {
%5 = tail call i64 @element_length(i8 signext %3)
%6 = add nsw i64 %2, 1
%7 = mul i64 %5, %6
%8 = tail call i8* @realloc(i8* %0, i64 %7)
%9 = icmp sgt i64 %2, %1
br i1 %9, label %10, label %17
10: ; preds = %4
%11 = add nsw i64 %1, 1
%12 = mul i64 %5, %11
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = sub nsw i64 %2, %1
%15 = mul i64 %5, %14
%16 = tail call i32 @memset(i8* %13, i32 0, i64 %15)
br label %17
17: ; preds = %10, %4
ret i8* %8
}