#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(int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int swap3(void *x, void *y, int size) {
  void *tmp;
  if ((tmp = malloc(size)) == NULL)
    return -1;
  memcpy(tmp, x, size);
  memcpy(x, y, size);
  memcpy(y, tmp, size);
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<swap3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1165 <swap3+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <swap3+0x75>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap3>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1181 <swap3+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1186 <swap3+0x56>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @swap3(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %2)
%8 = tail call i32 @memcpy(i8* %0, i8* %1, i32 %2)
%9 = tail call i32 @memcpy(i8* %1, i8* %4, i32 %2)
%10 = tail call i32 @free(i8* %4)
br label %11
11: ; preds = %3, %6
%12 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %12
}