#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 CountSortedInt(int, int *, int *, int *, int *, int *, int *);
int /*<<< orphan*/ SortInt(int, int *, int *, int *);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int UniqueInt(int M, int *list, int *uni_list, int *uni_i, int *uni_j,
              int *cnt) {
  int *sorted;
  int *sort_idx;
  int u;
  sorted = (int *)malloc(M * sizeof(int));
  sort_idx = (int *)malloc(M * sizeof(int));
  SortInt(M, list, sorted, sort_idx);
  u = CountSortedInt(M, sorted, sort_idx, uni_list, uni_i, uni_j, cnt);
  free(sorted);
  free(sort_idx);
  return u;
}


x86 assembly (clang, -O0):
<UniqueInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1060 <SortInt@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <CountSortedInt@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UniqueInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r13
mov    %r8,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r12
mov    %edi,%ebp
lea    0x0(,%rbp,4),%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1060 <SortInt@plt>
mov    %r13,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
call   1040 <CountSortedInt@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @UniqueInt(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %13
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i32*
store i32* %27, i32** %14
%28 = load i32, i32* %7
%29 = load i32*, i32** %8
%30 = load i32*, i32** %13
%31 = load i32*, i32** %14
%32 = call i32 @SortInt(i32 %28, i32* %29, i32* %30, i32* %31)
%33 = load i32, i32* %7
%34 = load i32*, i32** %13
%35 = load i32*, i32** %14
%36 = load i32*, i32** %9
%37 = load i32*, i32** %10
%38 = load i32*, i32** %11
%39 = load i32*, i32** %12
%40 = call i32 @CountSortedInt(i32 %33, i32* %34, i32* %35, i32* %36, i32* %37, i32* %38, i32* %39)
store i32 %40, i32* %15
%41 = load i32*, i32** %13
%42 = call i32 @free(i32* %41)
%43 = load i32*, i32** %14
%44 = call i32 @free(i32* %43)
%45 = load i32, i32* %15
ret i32 %45
}

LLVM IR (-O2):
define i32 @UniqueInt(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = shl i32 %0, 2
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i32*
%10 = tail call i64 @malloc(i32 %7)
%11 = inttoptr i64 %10 to i32*
%12 = tail call i32 @SortInt(i32 %0, i32* %1, i32* %9, i32* %11)
%13 = tail call i32 @CountSortedInt(i32 %0, i32* %9, i32* %11, i32* %2, i32* %3, i32* %4, i32* %5)
%14 = tail call i32 @free(i32* %9)
%15 = tail call i32 @free(i32* %11)
ret i32 %13
}