#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 DeshuffleIndex(int, int);
int /*<<< orphan*/ ShuffleSortedArray(int *, int);
int ShuffledBinarySearch(int, int *, int);
int /*<<< orphan*/ SortShuffledArray(int *, int);
int /*<<< orphan*/ memmove(int *, int *, int);
int RemoveShuffledArrayValue(int value, int *shuffled_array, int count) {
  int index = ShuffledBinarySearch(value, shuffled_array, count);
  if (index >= 0) {
    SortShuffledArray(shuffled_array, count);
    int deshuf = DeshuffleIndex(index, count);
    if (deshuf < (count - 1))
      memmove(shuffled_array + deshuf, shuffled_array + deshuf + 1,
              (count - 1 - deshuf) * sizeof(int));
    count--;
    ShuffleSortedArray(shuffled_array, count);
  }
  return count;
}


x86 assembly (clang, -O0):
<RemoveShuffledArrayValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <ShuffledBinarySearch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11f6 <RemoveShuffledArrayValue+0xa6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <SortShuffledArray@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <DeshuffleIndex@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e1 <RemoveShuffledArrayValue+0x91>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memmove@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <ShuffleSortedArray@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RemoveShuffledArrayValue>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
call   1030 <ShuffledBinarySearch@plt>
test   %eax,%eax
js     11a0 <RemoveShuffledArrayValue+0x50>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %ebx,%esi
call   1070 <SortShuffledArray@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <DeshuffleIndex@plt>
add    $0xffffffff,%ebx
mov    %ebx,%edx
sub    %eax,%edx
jle    1196 <RemoveShuffledArrayValue+0x46>
cltq
lea    (%r14,%rax,4),%rdi
lea    (%r14,%rax,4),%rsi
add    $0x4,%rsi
shl    $0x2,%edx
call   1060 <memmove@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <ShuffleSortedArray@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @RemoveShuffledArrayValue(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32*, i32** %5
%11 = load i32, i32* %6
%12 = call i32 @ShuffledBinarySearch(i32 %9, i32* %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %50
15: ; preds = %3
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = call i32 @SortShuffledArray(i32* %16, i32 %17)
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = call i32 @DeshuffleIndex(i32 %19, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %44
26: ; preds = %15
%27 = load i32*, i32** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32*, i32** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = getelementptr inbounds i32, i32* %34, i64 1
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, 1
%38 = load i32, i32* %8
%39 = sub nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = mul i64 %40, 4
%42 = trunc i64 %41 to i32
%43 = call i32 @memmove(i32* %30, i32* %35, i32 %42)
br label %44
44: ; preds = %26, %15
%45 = load i32, i32* %6
%46 = add nsw i32 %45, -1
store i32 %46, i32* %6
%47 = load i32*, i32** %5
%48 = load i32, i32* %6
%49 = call i32 @ShuffleSortedArray(i32* %47, i32 %48)
br label %50
50: ; preds = %44, %3
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
define i32 @RemoveShuffledArrayValue(i32 %0, i32* %1, i32 %2) {
%4 = tail call i32 @ShuffledBinarySearch(i32 %0, i32* %1, i32 %2)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = tail call i32 @SortShuffledArray(i32* %1, i32 %2)
%8 = tail call i32 @DeshuffleIndex(i32 %4, i32 %2)
%9 = add nsw i32 %2, -1
%10 = icmp sgt i32 %9, %8
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = sub nsw i32 %9, %8
%16 = shl i32 %15, 2
%17 = tail call i32 @memmove(i32* %13, i32* %14, i32 %16)
br label %18
18: ; preds = %11, %6
%19 = tail call i32 @ShuffleSortedArray(i32* %1, i32 %9)
br label %20
20: ; preds = %18, %3
%21 = phi i32 [ %9, %18 ], [ %2, %3 ]
ret i32 %21
}