#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__ ortho_transformed(double, int, int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(double);
double ortho_transformed_smeared(double d_max, int n, double height,
                                 double width, double q, int npts) {
  double sum, y, z;
  int i, j, n_height, n_width;
  double count_w;
  double fnpts;
  sum = 0.0;
  fnpts = (float)npts - 1.0;
  n_height = (height > 0) ? npts : 1;
  n_width = (width > 0) ? npts : 1;
  count_w = 0.0;
  for (j = 0; j < n_height; j++) {
    if (height > 0) {
      z = height / fnpts * (float)j;
    } else {
      z = 0.0;
    }
    for (i = 0; i < n_width; i++) {
      if (width > 0) {
        y = -width / 2.0 + width / fnpts * (float)i;
      } else {
        y = 0.0;
      }
      if (((q - y) * (q - y) + z * z) <= 0.0)
        continue;
      count_w += 1.0;
      sum += ortho_transformed(d_max, n, sqrt((q - y) * (q - y) + z * z));
    }
  }
  return sum / count_w;
}


x86 assembly (clang, -O0):
<ortho_transformed_smeared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2ssl -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea2(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1184 <ortho_transformed_smeared+0x64>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
jmp    1191 <ortho_transformed_smeared+0x71>
mov    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    1191 <ortho_transformed_smeared+0x71>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x54(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11b4 <ortho_transformed_smeared+0x94>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x70(%rbp)
jmp    11c1 <ortho_transformed_smeared+0xa1>
mov    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    11c1 <ortho_transformed_smeared+0xa1>
mov    -0x70(%rbp),%eax
mov    %eax,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    135b <ortho_transformed_smeared+0x23b>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1215 <ortho_transformed_smeared+0xf5>
movsd  -0x18(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
cvtsi2ssl -0x50(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    121d <ortho_transformed_smeared+0xfd>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1348 <ortho_transformed_smeared+0x228>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    128f <ortho_transformed_smeared+0x16f>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xda2(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
cvtsi2ssl -0x4c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1297 <ortho_transformed_smeared+0x177>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
subsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jb     12cf <ortho_transformed_smeared+0x1af>
jmp    133a <ortho_transformed_smeared+0x21a>
movsd  0xd29(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x74(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
subsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  -0x80(%rbp),%xmm0
mov    -0x74(%rbp),%edi
mov    %eax,%esi
call   1030 <ortho_transformed@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1224 <ortho_transformed_smeared+0x104>
jmp    134d <ortho_transformed_smeared+0x22d>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    11d6 <ortho_transformed_smeared+0xb6>
movsd  -0x38(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ortho_transformed_smeared>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
xorpd  %xmm8,%xmm8
ucomisd %xmm8,%xmm1
mov    $0x1,%r14d
cmova  %esi,%r14d
movsd  %xmm0,0x28(%rsp)
mov    $0x1,%ebp
ucomisd %xmm8,%xmm2
cmova  %esi,%ebp
test   %r14d,%r14d
jle    12c3 <ortho_transformed_smeared+0x1a3>
mov    %edi,%r12d
xorps  %xmm0,%xmm0
cvtsi2ss %esi,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe8e(%rip),%xmm0
xorpd  %xmm5,%xmm5
cmpltsd %xmm1,%xmm5
movapd %xmm5,0x40(%rsp)
divsd  %xmm0,%xmm1
movsd  0xe82(%rip),%xmm10
mulsd  %xmm2,%xmm10
xor    %r15d,%r15d
xorpd  %xmm4,%xmm4
cmpltsd %xmm2,%xmm4
divsd  %xmm0,%xmm2
xorpd  %xmm9,%xmm9
xorpd  %xmm7,%xmm7
movsd  %xmm1,0x20(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm10,0x8(%rsp)
movapd %xmm4,0x50(%rsp)
jmp    11dd <ortho_transformed_smeared+0xbd>
nopl   (%rax)
add    $0x1,%r15d
cmp    %r14d,%r15d
je     12bc <ortho_transformed_smeared+0x19c>
test   %ebp,%ebp
jle    11d0 <ortho_transformed_smeared+0xb0>
xorps  %xmm0,%xmm0
cvtsi2ss %r15d,%xmm0
xorps  %xmm6,%xmm6
cvtss2sd %xmm0,%xmm6
mulsd  %xmm1,%xmm6
andpd  0x40(%rsp),%xmm6
mulsd  %xmm6,%xmm6
xor    %ebx,%ebx
movapd %xmm6,0x60(%rsp)
jmp    1217 <ortho_transformed_smeared+0xf7>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     11d0 <ortho_transformed_smeared+0xb0>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
xorps  %xmm5,%xmm5
cvtss2sd %xmm0,%xmm5
mulsd  %xmm2,%xmm5
addsd  %xmm10,%xmm5
andpd  %xmm4,%xmm5
movapd %xmm3,%xmm0
subsd  %xmm5,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm6,%xmm0
ucomisd %xmm0,%xmm8
jae    1210 <ortho_transformed_smeared+0xf0>
addsd  0xdc7(%rip),%xmm7
movsd  %xmm7,0x30(%rsp)
movsd  %xmm9,0x38(%rsp)
call   1040 <sqrt@plt>
movsd  0x28(%rsp),%xmm0
mov    %r12d,%edi
mov    %eax,%esi
call   1030 <ortho_transformed@plt>
movapd 0x60(%rsp),%xmm6
movsd  0x30(%rsp),%xmm7
movapd 0x50(%rsp),%xmm4
movsd  0x38(%rsp),%xmm9
movsd  0x8(%rsp),%xmm10
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
xorpd  %xmm8,%xmm8
movsd  0x20(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm9
jmp    1210 <ortho_transformed_smeared+0xf0>
divsd  %xmm7,%xmm9
jmp    12cc <ortho_transformed_smeared+0x1ac>
movsd  0xd3c(%rip),%xmm9
movapd %xmm9,%xmm0
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @ortho_transformed_smeared(double %0, i32 %1, double %2, double %3, double %4, i32 %5) {
%7 = sitofp i32 %5 to float
%8 = fpext float %7 to double
%9 = fadd double %8, -1.000000e+00
%10 = fcmp ogt double %2, 0.000000e+00
%11 = select i1 %10, i32 %5, i32 1
%12 = fcmp ogt double %3, 0.000000e+00
%13 = select i1 %12, i32 %5, i32 1
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %59
15: ; preds = %6
%16 = fdiv double %2, %9
%17 = icmp sgt i32 %13, 0
%18 = fmul double %3, -5.000000e-01
%19 = fdiv double %3, %9
br label %20
20: ; preds = %15, %52
%21 = phi double [ 0.000000e+00, %15 ], [ %54, %52 ]
%22 = phi double [ 0.000000e+00, %15 ], [ %53, %52 ]
%23 = phi i32 [ 0, %15 ], [ %55, %52 ]
br i1 %17, label %24, label %52
24: ; preds = %20
%25 = sitofp i32 %23 to float
%26 = fpext float %25 to double
%27 = fmul double %16, %26
%28 = select i1 %10, double %27, double 0.000000e+00
%29 = fmul double %28, %28
br label %30
30: ; preds = %24, %47
%31 = phi double [ %21, %24 ], [ %49, %47 ]
%32 = phi double [ %22, %24 ], [ %48, %47 ]
%33 = phi i32 [ 0, %24 ], [ %50, %47 ]
%34 = sitofp i32 %33 to float
%35 = fpext float %34 to double
%36 = tail call double @llvm.fmuladd.f64(double %19, double %35, double %18)
%37 = select i1 %12, double %36, double 0.000000e+00
%38 = fsub double %4, %37
%39 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %29)
%40 = fcmp ugt double %39, 0.000000e+00
br i1 %40, label %41, label %47
41: ; preds = %30
%42 = fadd double %32, 1.000000e+00
%43 = tail call i32 @sqrt(double %39)
%44 = tail call i64 @ortho_transformed(double %0, i32 %1, i32 %43)
%45 = sitofp i64 %44 to double
%46 = fadd double %31, %45
br label %47
47: ; preds = %30, %41
%48 = phi double [ %32, %30 ], [ %42, %41 ]
%49 = phi double [ %31, %30 ], [ %46, %41 ]
%50 = add nuw nsw i32 %33, 1
%51 = icmp eq i32 %50, %13
br i1 %51, label %52, label %30
52: ; preds = %47, %20
%53 = phi double [ %22, %20 ], [ %48, %47 ]
%54 = phi double [ %21, %20 ], [ %49, %47 ]
%55 = add nuw nsw i32 %23, 1
%56 = icmp eq i32 %55, %11
br i1 %56, label %57, label %20
57: ; preds = %52
%58 = fdiv double %54, %53
br label %59
59: ; preds = %57, %6
%60 = phi double [ %58, %57 ], [ 0x7FF8000000000000, %6 ]
ret double %60
}