#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*/ flip(int *, int);
int max_ind(int *, int);
int pancakeSort(int arr[], int n) {
  int size, max;
  for (size = n; size > 1; size--) {
    max = max_ind(arr, size);
    if (max != size - 1) {
      flip(arr, max);
      flip(arr, size - 1);
    }
  }
}


x86 assembly (clang, -O0):
<pancakeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    118d <pancakeSort+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <max_ind@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     117a <pancakeSort+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <flip@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
sub    $0x1,%esi
call   1040 <flip@plt>
jmp    117f <pancakeSort+0x5f>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1135 <pancakeSort+0x15>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pancakeSort>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     115f <pancakeSort+0x3f>
mov    %esi,%ebx
mov    %rdi,%r14
jmp    1138 <pancakeSort+0x18>
lea    0x1(%rbx),%eax
cmp    $0x2,%eax
jbe    115f <pancakeSort+0x3f>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <max_ind@plt>
add    $0xffffffff,%ebx
cmp    %eax,%ebx
je     1130 <pancakeSort+0x10>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <flip@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <flip@plt>
jmp    1130 <pancakeSort+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @pancakeSort(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
store i32 %8, i32* %6
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = load i32, i32* %6
%15 = call i32 @max_ind(i32* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %28
20: ; preds = %12
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = call i32 @flip(i32* %21, i32 %22)
%24 = load i32*, i32** %4
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = call i32 @flip(i32* %24, i32 %26)
br label %28
28: ; preds = %20, %12
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, -1
store i32 %31, i32* %6
br label %9
32: ; preds = %9
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @pancakeSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %14
4: ; preds = %2, %12
%5 = phi i32 [ %7, %12 ], [ %1, %2 ]
%6 = tail call i32 @max_ind(i32* %0, i32 %5)
%7 = add nsw i32 %5, -1
%8 = icmp eq i32 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 @flip(i32* %0, i32 %6)
%11 = tail call i32 @flip(i32* %0, i32 %7)
br label %12
12: ; preds = %4, %9
%13 = icmp ugt i32 %5, 2
br i1 %13, label %4, label %14
14: ; preds = %12, %2
ret i32 undef
}