#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*/ assert(int /*<<< orphan*/);
char *cbmyfatal(char *);
int /*<<< orphan*/ cbqsortsub(void *, int, int, char *, char *,
                              int (*)(void const *, void const *));
int /*<<< orphan*/ free(char *);
char *malloc(int);
void cbqsort(void *base, int nmemb, int size,
             int (*compar)(const void *, const void *)) {
  char *pswap, *vswap;
  assert(base && nmemb >= 0 && size > 0 && compar);
  (((pswap) = malloc(size)) ? (pswap) : cbmyfatal("out of memory"));
  (((vswap) = malloc(size)) ? (vswap) : cbmyfatal("out of memory"));
  cbqsortsub(base, nmemb, size, pswap, vswap, compar);
  free(vswap);
  free(pswap);
}


x86 assembly (clang, -O0):
<cbqsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
je     119f <cbqsort+0x4f>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x29(%rbp)
jl     119f <cbqsort+0x4f>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
jle    119f <cbqsort+0x4f>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cb <cbqsort+0x7b>
mov    -0x20(%rbp),%rax
jmp    11d7 <cbqsort+0x87>
lea    0xe2e(%rip),%rdi
call   1070 <cbmyfatal@plt>
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f6 <cbqsort+0xa6>
mov    -0x28(%rbp),%rax
jmp    1202 <cbqsort+0xb2>
lea    0xe03(%rip),%rdi
call   1070 <cbmyfatal@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x18(%rbp),%r9
call   1040 <cbqsortsub@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cbqsort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r12
test   %rdi,%rdi
setne  %al
test   %esi,%esi
setns  %cl
and    %al,%cl
test   %edx,%edx
setg   %al
test   %r14,%r14
setne  %dl
and    %al,%dl
and    %cl,%dl
movzbl %dl,%edi
call   1050 <assert@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11a5 <cbqsort+0x55>
lea    0xe60(%rip),%rdi
call   1070 <cbmyfatal@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <cbqsort+0x70>
lea    0xe45(%rip),%rdi
call   1070 <cbmyfatal@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r13,%rcx
mov    %rbx,%r8
mov    %r14,%r9
call   1040 <cbqsortsub@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define void @cbqsort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = load i32, i32* %6
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%21 = icmp ne i32 (i8*, i8*)* %20, null
br label %22
22: ; preds = %19, %16, %13, %4
%23 = phi i1 [ false, %16 ], [ false, %13 ], [ false, %4 ], [ %21, %19 ]
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %7
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i8*, i8** %9
br label %33
31: ; preds = %22
%32 = call i8* @cbmyfatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = phi i8* [ %30, %29 ], [ %32, %31 ]
%35 = load i32, i32* %7
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = load i8*, i8** %10
br label %42
40: ; preds = %33
%41 = call i8* @cbmyfatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %38
%43 = phi i8* [ %39, %38 ], [ %41, %40 ]
%44 = load i8*, i8** %5
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = load i8*, i8** %9
%48 = load i8*, i8** %10
%49 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%50 = call i32 @cbqsortsub(i8* %44, i32 %45, i32 %46, i8* %47, i8* %48, i32 (i8*, i8*)* %49)
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %9
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
define void @cbqsort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*)* %3) {
%5 = icmp ne i8* %0, null
%6 = icmp sgt i32 %1, -1
%7 = and i1 %5, %6
%8 = icmp sgt i32 %2, 0
%9 = and i1 %7, %8
%10 = icmp ne i32 (i8*, i8*)* %3, null
%11 = and i1 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i8* @malloc(i32 %2)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = tail call i8* @cbmyfatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %4, %16
%19 = tail call i8* @malloc(i32 %2)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i8* @cbmyfatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %18, %21
%24 = tail call i32 @cbqsortsub(i8* %0, i32 %1, i32 %2, i8* %14, i8* %19, i32 (i8*, i8*)* %3)
%25 = tail call i32 @free(i8* %19)
%26 = tail call i32 @free(i8* %14)
ret void
}