#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*/ printf(char *, int);
int *relativeSortArray(int *, int, int *, int, int *);
int main() {
  int arr1[] = {2, 3, 1, 3, 2, 4, 6, 19, 9, 2, 7}, arr2[] = {2, 1, 4, 3, 9, 6};
  int *p1 = arr1, *p2 = arr2;
  int retsize;
  int *a = relativeSortArray(p1, 11, p2, 6, &retsize);
  for (int i = 0; i < retsize; i++)
    printf("%d ", a[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x2c,%edx
call   1050 <memcpy@plt>
mov    0xed2(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xecf(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xecc(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    $0xb,%esi
mov    $0x6,%ecx
lea    -0x64(%rbp),%r8
call   1030 <relativeSortArray@plt>
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11df <main+0xaf>
mov    -0x70(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11ae <main+0x7e>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
movups 0xeec(%rip),%xmm0
movups %xmm0,0x4c(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
mov    0xeec(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%r8
mov    $0xb,%esi
mov    $0x6,%ecx
call   1030 <relativeSortArray@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ba <main+0x9a>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xeb2(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11a0 <main+0x80>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.arr1 = [11 x i32] [i32 2, i32 3, i32 1, i32 3, i32 2, i32 4, i32 6, i32 19, i32 9, i32 2, i32 7]
@__const.main.arr2 = [6 x i32] [i32 2, i32 1, i32 4, i32 3, i32 9, i32 6]
@.str = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i32]
%3 = alloca [6 x i32]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [11 x i32]* %2 to i8*
%10 = bitcast [6 x i32]* %3 to i8*
%11 = getelementptr inbounds [11 x i32], [11 x i32]* %2, i64 0, i64 0
store i32* %11, i32** %4
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
store i32* %12, i32** %5
%13 = load i32*, i32** %4
%14 = load i32*, i32** %5
%15 = call i32* @relativeSortArray(i32* %13, i32 11, i32* %14, i32 6, i32* %6)
store i32* %15, i32** %7
store i32 0, i32* %8
br label %16
16: ; preds = %27, %0
%17 = load i32, i32* %8
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %16
30: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr1 = [11 x i32] [i32 2, i32 3, i32 1, i32 3, i32 2, i32 4, i32 6, i32 19, i32 9, i32 2, i32 7]
@__const.main.arr2 = [6 x i32] [i32 2, i32 1, i32 4, i32 3, i32 9, i32 6]
@.str = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = alloca [6 x i32]
%3 = alloca i32
%4 = bitcast [11 x i32]* %1 to i8*
%5 = bitcast [6 x i32]* %2 to i8*
%6 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %2, i64 0, i64 0
%8 = bitcast i32* %3 to i8*
%9 = call i32* @relativeSortArray(i32* %6, i32 11, i32* %7, i32 6, i32* %3)
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %13, %0
ret i32 0
13: ; preds = %0, %13
%14 = phi i64 [ %18, %13 ], [ 0, %0 ]
%15 = getelementptr inbounds i32, i32* %9, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %14, 1
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %13, label %12
}