#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void swap_data(void *first_item, void *second_item, size_t item_size) {
  void *temp;
  if (!(temp = (void *)malloc(item_size))) {
    ;
    return;
  }
  memcpy(temp, first_item, item_size);
  memcpy(first_item, second_item, item_size);
  memcpy(second_item, temp, item_size);
}


x86 assembly (clang, -O0):
<swap_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1150 <swap_data+0x30>
jmp    1183 <swap_data+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1176 <swap_data+0x56>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @swap_data(i8* %0, i8* %1, i64 %2) {
%4 = tail call i64 @malloc(i64 %2)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = tail call i32 @memcpy(i8* %5, i8* %0, i64 %2)
%9 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %2)
%10 = tail call i32 @memcpy(i8* %1, i8* %5, i64 %2)
br label %11
11: ; preds = %3, %7
ret void
}