void separation_point_shear_stress(double *x_loc, double dx, double dy,
                                   int imax, double **U, double **V) {
  int i;
  double dv_dx, du_dy, stress, stress_ahead;
  du_dy = (U[imax][2] - U[imax][0]) / (2 * dy);
  dv_dx = (V[imax + 1][1] - V[imax - 1][1]) / (2 * dx);
  stress_ahead = du_dy + dv_dx;
  for (i = imax - 1; i > 1; i--) {
    du_dy = (U[i][2] - U[i][0]) / (2 * dy);
    dv_dx = (V[i + 1][1] - V[i - 1][1]) / (2 * dx);
    stress = du_dy + dv_dx;
    if (stress_ahead > 0 && stress < 0) {
      *x_loc = (i)*dx;
      break;
    }
    stress_ahead = stress;
  }
}


x86 assembly (clang, -O0):
<separation_point_shear_stress>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x10(%rax),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
subsd  (%rax),%xmm0
movsd  0xeba(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x8(%rax),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
subsd  0x8(%rax),%xmm0
movsd  0xe78(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jle    128f <separation_point_shear_stress+0x18f>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x10(%rax),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
subsd  (%rax),%xmm0
movsd  0xe1f(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsd  0x8(%rax),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
subsd  0x8(%rax),%xmm0
movsd  0xddd(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x58(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1277 <separation_point_shear_stress+0x177>
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    1277 <separation_point_shear_stress+0x177>
cvtsi2sdl -0x34(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    128f <separation_point_shear_stress+0x18f>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11ae <separation_point_shear_stress+0xae>
pop    %rbp
ret

x86 assembly (clang, -O2):
<separation_point_shear_stress>:
movslq %esi,%rax
mov    (%rdx,%rax,8),%r8
unpcklpd %xmm0,%xmm1
addpd  %xmm1,%xmm1
mov    -0x8(%rcx,%rax,8),%r9
mov    0x8(%rcx,%rax,8),%r10
lea    -0x1(%rax),%r11d
movsd  (%r8),%xmm2
movsd  0x10(%r8),%xmm3
movhpd 0x8(%r10),%xmm3
movhpd 0x8(%r9),%xmm2
subpd  %xmm2,%xmm3
divpd  %xmm1,%xmm3
movapd %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
addsd  %xmm3,%xmm2
lea    (%rdx,%r11,8),%r8
lea    (%rcx,%r11,8),%r9
add    $0x8,%r9
add    $0xfffffffe,%eax
lea    (%rcx,%rax,8),%r10
xor    %eax,%eax
xorpd  %xmm3,%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%esi
cmp    $0x2,%esi
jl     11d3 <separation_point_shear_stress+0xd3>
mov    (%r8,%rax,1),%rdx
mov    (%r9,%rax,1),%rcx
mov    (%r10,%rax,1),%r11
movsd  (%rdx),%xmm4
movsd  0x10(%rdx),%xmm5
movhpd 0x8(%rcx),%xmm5
movhpd 0x8(%r11),%xmm4
subpd  %xmm4,%xmm5
divpd  %xmm1,%xmm5
movapd %xmm5,%xmm4
unpckhpd %xmm5,%xmm4
addsd  %xmm5,%xmm4
add    $0xfffffffffffffff8,%rax
ucomisd %xmm3,%xmm2
movapd %xmm4,%xmm2
jbe    1170 <separation_point_shear_stress+0x70>
ucomisd %xmm4,%xmm3
movapd %xmm4,%xmm2
jbe    1170 <separation_point_shear_stress+0x70>
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
ret

LLVM IR (-O0):
define void @separation_point_shear_stress(double* %0, double %1, double %2, i32 %3, double** %4, double** %5) {
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double**
%12 = alloca double**
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double* %0, double** %7
store double %1, double* %8
store double %2, double* %9
store i32 %3, i32* %10
store double** %4, double*** %11
store double** %5, double*** %12
%18 = load double**, double*** %11
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double*, double** %18, i64 %20
%22 = load double*, double** %21
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = load double**, double*** %11
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double*, double** %25, i64 %27
%29 = load double*, double** %28
%30 = getelementptr inbounds double, double* %29, i64 0
%31 = load double, double* %30
%32 = fsub double %24, %31
%33 = load double, double* %9
%34 = fmul double 2.000000e+00, %33
%35 = fdiv double %32, %34
store double %35, double* %15
%36 = load double**, double*** %12
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double*, double** %36, i64 %39
%41 = load double*, double** %40
%42 = getelementptr inbounds double, double* %41, i64 1
%43 = load double, double* %42
%44 = load double**, double*** %12
%45 = load i32, i32* %10
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double*, double** %44, i64 %47
%49 = load double*, double** %48
%50 = getelementptr inbounds double, double* %49, i64 1
%51 = load double, double* %50
%52 = fsub double %43, %51
%53 = load double, double* %8
%54 = fmul double 2.000000e+00, %53
%55 = fdiv double %52, %54
store double %55, double* %14
%56 = load double, double* %15
%57 = load double, double* %14
%58 = fadd double %56, %57
store double %58, double* %17
%59 = load i32, i32* %10
%60 = sub nsw i32 %59, 1
store i32 %60, i32* %13
br label %61
61: ; preds = %119, %6
%62 = load i32, i32* %13
%63 = icmp sgt i32 %62, 1
br i1 %63, label %64, label %122
64: ; preds = %61
%65 = load double**, double*** %11
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
%69 = load double*, double** %68
%70 = getelementptr inbounds double, double* %69, i64 2
%71 = load double, double* %70
%72 = load double**, double*** %11
%73 = load i32, i32* %13
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double*, double** %72, i64 %74
%76 = load double*, double** %75
%77 = getelementptr inbounds double, double* %76, i64 0
%78 = load double, double* %77
%79 = fsub double %71, %78
%80 = load double, double* %9
%81 = fmul double 2.000000e+00, %80
%82 = fdiv double %79, %81
store double %82, double* %15
%83 = load double**, double*** %12
%84 = load i32, i32* %13
%85 = add nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double*, double** %83, i64 %86
%88 = load double*, double** %87
%89 = getelementptr inbounds double, double* %88, i64 1
%90 = load double, double* %89
%91 = load double**, double*** %12
%92 = load i32, i32* %13
%93 = sub nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds double*, double** %91, i64 %94
%96 = load double*, double** %95
%97 = getelementptr inbounds double, double* %96, i64 1
%98 = load double, double* %97
%99 = fsub double %90, %98
%100 = load double, double* %8
%101 = fmul double 2.000000e+00, %100
%102 = fdiv double %99, %101
store double %102, double* %14
%103 = load double, double* %15
%104 = load double, double* %14
%105 = fadd double %103, %104
store double %105, double* %16
%106 = load double, double* %17
%107 = fcmp ogt double %106, 0.000000e+00
br i1 %107, label %108, label %117
108: ; preds = %64
%109 = load double, double* %16
%110 = fcmp olt double %109, 0.000000e+00
br i1 %110, label %111, label %117
111: ; preds = %108
%112 = load i32, i32* %13
%113 = sitofp i32 %112 to double
%114 = load double, double* %8
%115 = fmul double %113, %114
%116 = load double*, double** %7
store double %115, double* %116
br label %122
117: ; preds = %108, %64
%118 = load double, double* %16
store double %118, double* %17
br label %119
119: ; preds = %117
%120 = load i32, i32* %13
%121 = add nsw i32 %120, -1
store i32 %121, i32* %13
br label %61
122: ; preds = %111, %61
ret void
}

LLVM IR (-O2):
define void @separation_point_shear_stress(double* nocapture writeonly %0, double %1, double %2, i32 %3, double** nocapture %4, double** nocapture %5) {
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds double*, double** %4, i64 %7
%9 = load double*, double** %8
%10 = getelementptr inbounds double, double* %9, i64 2
%11 = load double, double* %10
%12 = load double, double* %9
%13 = insertelement <2 x double> poison, double %2, i64 0
%14 = insertelement <2 x double> %13, double %1, i64 1
%15 = fmul <2 x double> %14, <double 2.000000e+00, double 2.000000e+00>
%16 = add nsw i32 %3, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double*, double** %5, i64 %17
%19 = load double*, double** %18
%20 = getelementptr inbounds double, double* %19, i64 1
%21 = load double, double* %20
%22 = add nsw i32 %3, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double*, double** %5, i64 %23
%25 = load double*, double** %24
%26 = getelementptr inbounds double, double* %25, i64 1
%27 = load double, double* %26
%28 = insertelement <2 x double> poison, double %11, i64 0
%29 = insertelement <2 x double> %28, double %21, i64 1
%30 = insertelement <2 x double> poison, double %12, i64 0
%31 = insertelement <2 x double> %30, double %27, i64 1
%32 = fsub <2 x double> %29, %31
%33 = fdiv <2 x double> %32, %15
%34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%35 = fadd <2 x double> %33, %34
%36 = extractelement <2 x double> %35, i64 0
%37 = zext i32 %22 to i64
br label %38
38: ; preds = %43, %6
%39 = phi i64 [ %54, %43 ], [ %37, %6 ]
%40 = phi double [ %68, %43 ], [ %36, %6 ]
%41 = trunc i64 %39 to i32
%42 = icmp sgt i32 %41, 1
br i1 %42, label %43, label %76
43: ; preds = %38
%44 = getelementptr inbounds double*, double** %4, i64 %39
%45 = load double*, double** %44
%46 = getelementptr inbounds double, double* %45, i64 2
%47 = load double, double* %46
%48 = load double, double* %45
%49 = add nuw nsw i64 %39, 1
%50 = getelementptr inbounds double*, double** %5, i64 %49
%51 = load double*, double** %50
%52 = getelementptr inbounds double, double* %51, i64 1
%53 = load double, double* %52
%54 = add nsw i64 %39, -1
%55 = and i64 %54, 4294967295
%56 = getelementptr inbounds double*, double** %5, i64 %55
%57 = load double*, double** %56
%58 = getelementptr inbounds double, double* %57, i64 1
%59 = load double, double* %58
%60 = insertelement <2 x double> poison, double %47, i64 0
%61 = insertelement <2 x double> %60, double %53, i64 1
%62 = insertelement <2 x double> poison, double %48, i64 0
%63 = insertelement <2 x double> %62, double %59, i64 1
%64 = fsub <2 x double> %61, %63
%65 = fdiv <2 x double> %64, %15
%66 = shufflevector <2 x double> %65, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%67 = fadd <2 x double> %65, %66
%68 = extractelement <2 x double> %67, i64 0
%69 = fcmp ogt double %40, 0.000000e+00
%70 = fcmp olt double %68, 0.000000e+00
%71 = select i1 %69, i1 %70, i1 false
br i1 %71, label %72, label %38
72: ; preds = %43
%73 = trunc i64 %39 to i32
%74 = sitofp i32 %73 to double
%75 = fmul double %74, %1
store double %75, double* %0
br label %76
76: ; preds = %38, %72
ret void
}