#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*/ perror(char *);
char *realloc(char *, size_t);
int util_grow(char **ptr, size_t *allo, size_t new_size, size_t elm_size) {
  char *new_ptr;
  if (new_size <= *allo)
    return -1;
  new_ptr = realloc(*ptr, new_size * elm_size);
  if (new_ptr == NULL) {
    perror("realloc");
    return -1;
  }
  *allo = new_size;
  *ptr = new_ptr;
  return 0;
}


x86 assembly (clang, -O0):
<util_grow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
ja     1155 <util_grow+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <util_grow+0x8e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
imul   -0x28(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1191 <util_grow+0x71>
lea    0xe80(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <util_grow+0x8e>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_grow>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
cmp    %rdx,(%rsi)
jae    1159 <util_grow+0x39>
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
mov    (%rdi),%rdi
imul   %rdx,%rcx
mov    %rcx,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     1167 <util_grow+0x47>
mov    %rbx,0x0(%rbp)
mov    %rax,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
jmp    1159 <util_grow+0x39>

LLVM IR (-O0):
@.str = [8 x i8] c"realloc\00"
define i32 @util_grow(i8** %0, i64* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load i64, i64* %8
%12 = load i64*, i64** %7
%13 = load i64, i64* %12
%14 = icmp ule i64 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 -1, i32* %5
br label %32
16: ; preds = %4
%17 = load i8**, i8*** %6
%18 = load i8*, i8** %17
%19 = load i64, i64* %8
%20 = load i64, i64* %9
%21 = mul i64 %19, %20
%22 = call i8* @realloc(i8* %18, i64 %21)
store i8* %22, i8** %10
%23 = load i8*, i8** %10
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %32
27: ; preds = %16
%28 = load i64, i64* %8
%29 = load i64*, i64** %7
store i64 %28, i64* %29
%30 = load i8*, i8** %10
%31 = load i8**, i8*** %6
store i8* %30, i8** %31
store i32 0, i32* %5
br label %32
32: ; preds = %27, %25, %15
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
define i32 @util_grow(i8** nocapture %0, i64* nocapture %1, i64 %2, i64 %3) {
%5 = load i64, i64* %1
%6 = icmp ult i64 %5, %2
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i8*, i8** %0
%9 = mul i64 %3, %2
%10 = tail call i8* @realloc(i8* %8, i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %15
14: ; preds = %7
store i64 %2, i64* %1
store i8* %10, i8** %0
br label %15
15: ; preds = %4, %14, %12
%16 = phi i32 [ -1, %12 ], [ 0, %14 ], [ -1, %4 ]
ret i32 %16
}