#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 ta_calc_array_size(size_t, size_t);
int /*<<< orphan*/ ta_free(void *);
size_t ta_get_size(void *);
void *ta_zalloc_size(void *, size_t);
int ta_zalloc_fast(void *ta_parent, void *ptr, size_t count,
                   size_t element_size) {
  void **_ptr = ptr;
  size_t old_size = ta_get_size(*_ptr);
  size_t new_size = ta_calc_array_size(element_size, count);
  if (old_size < new_size) {
    ta_free(*_ptr);
    if (!(*_ptr = ta_zalloc_size(ta_parent, new_size)))
      return -1;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ta_zalloc_fast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1060 <ta_get_size@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <ta_calc_array_size@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    11d1 <ta_zalloc_fast+0x91>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1030 <ta_free@plt>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <ta_zalloc_size@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11c5 <ta_zalloc_fast+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <ta_zalloc_fast+0x98>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <ta_zalloc_fast+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ta_zalloc_fast>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%rdi
call   1060 <ta_get_size@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <ta_calc_array_size@plt>
mov    %rax,%rbx
xor    %eax,%eax
cmp    %rbx,%r13
jae    1194 <ta_zalloc_fast+0x54>
mov    (%r15),%rdi
call   1030 <ta_free@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <ta_zalloc_size@plt>
mov    %rax,(%r15)
cmp    $0x1,%rax
sbb    %eax,%eax
or     $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ta_zalloc_fast(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%13 = load i8*, i8** %7
%14 = bitcast i8* %13 to i8**
store i8** %14, i8*** %10
%15 = load i8**, i8*** %10
%16 = load i8*, i8** %15
%17 = call i64 @ta_get_size(i8* %16)
store i64 %17, i64* %11
%18 = load i64, i64* %9
%19 = load i64, i64* %8
%20 = call i64 @ta_calc_array_size(i64 %18, i64 %19)
store i64 %20, i64* %12
%21 = load i64, i64* %11
%22 = load i64, i64* %12
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %4
%25 = load i8**, i8*** %10
%26 = load i8*, i8** %25
%27 = call i32 @ta_free(i8* %26)
%28 = load i8*, i8** %6
%29 = load i64, i64* %12
%30 = call i8* @ta_zalloc_size(i8* %28, i64 %29)
%31 = load i8**, i8*** %10
store i8* %30, i8** %31
%32 = icmp ne i8* %30, null
br i1 %32, label %34, label %33
33: ; preds = %24
store i32 -1, i32* %5
br label %36
34: ; preds = %24
store i32 1, i32* %5
br label %36
35: ; preds = %4
store i32 0, i32* %5
br label %36
36: ; preds = %35, %34, %33
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
define i32 @ta_zalloc_fast(i8* %0, i8* nocapture %1, i64 %2, i64 %3) {
%5 = bitcast i8* %1 to i8**
%6 = load i8*, i8** %5
%7 = tail call i64 @ta_get_size(i8* %6)
%8 = tail call i64 @ta_calc_array_size(i64 %3, i64 %2)
%9 = icmp ult i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %4
%11 = load i8*, i8** %5
%12 = tail call i32 @ta_free(i8* %11)
%13 = tail call i8* @ta_zalloc_size(i8* %0, i64 %8)
store i8* %13, i8** %5
%14 = icmp eq i8* %13, null
%15 = select i1 %14, i32 -1, i32 1
br label %16
16: ; preds = %4, %10
%17 = phi i32 [ %15, %10 ], [ 0, %4 ]
ret i32 %17
}