#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int hex_encode(int /*<<< orphan*/ const *, int const, int /*<<< orphan*/ *,
               int);
int /*<<< orphan*/ *malloc(int);
int hex_encode_alloc(const uint8_t *in, const uint32_t in_len, uint8_t **out) {
  uint32_t out_len = 2 * in_len;
  *out = malloc(out_len);
  if (*out == NULL) {
    return -1;
  }
  return hex_encode(in, in_len, *out, out_len);
}


x86 assembly (clang, -O0):
<hex_encode_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1168 <hex_encode_alloc+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <hex_encode_alloc+0x61>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <hex_encode@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_encode_alloc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
lea    (%rbx,%rbx,1),%ebp
mov    %ebp,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     115a <hex_encode_alloc+0x3a>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <hex_encode@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hex_encode_alloc(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32** %2, i32*** %7
%9 = load i32, i32* %6
%10 = mul nsw i32 2, %9
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = call i32* @malloc(i32 %11)
%13 = load i32**, i32*** %7
store i32* %12, i32** %13
%14 = load i32**, i32*** %7
%15 = load i32*, i32** %14
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 -1, i32* %4
br label %25
18: ; preds = %3
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = load i32**, i32*** %7
%22 = load i32*, i32** %21
%23 = load i32, i32* %8
%24 = call i32 @hex_encode(i32* %19, i32 %20, i32* %22, i32 %23)
store i32 %24, i32* %4
br label %25
25: ; preds = %18, %17
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
define i32 @hex_encode_alloc(i32* %0, i32 %1, i32** nocapture writeonly %2) {
%4 = shl nsw i32 %1, 1
%5 = tail call i32* @malloc(i32 %4)
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @hex_encode(i32* %0, i32 %1, i32* %5, i32 %4)
br label %9
9: ; preds = %3, %7
%10 = phi i32 [ %8, %7 ], [ -1, %3 ]
ret i32 %10
}