#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 */
long find_element(double, long, double const *);
int rect_grid_search(long *ii, long *jj, double x, double y, long nxm, long nym,
                     const double *restrict xm, const double *restrict ym) {
  int lfound = 0;
  *jj = find_element(y, nym, ym);
  if (*jj < nym) {
    *ii = find_element(x, nxm, xm);
    if (*ii < nxm)
      lfound = 1;
  }
  return (lfound);
}


x86 assembly (clang, -O0):
<rect_grid_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <find_element@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x30(%rbp),%rax
jge    11a7 <rect_grid_search+0x97>
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <find_element@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jge    11a2 <rect_grid_search+0x92>
movl   $0x1,-0x44(%rbp)
jmp    11a7 <rect_grid_search+0x97>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rect_grid_search>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r12
movsd  %xmm0,0x8(%rsp)
mov    %rsi,%r13
mov    %rdi,%r15
movaps %xmm1,%xmm0
mov    %rcx,%rdi
mov    %r9,%rsi
call   1030 <find_element@plt>
mov    %rax,%rcx
mov    %rax,0x0(%r13)
xor    %eax,%eax
cmp    %rbx,%rcx
jge    116d <rect_grid_search+0x5d>
movsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <find_element@plt>
mov    %rax,%rcx
mov    %rax,(%r15)
xor    %eax,%eax
cmp    %r12,%rcx
setl   %al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @rect_grid_search(i64* %0, i64* %1, double %2, double %3, i64 %4, i64 %5, double* noalias %6, double* noalias %7) {
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca double
%12 = alloca double
%13 = alloca i64
%14 = alloca i64
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
store i64* %0, i64** %9
store i64* %1, i64** %10
store double %2, double* %11
store double %3, double* %12
store i64 %4, i64* %13
store i64 %5, i64* %14
store double* %6, double** %15
store double* %7, double** %16
store i32 0, i32* %17
%18 = load double, double* %12
%19 = load i64, i64* %14
%20 = load double*, double** %16
%21 = call i64 @find_element(double %18, i64 %19, double* %20)
%22 = load i64*, i64** %10
store i64 %21, i64* %22
%23 = load i64*, i64** %10
%24 = load i64, i64* %23
%25 = load i64, i64* %14
%26 = icmp slt i64 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %8
%28 = load double, double* %11
%29 = load i64, i64* %13
%30 = load double*, double** %15
%31 = call i64 @find_element(double %28, i64 %29, double* %30)
%32 = load i64*, i64** %9
store i64 %31, i64* %32
%33 = load i64*, i64** %9
%34 = load i64, i64* %33
%35 = load i64, i64* %13
%36 = icmp slt i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %27
store i32 1, i32* %17
br label %38
38: ; preds = %37, %27
br label %39
39: ; preds = %38, %8
%40 = load i32, i32* %17
ret i32 %40
}

LLVM IR (-O2):
define i32 @rect_grid_search(i64* nocapture writeonly %0, i64* nocapture writeonly %1, double %2, double %3, i64 %4, i64 %5, double* noalias %6, double* noalias %7) {
%9 = tail call i64 @find_element(double %3, i64 %5, double* %7)
store i64 %9, i64* %1
%10 = icmp slt i64 %9, %5
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = tail call i64 @find_element(double %2, i64 %4, double* %6)
store i64 %12, i64* %0
%13 = icmp slt i64 %12, %4
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ 0, %8 ], [ %14, %11 ]
ret i32 %16
}