#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 *bogobogosort_rec(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int *bogobogosort(int *toSort, int size) {
  int i;
  int *result = (int *)malloc(size * sizeof(int));
  int *tmp = bogobogosort_rec(toSort, size);
  memcpy(result, tmp, size * sizeof(int));
  for (i = 0; i < size; i++) {
    if (result[i] == tmp[i])
      continue;
  }
  return result;
}


x86 assembly (clang, -O0):
<bogobogosort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <bogobogosort_rec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c0 <bogobogosort+0x90>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x20(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    11ad <bogobogosort+0x7d>
jmp    11b2 <bogobogosort+0x82>
jmp    11b2 <bogobogosort+0x82>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <bogobogosort+0x50>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bogobogosort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x0(,%rbx,4),%r15d
mov    %r15d,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <bogobogosort_rec@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @bogobogosort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %6
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = call i32* @bogobogosort_rec(i32* %14, i32 %15)
store i32* %16, i32** %7
%17 = load i32*, i32** %6
%18 = load i32*, i32** %7
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i32 @memcpy(i32* %17, i32* %18, i32 %22)
store i32 0, i32* %5
br label %24
24: ; preds = %42, %2
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %7
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %33, %38
br i1 %39, label %40, label %41
40: ; preds = %28
br label %42
41: ; preds = %28
br label %42
42: ; preds = %41, %40
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %24
45: ; preds = %24
%46 = load i32*, i32** %6
ret i32* %46
}

LLVM IR (-O2):
define i32* @bogobogosort(i32* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i32* @bogobogosort_rec(i32* %0, i32 %1)
%7 = tail call i32 @memcpy(i32* %5, i32* %6, i32 %3)
ret i32* %5
}