#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 div2real(int);
int /*<<< orphan*/ exch(int *, int, int);
void swim(int *arr, int size, int k) {
  int prevk = div2real(k);
  while (1 < k && arr[prevk] > arr[k]) {
    exch(arr, prevk, k);
    int prek = k;
    int newprevk = div2real(prevk);
    k = prevk;
    prevk = newprevk;
  }
}


x86 assembly (clang, -O0):
<swim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <div2real@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    $0x1,%ecx
cmp    -0x10(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    116c <swim+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117c <swim+0x5c>
jmp    11ad <swim+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <exch@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <div2real@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113d <swim+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swim>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <div2real@plt>
cmp    $0x2,%ebx
jl     116b <swim+0x4b>
mov    %eax,%ebp
nopw   0x0(%rax,%rax,1)
movslq %ebp,%rax
mov    (%r14,%rax,4),%eax
mov    %ebx,%ecx
cmp    (%r14,%rcx,4),%eax
jle    116b <swim+0x4b>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <exch@plt>
mov    %ebp,%edi
call   1040 <div2real@plt>
mov    %ebp,%ebx
cmp    $0x1,%ebp
mov    %eax,%ebp
jg     1140 <swim+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @swim(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = call i32 @div2real(i32 %10)
store i32 %11, i32* %7
br label %12
12: ; preds = %29, %3
%13 = load i32, i32* %6
%14 = icmp slt i32 1, %13
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = load i32*, i32** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = icmp sgt i32 %20, %25
br label %27
27: ; preds = %15, %12
%28 = phi i1 [ false, %12 ], [ %26, %15 ]
br i1 %28, label %29, label %39
29: ; preds = %27
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = call i32 @exch(i32* %30, i32 %31, i32 %32)
%34 = load i32, i32* %6
store i32 %34, i32* %8
%35 = load i32, i32* %7
%36 = call i32 @div2real(i32 %35)
store i32 %36, i32* %9
%37 = load i32, i32* %7
store i32 %37, i32* %6
%38 = load i32, i32* %9
store i32 %38, i32* %7
br label %12
39: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @swim(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @div2real(i32 %2)
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %20
6: ; preds = %3, %16
%7 = phi i32 [ %8, %16 ], [ %2, %3 ]
%8 = phi i32 [ %18, %16 ], [ %4, %3 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = zext i32 %7 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = icmp sgt i32 %11, %14
br i1 %15, label %16, label %20
16: ; preds = %6
%17 = tail call i32 @exch(i32* %0, i32 %8, i32 %7)
%18 = tail call i32 @div2real(i32 %8)
%19 = icmp sgt i32 %8, 1
br i1 %19, label %6, label %20
20: ; preds = %6, %16, %3
ret void
}