#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 getMinElementIndex(int *, int, int, int, int);
int /*<<< orphan*/ swap(int *, int, int);
void sortPeaksValleys(int *arr, int size) {
  for (int i = 1; i < size; i += 2) {
    int minElementIndex = getMinElementIndex(arr, size, i, i - 1, i + 1);
    if (i != minElementIndex) {
      swap(arr, i, minElementIndex);
    }
  }
}


x86 assembly (clang, -O0):
<sortPeaksValleys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1190 <sortPeaksValleys+0x70>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%r8d
add    $0x1,%r8d
call   1030 <getMinElementIndex@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     117d <sortPeaksValleys+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <swap@plt>
jmp    1182 <sortPeaksValleys+0x62>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <sortPeaksValleys+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortPeaksValleys>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jl     116c <sortPeaksValleys+0x4c>
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x1,%ebx
jmp    1147 <sortPeaksValleys+0x27>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x2,%ebx
cmp    %ebp,%ebx
jge    116c <sortPeaksValleys+0x4c>
lea    -0x1(%rbx),%ecx
lea    0x1(%rbx),%r8d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <getMinElementIndex@plt>
cmp    %eax,%ebx
je     1140 <sortPeaksValleys+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <swap@plt>
jmp    1140 <sortPeaksValleys+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @sortPeaksValleys(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %5, label %4
4: ; preds = %13, %2
ret void
5: ; preds = %2, %13
%6 = phi i32 [ %14, %13 ], [ 1, %2 ]
%7 = add nsw i32 %6, -1
%8 = add nuw nsw i32 %6, 1
%9 = tail call i32 @getMinElementIndex(i32* %0, i32 %1, i32 %6, i32 %7, i32 %8)
%10 = icmp eq i32 %6, %9
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i32 @swap(i32* %0, i32 %6, i32 %9)
br label %13
13: ; preds = %11, %5
%14 = add nuw nsw i32 %6, 2
%15 = icmp slt i32 %14, %1
br i1 %15, label %5, label %4
}