#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*/, size_t);
void *realloc(void *, int);
int /*<<< orphan*/ yyerror(char *);
void *panoScriptReAlloc(void **ptr, size_t size, int *count) {
  char *temp;
  void *new_ptr = realloc(*ptr, ((*count) + 1) * size);
  if (new_ptr == NULL) {
    yyerror("Not enough memory");
    return NULL;
  }
  (*count)++;
  *ptr = new_ptr;
  temp = (char *)*ptr;
  temp += size * ((*count) - 1);
  memset(temp, 0, size);
  return (void *)temp;
}


x86 assembly (clang, -O0):
<panoScriptReAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
imul   -0x18(%rbp),%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118a <panoScriptReAlloc+0x5a>
lea    0xe88(%rip),%rdi
call   1030 <yyerror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11de <panoScriptReAlloc+0xae>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
imul   %rcx,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<panoScriptReAlloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
mov    (%rdx),%eax
add    $0x1,%eax
imul   %eax,%esi
call   1050 <realloc@plt>
test   %rax,%rax
je     117a <panoScriptReAlloc+0x4a>
movslq (%r12),%rbx
lea    0x1(%rbx),%ecx
mov    %ecx,(%r12)
mov    %rax,(%r15)
imul   %r14,%rbx
add    %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
jmp    1188 <panoScriptReAlloc+0x58>
lea    0xe7f(%rip),%rdi
call   1030 <yyerror@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Not enough memory\00"
define i8* @panoScriptReAlloc(i8** %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = load i64, i64* %6
%17 = mul i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @realloc(i8* %11, i32 %18)
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @yyerror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %44
24: ; preds = %3
%25 = load i32*, i32** %7
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
store i32 %27, i32* %25
%28 = load i8*, i8** %9
%29 = load i8**, i8*** %5
store i8* %28, i8** %29
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i64, i64* %6
%33 = load i32*, i32** %7
%34 = load i32, i32* %33
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 %32, %36
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 %37
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = load i64, i64* %6
%42 = call i32 @memset(i8* %40, i32 0, i64 %41)
%43 = load i8*, i8** %8
store i8* %43, i8** %4
br label %44
44: ; preds = %24, %22
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [18 x i8] c"Not enough memory\00"
define i8* @panoScriptReAlloc(i8** nocapture %0, i64 %1, i32* nocapture %2) {
%4 = load i8*, i8** %0
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
%7 = trunc i64 %1 to i32
%8 = mul i32 %6, %7
%9 = tail call i8* @realloc(i8* %4, i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @yyerror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %20
13: ; preds = %3
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
store i8* %9, i8** %0
%16 = sext i32 %14 to i64
%17 = mul i64 %16, %1
%18 = getelementptr inbounds i8, i8* %9, i64 %17
%19 = tail call i32 @memset(i8* %18, i32 0, i64 %1)
br label %20
20: ; preds = %13, %11
%21 = phi i8* [ null, %11 ], [ %18, %13 ]
ret i8* %21
}