#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(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(void *, char *, int);
int qksort_exchange(void *item1, void *item2, int esize) {
  char *tmp = (char *)malloc(esize);
  if (NULL == tmp)
    return -1;
  memcpy(tmp, item1, esize);
  memcpy(item1, item2, esize);
  memcpy(item2, tmp, esize);
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<qksort_exchange>:
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)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1167 <qksort_exchange+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <qksort_exchange+0x77>
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):
<qksort_exchange>:
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 <qksort_exchange+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 <qksort_exchange+0x56>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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