#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*/ sfree(int *);
int *smalloc(int);
void sorts2d(double *vals[4][8], int *indices[4][8], int nvtxs) {
  int *space;
  int *temp[4];
  int nlists = 4;
  int i;
  void mergesort();
  space = smalloc(nvtxs * sizeof(int));
  for (i = 0; i < nlists; i++) {
    temp[i] = smalloc(nvtxs * sizeof(int));
  }
  mergesort(vals[0][1], nvtxs, temp[0], space);
  mergesort(vals[0][2], nvtxs, temp[1], space);
  mergesort(vals[0][3], nvtxs, temp[2], space);
  mergesort(vals[1][2], nvtxs, temp[3], space);
  sfree(space);
  indices[0][1] = indices[1][0] = indices[2][3] = indices[3][2] = temp[0];
  indices[0][2] = indices[2][0] = indices[1][3] = indices[3][1] = temp[1];
  indices[0][3] = indices[3][0] = temp[2];
  indices[1][2] = indices[2][1] = temp[3];
}


x86 assembly (clang, -O0):
<sorts2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x4,-0x44(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <smalloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1199 <sorts2d+0x69>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <smalloc@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1164 <sorts2d+0x34>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rax
mov    0x50(%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <mergesort@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sfree@plt>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0xd0(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x98(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x40(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0xc8(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x58(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x80(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0xc0(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x88(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,0x50(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorts2d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1050 <smalloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
call   1050 <smalloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1050 <smalloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
call   1050 <smalloc@plt>
mov    %rax,(%rsp)
mov    %ebp,%edi
call   1050 <smalloc@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%rbp
mov    0x8(%rbp),%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <mergesort@plt>
mov    0x10(%rbp),%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <mergesort@plt>
mov    0x18(%rbp),%rdi
mov    %r14d,%esi
mov    (%rsp),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <mergesort@plt>
mov    0x50(%rbp),%rdi
mov    %r14d,%esi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <mergesort@plt>
mov    %r12,%rdi
call   1030 <sfree@plt>
mov    %r15,0xd0(%rbx)
mov    %r15,0x98(%rbx)
mov    %r15,0x40(%rbx)
mov    %r15,0x8(%rbx)
mov    %r13,0xc8(%rbx)
mov    %r13,0x58(%rbx)
mov    %r13,0x80(%rbx)
mov    %r13,0x10(%rbx)
mov    (%rsp),%rax
mov    %rax,0xc0(%rbx)
mov    %rax,0x18(%rbx)
mov    %rbp,0x88(%rbx)
mov    %rbp,0x50(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sorts2d([8 x double*]* %0, [8 x i32*]* %1, i32 %2) {
%4 = alloca [8 x double*]*
%5 = alloca [8 x i32*]*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [4 x i32*]
%9 = alloca i32
%10 = alloca i32
store [8 x double*]* %0, [8 x double*]** %4
store [8 x i32*]* %1, [8 x i32*]** %5
store i32 %2, i32* %6
store i32 4, i32* %9
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i32* @smalloc(i32 %14)
store i32* %15, i32** %7
store i32 0, i32* %10
br label %16
16: ; preds = %29, %3
%17 = load i32, i32* %10
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i32* @smalloc(i32 %24)
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 %27
store i32* %25, i32** %28
br label %29
29: ; preds = %20
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %16
32: ; preds = %16
%33 = load [8 x double*]*, [8 x double*]** %4
%34 = getelementptr inbounds [8 x double*], [8 x double*]* %33, i64 0
%35 = getelementptr inbounds [8 x double*], [8 x double*]* %34, i64 0, i64 1
%36 = load double*, double** %35
%37 = load i32, i32* %6
%38 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 0
%39 = load i32*, i32** %38
%40 = load i32*, i32** %7
%41 = load [8 x double*]*, [8 x double*]** %4
%42 = getelementptr inbounds [8 x double*], [8 x double*]* %41, i64 0
%43 = getelementptr inbounds [8 x double*], [8 x double*]* %42, i64 0, i64 2
%44 = load double*, double** %43
%45 = load i32, i32* %6
%46 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 1
%47 = load i32*, i32** %46
%48 = load i32*, i32** %7
%49 = load [8 x double*]*, [8 x double*]** %4
%50 = getelementptr inbounds [8 x double*], [8 x double*]* %49, i64 0
%51 = getelementptr inbounds [8 x double*], [8 x double*]* %50, i64 0, i64 3
%52 = load double*, double** %51
%53 = load i32, i32* %6
%54 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 2
%55 = load i32*, i32** %54
%56 = load i32*, i32** %7
%57 = load [8 x double*]*, [8 x double*]** %4
%58 = getelementptr inbounds [8 x double*], [8 x double*]* %57, i64 1
%59 = getelementptr inbounds [8 x double*], [8 x double*]* %58, i64 0, i64 2
%60 = load double*, double** %59
%61 = load i32, i32* %6
%62 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 3
%63 = load i32*, i32** %62
%64 = load i32*, i32** %7
%65 = load i32*, i32** %7
%66 = call i32 @sfree(i32* %65)
%67 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 0
%68 = load i32*, i32** %67
%69 = load [8 x i32*]*, [8 x i32*]** %5
%70 = getelementptr inbounds [8 x i32*], [8 x i32*]* %69, i64 3
%71 = getelementptr inbounds [8 x i32*], [8 x i32*]* %70, i64 0, i64 2
store i32* %68, i32** %71
%72 = load [8 x i32*]*, [8 x i32*]** %5
%73 = getelementptr inbounds [8 x i32*], [8 x i32*]* %72, i64 2
%74 = getelementptr inbounds [8 x i32*], [8 x i32*]* %73, i64 0, i64 3
store i32* %68, i32** %74
%75 = load [8 x i32*]*, [8 x i32*]** %5
%76 = getelementptr inbounds [8 x i32*], [8 x i32*]* %75, i64 1
%77 = getelementptr inbounds [8 x i32*], [8 x i32*]* %76, i64 0, i64 0
store i32* %68, i32** %77
%78 = load [8 x i32*]*, [8 x i32*]** %5
%79 = getelementptr inbounds [8 x i32*], [8 x i32*]* %78, i64 0
%80 = getelementptr inbounds [8 x i32*], [8 x i32*]* %79, i64 0, i64 1
store i32* %68, i32** %80
%81 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 1
%82 = load i32*, i32** %81
%83 = load [8 x i32*]*, [8 x i32*]** %5
%84 = getelementptr inbounds [8 x i32*], [8 x i32*]* %83, i64 3
%85 = getelementptr inbounds [8 x i32*], [8 x i32*]* %84, i64 0, i64 1
store i32* %82, i32** %85
%86 = load [8 x i32*]*, [8 x i32*]** %5
%87 = getelementptr inbounds [8 x i32*], [8 x i32*]* %86, i64 1
%88 = getelementptr inbounds [8 x i32*], [8 x i32*]* %87, i64 0, i64 3
store i32* %82, i32** %88
%89 = load [8 x i32*]*, [8 x i32*]** %5
%90 = getelementptr inbounds [8 x i32*], [8 x i32*]* %89, i64 2
%91 = getelementptr inbounds [8 x i32*], [8 x i32*]* %90, i64 0, i64 0
store i32* %82, i32** %91
%92 = load [8 x i32*]*, [8 x i32*]** %5
%93 = getelementptr inbounds [8 x i32*], [8 x i32*]* %92, i64 0
%94 = getelementptr inbounds [8 x i32*], [8 x i32*]* %93, i64 0, i64 2
store i32* %82, i32** %94
%95 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 2
%96 = load i32*, i32** %95
%97 = load [8 x i32*]*, [8 x i32*]** %5
%98 = getelementptr inbounds [8 x i32*], [8 x i32*]* %97, i64 3
%99 = getelementptr inbounds [8 x i32*], [8 x i32*]* %98, i64 0, i64 0
store i32* %96, i32** %99
%100 = load [8 x i32*]*, [8 x i32*]** %5
%101 = getelementptr inbounds [8 x i32*], [8 x i32*]* %100, i64 0
%102 = getelementptr inbounds [8 x i32*], [8 x i32*]* %101, i64 0, i64 3
store i32* %96, i32** %102
%103 = getelementptr inbounds [4 x i32*], [4 x i32*]* %8, i64 0, i64 3
%104 = load i32*, i32** %103
%105 = load [8 x i32*]*, [8 x i32*]** %5
%106 = getelementptr inbounds [8 x i32*], [8 x i32*]* %105, i64 2
%107 = getelementptr inbounds [8 x i32*], [8 x i32*]* %106, i64 0, i64 1
store i32* %104, i32** %107
%108 = load [8 x i32*]*, [8 x i32*]** %5
%109 = getelementptr inbounds [8 x i32*], [8 x i32*]* %108, i64 1
%110 = getelementptr inbounds [8 x i32*], [8 x i32*]* %109, i64 0, i64 2
store i32* %104, i32** %110
ret void
}

LLVM IR (-O2):
define void @sorts2d([8 x double*]* nocapture %0, [8 x i32*]* nocapture writeonly %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32* @smalloc(i32 %4)
%6 = tail call i32* @smalloc(i32 %4)
%7 = tail call i32* @smalloc(i32 %4)
%8 = tail call i32* @smalloc(i32 %4)
%9 = tail call i32* @smalloc(i32 %4)
%10 = getelementptr inbounds [8 x double*], [8 x double*]* %0, i64 0, i64 1
%11 = load double*, double** %10
tail call void (double*, i32, i32*, i32*, ...) bitcast (void (...)* @mergesort to void (double*, i32, i32*, i32*, ...)*)(double* %11, i32 %2, i32* %6, i32* %5)
%12 = getelementptr inbounds [8 x double*], [8 x double*]* %0, i64 0, i64 2
%13 = load double*, double** %12
tail call void (double*, i32, i32*, i32*, ...) bitcast (void (...)* @mergesort to void (double*, i32, i32*, i32*, ...)*)(double* %13, i32 %2, i32* %7, i32* %5)
%14 = getelementptr inbounds [8 x double*], [8 x double*]* %0, i64 0, i64 3
%15 = load double*, double** %14
tail call void (double*, i32, i32*, i32*, ...) bitcast (void (...)* @mergesort to void (double*, i32, i32*, i32*, ...)*)(double* %15, i32 %2, i32* %8, i32* %5)
%16 = getelementptr inbounds [8 x double*], [8 x double*]* %0, i64 1, i64 2
%17 = load double*, double** %16
tail call void (double*, i32, i32*, i32*, ...) bitcast (void (...)* @mergesort to void (double*, i32, i32*, i32*, ...)*)(double* %17, i32 %2, i32* %9, i32* %5)
%18 = tail call i32 @sfree(i32* %5)
%19 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 3, i64 2
store i32* %6, i32** %19
%20 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 2, i64 3
store i32* %6, i32** %20
%21 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 1, i64 0
store i32* %6, i32** %21
%22 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 0, i64 1
store i32* %6, i32** %22
%23 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 3, i64 1
store i32* %7, i32** %23
%24 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 1, i64 3
store i32* %7, i32** %24
%25 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 2, i64 0
store i32* %7, i32** %25
%26 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 0, i64 2
store i32* %7, i32** %26
%27 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 3, i64 0
store i32* %8, i32** %27
%28 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 0, i64 3
store i32* %8, i32** %28
%29 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 2, i64 1
store i32* %9, i32** %29
%30 = getelementptr inbounds [8 x i32*], [8 x i32*]* %1, i64 1, i64 2
store i32* %9, i32** %30
ret void
}