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


x86 assembly (clang, -O0):
<search_platform_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xec9(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xea5(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    11ba <search_platform_down+0xaa>
movsd  -0x10(%rbp),%xmm0
mov    -0x2c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <search_row@plt>
cmp    $0x0,%rax
je     11a3 <search_platform_down+0x93>
cvtsi2sdl -0x2c(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c7 <search_platform_down+0xb7>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1149 <search_platform_down+0x39>
movsd  0xe3e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_platform_down>:
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 %xmm2,%xmm3
jbe    11b0 <search_platform_down+0xa0>
mov    %edi,%r14d
movsd  0xeb7(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ebx
mov    $0xffffffff,%ebp
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%edi
add    $0x1,%edi
movsd  0x18(%rsp),%xmm0
mov    %r14d,%esi
call   1030 <search_row@plt>
test   %rax,%rax
jne    1195 <search_platform_down+0x85>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
add    $0xffffffff,%ebp
ucomisd 0x10(%rsp),%xmm0
ja     1160 <search_platform_down+0x50>
movsd  0xe75(%rip),%xmm0
jmp    11b0 <search_platform_down+0xa0>
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  0x8(%rsp),%xmm0
addsd  0xe58(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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