#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 */
scalar_t__ search_row(double, int, int);
double search_platform_up(double x, double y, int width, double max_distance) {
  int row;
  int rows_searched;
  row = y;
  rows_searched = 0;
  while (rows_searched < max_distance + 1) {
    if (search_row(x, row, width))
      return row - y;
    rows_searched++;
    row++;
  }
  return -1;
}


x86 assembly (clang, -O0):
<search_platform_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xeba(%rip),%xmm0
addsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    119a <search_platform_up+0x8a>
movsd  -0x10(%rbp),%xmm0
mov    -0x2c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <search_row@plt>
cmp    $0x0,%rax
je     1183 <search_platform_up+0x73>
cvtsi2sdl -0x2c(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a7 <search_platform_up+0x97>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1139 <search_platform_up+0x29>
movsd  0xe66(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_platform_up>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
addsd  0xeda(%rip),%xmm2
movsd  0xeda(%rip),%xmm0
xorpd  %xmm3,%xmm3
movsd  %xmm2,0x10(%rsp)
ucomisd %xmm3,%xmm2
jbe    119c <search_platform_up+0x8c>
mov    %edi,%r14d
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%ebx
mov    $0x1,%ebp
lea    (%rbx,%rbp,1),%edi
add    $0xffffffff,%edi
movsd  0x18(%rsp),%xmm0
mov    %r14d,%esi
call   1030 <search_row@plt>
test   %rax,%rax
jne    1189 <search_platform_up+0x79>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
add    $0x1,%ebp
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1150 <search_platform_up+0x40>
movsd  0xe81(%rip),%xmm0
jmp    119c <search_platform_up+0x8c>
lea    (%rbx,%rbp,1),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @search_platform_up(double %0, double %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double %3, double* %9
%12 = load double, double* %7
%13 = fptosi double %12 to i32
store i32 %13, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %31, %4
%15 = load i32, i32* %11
%16 = sitofp i32 %15 to double
%17 = load double, double* %9
%18 = fadd double %17, 1.000000e+00
%19 = fcmp olt double %16, %18
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = load double, double* %6
%22 = load i32, i32* %10
%23 = load i32, i32* %8
%24 = call i64 @search_row(double %21, i32 %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* %10
%28 = sitofp i32 %27 to double
%29 = load double, double* %7
%30 = fsub double %28, %29
store double %30, double* %5
br label %37
31: ; preds = %20
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %14
36: ; preds = %14
store double -1.000000e+00, double* %5
br label %37
37: ; preds = %36, %26
%38 = load double, double* %5
ret double %38
}

LLVM IR (-O2):
define double @search_platform_up(double %0, double %1, i32 %2, double %3) {
%5 = fadd double %3, 1.000000e+00
%6 = fcmp ogt double %5, 0.000000e+00
br i1 %6, label %7, label %22
7: ; preds = %4
%8 = fptosi double %1 to i32
br label %9
9: ; preds = %7, %17
%10 = phi i32 [ %18, %17 ], [ 0, %7 ]
%11 = phi i32 [ %19, %17 ], [ %8, %7 ]
%12 = tail call i64 @search_row(double %0, i32 %11, i32 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = sitofp i32 %11 to double
%16 = fsub double %15, %1
br label %22
17: ; preds = %9
%18 = add nuw nsw i32 %10, 1
%19 = add nsw i32 %11, 1
%20 = sitofp i32 %18 to double
%21 = fcmp ogt double %5, %20
br i1 %21, label %9, label %22
22: ; preds = %17, %4, %14
%23 = phi double [ %16, %14 ], [ -1.000000e+00, %4 ], [ -1.000000e+00, %17 ]
ret double %23
}