#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);
int /*<<< orphan*/ printf(char *);
void swap_data(void *first_item, void *second_item, size_t item_size) {
  void *temp;
  if (!(temp = (void *)malloc(item_size))) {
    printf("Unrecoverable Error: No Memory..!!!\n");
    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   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116c <swap_data+0x3c>
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
jmp    119f <swap_data+0x6f>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <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   1050 <malloc@plt>
test   %rax,%rax
je     1186 <swap_data+0x56>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>
lea    0xe73(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Unrecoverable Error: No Memory..!!!\0A\00"
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 %14, label %12
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %27
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load i8*, i8** %4
%17 = load i64, i64* %6
%18 = call i32 @memcpy(i8* %15, i8* %16, i64 %17)
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i32 @memcpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %5
%24 = load i8*, i8** %7
%25 = load i64, i64* %6
%26 = call i32 @memcpy(i8* %23, i8* %24, i64 %25)
br label %27
27: ; preds = %14, %12
ret void
}

LLVM IR (-O2):
@str = [36 x i8] c"Unrecoverable Error: No Memory..!!!\00"
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 %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %13
9: ; preds = %3
%10 = tail call i32 @memcpy(i8* %5, i8* %0, i64 %2)
%11 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %2)
%12 = tail call i32 @memcpy(i8* %1, i8* %5, i64 %2)
br label %13
13: ; preds = %9, %7
ret void
}