#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*/ ENOMEM;
int /*<<< orphan*/ errno;
void *realloc(void *, int);
int _crypt_data_alloc(void **data, int *size, int need) {
  void *updated;
  if (*data && *size >= need)
    return 0;
  updated = realloc(*data, need);
  if (!updated) {
    errno = (ENOMEM);
    return -1;
  }
  *data = updated;
  *size = need;
  return 0;
}


x86 assembly (clang, -O0):
<_crypt_data_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     114c <_crypt_data_alloc+0x3c>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
cmp    -0x1c(%rbp),%eax
jl     114c <_crypt_data_alloc+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <_crypt_data_alloc+0x93>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1188 <_crypt_data_alloc+0x78>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <_crypt_data_alloc+0x93>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_crypt_data_alloc>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     112c <_crypt_data_alloc+0x1c>
xor    %eax,%eax
cmp    %ebx,(%r14)
jge    1159 <_crypt_data_alloc+0x49>
mov    %ebx,%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     1142 <_crypt_data_alloc+0x32>
mov    %rax,(%r15)
mov    %ebx,(%r14)
xor    %eax,%eax
jmp    1159 <_crypt_data_alloc+0x49>
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    0x2e86(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @_crypt_data_alloc(i8** %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
%15 = load i32, i32* %7
%16 = icmp sge i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %4
br label %32
18: ; preds = %12, %3
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = load i32, i32* %7
%22 = call i8* @realloc(i8* %20, i32 %21)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = load i32, i32* @ENOMEM
store i32 %26, i32* @errno
store i32 -1, i32* %4
br label %32
27: ; preds = %18
%28 = load i8*, i8** %8
%29 = load i8**, i8*** %5
store i8* %28, i8** %29
%30 = load i32, i32* %7
%31 = load i32*, i32** %6
store i32 %30, i32* %31
store i32 0, i32* %4
br label %32
32: ; preds = %27, %25, %17
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @_crypt_data_alloc(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %15
9: ; preds = %6, %3
%10 = tail call i8* @realloc(i8* %4, i32 %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32, i32* @ENOMEM
store i32 %13, i32* @errno
br label %15
14: ; preds = %9
store i8* %10, i8** %0
store i32 %2, i32* %1
br label %15
15: ; preds = %6, %14, %12
%16 = phi i32 [ 0, %14 ], [ -1, %12 ], [ 0, %6 ]
ret i32 %16
}