#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, peopleRowSize - 1);
  int queueRowSize = 0;
  int currAllocPerson = 1;
  queue[0][0] = people[0][0];
  queue[0][1] = people[0][1];
  allocatePeople(people, queue, queueRowSize, peopleRowSize, currAllocPerson);
  (*returnSize) = peopleRowSize;
  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
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
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    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
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    %rcx,(%rsp)
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r12
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %r15d,%r15d
jle    1185 <reconstructQueue+0x55>
shl    $0x2,%ebp
mov    %r15d,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbx
jne    1170 <reconstructQueue+0x40>
lea    -0x1(%r15),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <quickSort@plt>
mov    (%r12),%rax
mov    (%rax),%ecx
mov    0x0(%r13),%rdx
mov    %ecx,(%rdx)
mov    0x4(%rax),%eax
mov    %eax,0x4(%rdx)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %edx,%edx
mov    %r15d,%ecx
mov    $0x1,%r8d
call   1030 <allocatePeople@plt>
mov    (%rsp),%rax
mov    %r15d,(%rax)
mov    %r13,%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 = load i32, i32* %6
%40 = sub nsw i32 %39, 1
%41 = call i32 @quickSort(i32** %38, i32 0, i32 %40)
store i32 0, i32* %11
store i32 1, i32* %12
%42 = load i32**, i32*** %5
%43 = getelementptr inbounds i32*, i32** %42, i64 0
%44 = load i32*, i32** %43
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
%47 = load i32**, i32*** %9
%48 = getelementptr inbounds i32*, i32** %47, i64 0
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 0
store i32 %46, i32* %50
%51 = load i32**, i32*** %5
%52 = getelementptr inbounds i32*, i32** %51, i64 0
%53 = load i32*, i32** %52
%54 = getelementptr inbounds i32, i32* %53, i64 1
%55 = load i32, i32* %54
%56 = load i32**, i32*** %9
%57 = getelementptr inbounds i32*, i32** %56, i64 0
%58 = load i32*, i32** %57
%59 = getelementptr inbounds i32, i32* %58, i64 1
store i32 %55, i32* %59
%60 = load i32**, i32*** %5
%61 = load i32**, i32*** %9
%62 = load i32, i32* %11
%63 = load i32, i32* %6
%64 = load i32, i32* %12
%65 = call i32 @allocatePeople(i32** %60, i32** %61, i32 %62, i32 %63, i32 %64)
%66 = load i32, i32* %6
%67 = load i32*, i32** %8
store i32 %66, i32* %67
%68 = load i32**, i32*** %9
ret i32** %68
}

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