#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 */
double edgedf(double, double, double);
double sqrt(double);
double distaa3(double *img, double *gximg, double *gyimg, int w, int c, int xc,
               int yc, int xi, int yi) {
  double di, df, dx, dy, gx, gy, a;
  int closest;
  closest = c - xc - yc * w;
  a = img[closest];
  gx = gximg[closest];
  gy = gyimg[closest];
  if (a > 1.0)
    a = 1.0;
  if (a < 0.0)
    a = 0.0;
  if (a == 0.0)
    return 1000000.0;
  dx = (double)xi;
  dy = (double)yi;
  di = sqrt(dx * dx + dy * dy);
  if (di == 0) {
    df = edgedf(gx, gy, a);
  } else {
    df = edgedf(dx, dy, a);
  }
  return di + df;
}


x86 assembly (clang, -O0):
<distaa3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x2c(%rbp),%eax
mov    0x10(%rbp),%ecx
imul   -0x24(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  0xe63(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b4 <distaa3+0x94>
movsd  0xe51(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x68(%rbp),%xmm0
jbe    11ca <distaa3+0xaa>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f4 <distaa3+0xd4>
jp     11f4 <distaa3+0xd4>
movsd  0xe1e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128c <distaa3+0x16c>
cvtsi2sdl 0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
cvtsi2sdl 0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1264 <distaa3+0x144>
jp     1264 <distaa3+0x144>
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1030 <edgedf@plt>
movsd  %xmm0,-0x40(%rbp)
jmp    127d <distaa3+0x15d>
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
call   1030 <edgedf@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distaa3>:
sub    $0x28,%rsp
imul   0x30(%rsp),%ecx
add    %r9d,%ecx
sub    %ecx,%r8d
movslq %r8d,%rax
movsd  0xec6(%rip),%xmm0
minsd  (%rdi,%rax,8),%xmm0
xorpd  %xmm5,%xmm5
xorpd  %xmm2,%xmm2
maxsd  %xmm0,%xmm2
ucomisd %xmm5,%xmm2
jne    1160 <distaa3+0x40>
jp     1160 <distaa3+0x40>
movsd  0xead(%rip),%xmm1
jmp    1202 <distaa3+0xe2>
movsd  (%rsi,%rax,8),%xmm4
cvtsi2sdl 0x38(%rsp),%xmm6
movsd  (%rdx,%rax,8),%xmm1
cvtsi2sdl 0x40(%rsp),%xmm7
movapd %xmm7,%xmm3
mulsd  %xmm7,%xmm3
movapd %xmm6,%xmm0
mulsd  %xmm6,%xmm0
addsd  %xmm3,%xmm0
ucomisd %xmm5,%xmm0
jb     1196 <distaa3+0x76>
sqrtsd %xmm0,%xmm0
jmp    11d5 <distaa3+0xb5>
movsd  %xmm2,(%rsp)
movsd  %xmm4,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm6,0x10(%rsp)
movsd  %xmm7,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm7
movsd  0x10(%rsp),%xmm6
movsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm4
movsd  (%rsp),%xmm2
xorpd  %xmm3,%xmm3
movsd  %xmm0,(%rsp)
ucomisd %xmm3,%xmm0
jne    11ec <distaa3+0xcc>
jp     11ec <distaa3+0xcc>
movapd %xmm4,%xmm0
jmp    11f4 <distaa3+0xd4>
movapd %xmm6,%xmm0
movapd %xmm7,%xmm1
call   1030 <edgedf@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @distaa3(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca double
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca i32
store double* %0, double** %11
store double* %1, double** %12
store double* %2, double** %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
%28 = load i32, i32* %15
%29 = load i32, i32* %16
%30 = sub nsw i32 %28, %29
%31 = load i32, i32* %17
%32 = load i32, i32* %14
%33 = mul nsw i32 %31, %32
%34 = sub nsw i32 %30, %33
store i32 %34, i32* %27
%35 = load double*, double** %11
%36 = load i32, i32* %27
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
store double %39, double* %26
%40 = load double*, double** %12
%41 = load i32, i32* %27
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
store double %44, double* %24
%45 = load double*, double** %13
%46 = load i32, i32* %27
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
store double %49, double* %25
%50 = load double, double* %26
%51 = fcmp ogt double %50, 1.000000e+00
br i1 %51, label %52, label %53
52: ; preds = %9
store double 1.000000e+00, double* %26
br label %53
53: ; preds = %52, %9
%54 = load double, double* %26
%55 = fcmp olt double %54, 0.000000e+00
br i1 %55, label %56, label %57
56: ; preds = %53
store double 0.000000e+00, double* %26
br label %57
57: ; preds = %56, %53
%58 = load double, double* %26
%59 = fcmp oeq double %58, 0.000000e+00
br i1 %59, label %60, label %61
60: ; preds = %57
store double 1.000000e+06, double* %10
br label %89
61: ; preds = %57
%62 = load i32, i32* %18
%63 = sitofp i32 %62 to double
store double %63, double* %22
%64 = load i32, i32* %19
%65 = sitofp i32 %64 to double
store double %65, double* %23
%66 = load double, double* %22
%67 = load double, double* %22
%68 = load double, double* %23
%69 = load double, double* %23
%70 = fmul double %68, %69
%71 = call double @llvm.fmuladd.f64(double %66, double %67, double %70)
%72 = call double @sqrt(double %71)
store double %72, double* %20
%73 = load double, double* %20
%74 = fcmp oeq double %73, 0.000000e+00
br i1 %74, label %75, label %80
75: ; preds = %61
%76 = load double, double* %24
%77 = load double, double* %25
%78 = load double, double* %26
%79 = call double @edgedf(double %76, double %77, double %78)
store double %79, double* %21
br label %85
80: ; preds = %61
%81 = load double, double* %22
%82 = load double, double* %23
%83 = load double, double* %26
%84 = call double @edgedf(double %81, double %82, double %83)
store double %84, double* %21
br label %85
85: ; preds = %80, %75
%86 = load double, double* %20
%87 = load double, double* %21
%88 = fadd double %86, %87
store double %88, double* %10
br label %89
89: ; preds = %85, %60
%90 = load double, double* %10
ret double %90
}

LLVM IR (-O2):
define double @distaa3(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = mul nsw i32 %6, %3
%11 = add i32 %10, %5
%12 = sub i32 %4, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 %13
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %2, i64 %13
%19 = load double, double* %18
%20 = fcmp ogt double %15, 1.000000e+00
%21 = select i1 %20, double 1.000000e+00, double %15
%22 = fcmp olt double %21, 0.000000e+00
%23 = select i1 %22, double 0.000000e+00, double %21
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %39, label %25
25: ; preds = %9
%26 = sitofp i32 %7 to double
%27 = sitofp i32 %8 to double
%28 = fmul double %27, %27
%29 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %28)
%30 = tail call double @sqrt(double %29)
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = tail call double @edgedf(double %17, double %19, double %23)
br label %36
34: ; preds = %25
%35 = tail call double @edgedf(double %26, double %27, double %23)
br label %36
36: ; preds = %34, %32
%37 = phi double [ %33, %32 ], [ %35, %34 ]
%38 = fadd double %30, %37
br label %39
39: ; preds = %9, %36
%40 = phi double [ %38, %36 ], [ 1.000000e+06, %9 ]
ret double %40
}