#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 */
int /*<<< orphan*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ memmove(void *, void *, size_t);
void swap(void *p1, void *p2, size_t size) {
  if (p1 == NULL || p2 == NULL)
    return;
  void *tmp = malloc(size);
  memmove(tmp, p1, size);
  memmove(p1, p2, size);
  memmove(p2, tmp, size);
  free(tmp);
}


x86 assembly (clang, -O0):
<swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115a <swap+0x2a>
cmpq   $0x0,-0x10(%rbp)
jne    115f <swap+0x2f>
jmp    11a8 <swap+0x78>
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memmove@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1193 <swap+0x63>
mov    %rsi,%r14
test   %rsi,%rsi
je     1193 <swap+0x63>
mov    %rdx,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <memmove@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @swap(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 i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %3
br label %31
14: ; preds = %10
%15 = load i64, i64* %6
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = call i32 @memmove(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @memmove(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %7
%27 = load i64, i64* %6
%28 = call i32 @memmove(i8* %25, i8* %26, i64 %27)
%29 = load i8*, i8** %7
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
define void @swap(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i8* @malloc(i64 %2)
%9 = tail call i32 @memmove(i8* %8, i8* %0, i64 %2)
%10 = tail call i32 @memmove(i8* %0, i8* %1, i64 %2)
%11 = tail call i32 @memmove(i8* %1, i8* %8, i64 %2)
%12 = tail call i32 @free(i8* %8)
br label %13
13: ; preds = %3, %7
ret void
}