#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*/ allocatePeople(int **, int **, int, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ quickSort(int **, int /*<<< orphan*/, int);
int **reconstructQueue(int **people, int peopleRowSize, int peopleColSize,
                       int *returnSize) {
  int **queue = (int **)malloc(peopleRowSize * sizeof(int *));
  for (int i = 0; i < peopleRowSize; i++) {
    queue[i] = (int *)malloc(peopleColSize * sizeof(int));
  }
  quickSort(people, 0, 5);
  int queueRowSize = 0;
  int currAllocPerson = 1;
  queue[0][0] = people[0][0];
  queue[0][1] = people[0][1];
  allocatePeople(people, queue, queueRowSize, peopleRowSize, currAllocPerson);
  return queue;
}


x86 assembly (clang, -O0):
<reconstructQueue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1198 <reconstructQueue+0x68>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1160 <reconstructQueue+0x30>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <quickSort@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1030 <allocatePeople@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reconstructQueue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    1185 <reconstructQueue+0x55>
shl    $0x2,%r13d
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,(%r12,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <reconstructQueue+0x40>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <quickSort@plt>
mov    (%r15),%rax
mov    (%rax),%ecx
mov    (%r12),%rdx
mov    %ecx,(%rdx)
mov    0x4(%rax),%eax
mov    %eax,0x4(%rdx)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %edx,%edx
mov    %r14d,%ecx
mov    $0x1,%r8d
call   1030 <allocatePeople@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32** @reconstructQueue(i32** %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32**
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32**
store i32** %18, i32*** %9
store i32 0, i32* %10
br label %19
19: ; preds = %34, %4
%20 = load i32, i32* %10
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
%30 = load i32**, i32*** %9
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32*, i32** %30, i64 %32
store i32* %29, i32** %33
br label %34
34: ; preds = %23
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %19
37: ; preds = %19
%38 = load i32**, i32*** %5
%39 = call i32 @quickSort(i32** %38, i32 0, i32 5)
store i32 0, i32* %11
store i32 1, i32* %12
%40 = load i32**, i32*** %5
%41 = getelementptr inbounds i32*, i32** %40, i64 0
%42 = load i32*, i32** %41
%43 = getelementptr inbounds i32, i32* %42, i64 0
%44 = load i32, i32* %43
%45 = load i32**, i32*** %9
%46 = getelementptr inbounds i32*, i32** %45, i64 0
%47 = load i32*, i32** %46
%48 = getelementptr inbounds i32, i32* %47, i64 0
store i32 %44, i32* %48
%49 = load i32**, i32*** %5
%50 = getelementptr inbounds i32*, i32** %49, i64 0
%51 = load i32*, i32** %50
%52 = getelementptr inbounds i32, i32* %51, i64 1
%53 = load i32, i32* %52
%54 = load i32**, i32*** %9
%55 = getelementptr inbounds i32*, i32** %54, i64 0
%56 = load i32*, i32** %55
%57 = getelementptr inbounds i32, i32* %56, i64 1
store i32 %53, i32* %57
%58 = load i32**, i32*** %5
%59 = load i32**, i32*** %9
%60 = load i32, i32* %11
%61 = load i32, i32* %6
%62 = load i32, i32* %12
%63 = call i32 @allocatePeople(i32** %58, i32** %59, i32 %60, i32 %61, i32 %62)
%64 = load i32**, i32*** %9
ret i32** %64
}

LLVM IR (-O2):
define i32** @reconstructQueue(i32** %0, i32 %1, i32 %2, i32* nocapture readnone %3) {
%5 = shl i32 %1, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i32**
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = shl i32 %2, 2
%11 = zext i32 %1 to i64
br label %21
12: ; preds = %21, %4
%13 = tail call i32 @quickSort(i32** %0, i32 0, i32 5)
%14 = load i32*, i32** %0
%15 = load i32, i32* %14
%16 = load i32*, i32** %7
store i32 %15, i32* %16
%17 = getelementptr inbounds i32, i32* %14, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %16, i64 1
store i32 %18, i32* %19
%20 = tail call i32 @allocatePeople(i32** %0, i32** %7, i32 0, i32 %1, i32 1)
ret i32** %7
21: ; preds = %9, %21
%22 = phi i64 [ 0, %9 ], [ %26, %21 ]
%23 = tail call i64 @malloc(i32 %10)
%24 = inttoptr i64 %23 to i32*
%25 = getelementptr inbounds i32*, i32** %7, i64 %22
store i32* %24, i32** %25
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %12, label %21
}