#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int GifPartition(int /*<<< orphan*/ *, int, int, int, int);
void GifPartitionByMedian(uint8_t *image, int left, int right, int com,
                          int neededCenter) {
  if (left < right - 1) {
    int pivotIndex = left + (right - left) / 2;
    pivotIndex = GifPartition(image, left, right, com, pivotIndex);
    if (pivotIndex > neededCenter)
      GifPartitionByMedian(image, left, pivotIndex, com, neededCenter);
    if (pivotIndex < neededCenter)
      GifPartitionByMedian(image, pivotIndex + 1, right, com, neededCenter);
  }
}


x86 assembly (clang, -O0):
<GifPartitionByMedian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11cd <GifPartitionByMedian+0xad>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1040 <GifPartition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11a3 <GifPartitionByMedian+0x83>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <GifPartitionByMedian@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c8 <GifPartitionByMedian+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <GifPartitionByMedian@plt>
jmp    11cd <GifPartitionByMedian+0xad>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GifPartitionByMedian>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
lea    -0x1(%r12),%eax
mov    %eax,0x4(%rsp)
cmp    %esi,%eax
jle    119e <GifPartitionByMedian+0x7e>
mov    %r8d,%r13d
mov    %ecx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%eax
sub    %ebx,%eax
mov    %eax,%r8d
shr    $0x1f,%r8d
add    %eax,%r8d
sar    %r8d
add    %ebx,%r8d
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1040 <GifPartition@plt>
mov    %eax,%ebp
cmp    %r13d,%eax
jle    118e <GifPartitionByMedian+0x6e>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %r13d,%r8d
call   1030 <GifPartitionByMedian@plt>
cmp    %r13d,%ebp
jge    119e <GifPartitionByMedian+0x7e>
add    $0x1,%ebp
mov    %ebp,%ebx
cmp    %ebp,0x4(%rsp)
jg     1150 <GifPartitionByMedian+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @GifPartitionByMedian(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = add nsw i32 %2, -1
%7 = icmp sgt i32 %6, %1
br i1 %7, label %8, label %21
8: ; preds = %5, %16
%9 = phi i32 [ %18, %16 ], [ %1, %5 ]
%10 = sub nsw i32 %2, %9
%11 = sdiv i32 %10, 2
%12 = add nsw i32 %11, %9
%13 = tail call i32 @GifPartition(i32* %0, i32 %9, i32 %2, i32 %3, i32 %12)
%14 = icmp sgt i32 %13, %4
br i1 %14, label %15, label %16
15: ; preds = %8
tail call void @GifPartitionByMedian(i32* %0, i32 %9, i32 %13, i32 %3, i32 %4)
br label %16
16: ; preds = %15, %8
%17 = icmp slt i32 %13, %4
%18 = add nsw i32 %13, 1
%19 = icmp sgt i32 %6, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %8, label %21
21: ; preds = %16, %5
ret void
}