#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 aaip_count_bytes(unsigned char *, int /*<<< orphan*/);
void *calloc(int, size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
int aaip_xinfo_cloner(void *old_data, void **new_data, int flag) {
  size_t aa_size;
  *new_data = NULL;
  if (old_data == NULL)
    return 0;
  aa_size = aaip_count_bytes((unsigned char *)old_data, 0);
  if (aa_size <= 0)
    return 0xE830FEAC;
  *new_data = calloc(1, aa_size);
  if (*new_data == NULL)
    return 0xF030FFFA;
  memcpy(*new_data, old_data, aa_size);
  return (int)aa_size;
}


x86 assembly (clang, -O0):
<aaip_xinfo_cloner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1165 <aaip_xinfo_cloner+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <aaip_xinfo_cloner+0xa8>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <aaip_count_bytes@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
ja     118b <aaip_xinfo_cloner+0x5b>
movl   $0xe830feac,-0x4(%rbp)
jmp    11d8 <aaip_xinfo_cloner+0xa8>
mov    -0x28(%rbp),%rsi
mov    $0x1,%edi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11bd <aaip_xinfo_cloner+0x8d>
movl   $0xf030fffa,-0x4(%rbp)
jmp    11d8 <aaip_xinfo_cloner+0xa8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aaip_xinfo_cloner>:
push   %r15
push   %r14
push   %rbx
movq   $0x0,(%rsi)
test   %rdi,%rdi
je     117b <aaip_xinfo_cloner+0x4b>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %esi,%esi
call   1050 <aaip_count_bytes@plt>
test   %rax,%rax
je     117f <aaip_xinfo_cloner+0x4f>
mov    %rax,%rbx
mov    $0x1,%edi
mov    %rax,%rsi
call   1030 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1186 <aaip_xinfo_cloner+0x56>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
jmp    118b <aaip_xinfo_cloner+0x5b>
xor    %ebx,%ebx
jmp    118b <aaip_xinfo_cloner+0x5b>
mov    $0xe830feac,%ebx
jmp    118b <aaip_xinfo_cloner+0x5b>
mov    $0xf030fffa,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @aaip_xinfo_cloner(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%9 = load i8**, i8*** %6
store i8* null, i8** %9
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %35
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @aaip_count_bytes(i8* %14, i32 0)
store i64 %15, i64* %8
%16 = load i64, i64* %8
%17 = icmp ule i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -399442260, i32* %4
br label %35
19: ; preds = %13
%20 = load i64, i64* %8
%21 = call i8* @calloc(i32 1, i64 %20)
%22 = load i8**, i8*** %6
store i8* %21, i8** %22
%23 = load i8**, i8*** %6
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 -265224198, i32* %4
br label %35
27: ; preds = %19
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = load i8*, i8** %5
%31 = load i64, i64* %8
%32 = call i32 @memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i64, i64* %8
%34 = trunc i64 %33 to i32
store i32 %34, i32* %4
br label %35
35: ; preds = %27, %26, %18, %12
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @aaip_xinfo_cloner(i8* %0, i8** nocapture writeonly %1, i32 %2) {
store i8* null, i8** %1
%4 = icmp eq i8* %0, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i64 @aaip_count_bytes(i8* %0, i32 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i8* @calloc(i32 1, i64 %6)
store i8* %9, i8** %1
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @memcpy(i8* %9, i8* %0, i64 %6)
%13 = trunc i64 %6 to i32
br label %14
14: ; preds = %8, %5, %3, %11
%15 = phi i32 [ %13, %11 ], [ 0, %3 ], [ -399442260, %5 ], [ -265224198, %8 ]
ret i32 %15
}