#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 */
void *ereallocarray(void *, size_t, size_t);
int /*<<< orphan*/ free(void *);
void resize(void **ptr, size_t *nmemb, size_t size, size_t new_nmemb,
            void **next) {
  void *n, *tmp;
  if (new_nmemb) {
    tmp = ereallocarray(*ptr, new_nmemb, size);
  } else {
    free(*ptr);
    tmp = NULL;
  }
  n = (char *)tmp + *nmemb * size;
  *nmemb = new_nmemb;
  *ptr = tmp;
  if (next)
    *next = n;
}


x86 assembly (clang, -O0):
<resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1164 <resize+0x44>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <ereallocarray@plt>
mov    %rax,-0x38(%rbp)
jmp    1178 <resize+0x58>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
imul   -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     11bb <resize+0x9b>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r12
mov    (%rdi),%rdi
test   %rcx,%rcx
je     114d <resize+0x2d>
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <ereallocarray@plt>
jmp    1154 <resize+0x34>
call   1030 <free@plt>
xor    %eax,%eax
mov    0x0(%r13),%rcx
mov    %rbx,0x0(%r13)
mov    %rax,(%r12)
test   %r15,%r15
je     116f <resize+0x4f>
imul   %r14,%rcx
add    %rcx,%rax
mov    %rax,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @resize(i8** nocapture %0, i64* nocapture %1, i64 %2, i64 %3, i8** writeonly %4) {
%6 = icmp eq i64 %3, 0
%7 = load i8*, i8** %0
br i1 %6, label %10, label %8
8: ; preds = %5
%9 = tail call i8* @ereallocarray(i8* %7, i64 %3, i64 %2)
br label %12
10: ; preds = %5
%11 = tail call i32 @free(i8* %7)
br label %12
12: ; preds = %10, %8
%13 = phi i8* [ %9, %8 ], [ null, %10 ]
%14 = load i64, i64* %1
store i64 %3, i64* %1
store i8* %13, i8** %0
%15 = icmp eq i8** %4, null
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = mul i64 %14, %2
%18 = getelementptr inbounds i8, i8* %13, i64 %17
store i8* %18, i8** %4
br label %19
19: ; preds = %16, %12
ret void
}