#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*/ u_char;

/* Variables and functions */
int getXMLMessageLen(char *);
int /*<<< orphan*/ log_fatal(char *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void *, int);
void copyXML(void **copy, void *original) {
  int len = getXMLMessageLen((char *)original);
  u_char *cpy = malloc(len * sizeof(u_char));
  if (cpy == NULL)
    log_fatal("out of memory: malloc copy of queue item failed");
  memcpy(cpy, original, len);
  *copy = (void *)cpy;
}


x86 assembly (clang, -O0):
<copyXML>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getXMLMessageLen@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <copyXML+0x46>
lea    0xe7f(%rip),%rdi
call   1060 <log_fatal@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyXML>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <getXMLMessageLen@plt>
mov    %eax,%r12d
lea    0x0(,%r12,4),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117a <copyXML+0x3a>
lea    0xe8b(%rip),%rdi
call   1060 <log_fatal@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <memcpy@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [48 x i8] c"out of memory: malloc copy of queue item failed\00"
define void @copyXML(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @getXMLMessageLen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @log_fatal(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i32*, i32** %6
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = call i32 @memcpy(i32* %19, i8* %20, i32 %21)
%23 = load i32*, i32** %6
%24 = bitcast i32* %23 to i8*
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"out of memory: malloc copy of queue item failed\00"
define void @copyXML(i8** nocapture writeonly %0, i8* %1) {
%3 = tail call i32 @getXMLMessageLen(i8* %1)
%4 = shl i32 %3, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @log_fatal(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = tail call i32 @memcpy(i32* %5, i8* %1, i32 %3)
%11 = bitcast i8** %0 to i32**
store i32* %5, i32** %11
ret void
}