#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 C_sumof2uniforms_cdf(double *, double const *, double const *, int *);
void C_rss2Dloop(const double *x, const double *y, const double *ax,
                 const double *ay, const int *n, const int *n_theta,
                 double *ans) {
  double p;
  for (int i_theta = 0; i_theta < *n_theta; i_theta++) {
    for (int i = 0; i < *n; i++) {
      p = x[i] * ax[i_theta] + y[i] * ay[i_theta];
      ans[i + *n * i_theta] = C_sumof2uniforms_cdf(&p, ax, ay, &i_theta);
    }
  }
}


x86 assembly (clang, -O0):
<C_rss2Dloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%eax
jge    11f2 <C_rss2Dloop+0xe2>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%eax
jge    11df <C_rss2Dloop+0xcf>
mov    -0x8(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x3c(%rbp),%rcx
call   1030 <C_sumof2uniforms_cdf@plt>
mov    0x10(%rbp),%rax
mov    -0x40(%rbp),%ecx
mov    -0x28(%rbp),%rdx
mov    (%rdx),%edx
imul   -0x3c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1151 <C_rss2Dloop+0x41>
jmp    11e4 <C_rss2Dloop+0xd4>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    113b <C_rss2Dloop+0x2b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<C_rss2Dloop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r12
movl   $0x0,0xc(%rsp)
mov    %r9,0x18(%rsp)
mov    (%r9),%edx
test   %edx,%edx
jle    11f2 <C_rss2Dloop+0xe2>
mov    %r8,%r13
mov    %rcx,%rbx
mov    %rsi,%rbp
mov    (%r8),%esi
xor    %eax,%eax
lea    0x10(%rsp),%r9
lea    0xc(%rsp),%r15
mov    %rdi,0x20(%rsp)
jmp    116f <C_rss2Dloop+0x5f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%eax
mov    %eax,0xc(%rsp)
cmp    %edx,%eax
jge    11f2 <C_rss2Dloop+0xe2>
test   %esi,%esi
jle    1160 <C_rss2Dloop+0x50>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
movsd  (%rdi,%r14,8),%xmm0
cltq
movsd  0x0(%rbp,%r14,8),%xmm1
mulsd  (%rbx,%rax,8),%xmm1
mulsd  (%r12,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r9,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <C_sumof2uniforms_cdf@plt>
lea    0x10(%rsp),%r9
mov    0x20(%rsp),%rdi
mov    0x60(%rsp),%r11
movslq 0x0(%r13),%rsi
mov    0xc(%rsp),%eax
mov    %eax,%edx
imul   %esi,%edx
movslq %edx,%rdx
add    %r14,%rdx
movsd  %xmm0,(%r11,%rdx,8)
add    $0x1,%r14
cmp    %rsi,%r14
jl     1180 <C_rss2Dloop+0x70>
mov    0x18(%rsp),%rdx
mov    (%rdx),%edx
jmp    1160 <C_rss2Dloop+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @C_rss2Dloop(double* %0, double* %1, double* %2, double* %3, i32* %4, i32* %5, double* %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca double*
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
store double* %0, double** %8
store double* %1, double** %9
store double* %2, double** %10
store double* %3, double** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store double* %6, double** %14
store i32 0, i32* %16
br label %18
18: ; preds = %68, %7
%19 = load i32, i32* %16
%20 = load i32*, i32** %13
%21 = load i32, i32* %20
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %71
23: ; preds = %18
store i32 0, i32* %17
br label %24
24: ; preds = %64, %23
%25 = load i32, i32* %17
%26 = load i32*, i32** %12
%27 = load i32, i32* %26
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %67
29: ; preds = %24
%30 = load double*, double** %8
%31 = load i32, i32* %17
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = load double*, double** %10
%36 = load i32, i32* %16
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %9
%41 = load i32, i32* %17
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %11
%46 = load i32, i32* %16
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = fmul double %44, %49
%51 = call double @llvm.fmuladd.f64(double %34, double %39, double %50)
store double %51, double* %15
%52 = load double*, double** %10
%53 = load double*, double** %11
%54 = call double @C_sumof2uniforms_cdf(double* %15, double* %52, double* %53, i32* %16)
%55 = load double*, double** %14
%56 = load i32, i32* %17
%57 = load i32*, i32** %12
%58 = load i32, i32* %57
%59 = load i32, i32* %16
%60 = mul nsw i32 %58, %59
%61 = add nsw i32 %56, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %55, i64 %62
store double %54, double* %63
br label %64
64: ; preds = %29
%65 = load i32, i32* %17
%66 = add nsw i32 %65, 1
store i32 %66, i32* %17
br label %24
67: ; preds = %24
br label %68
68: ; preds = %67
%69 = load i32, i32* %16
%70 = add nsw i32 %69, 1
store i32 %70, i32* %16
br label %18
71: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @C_rss2Dloop(double* nocapture %0, double* nocapture %1, double* %2, double* %3, i32* nocapture %4, i32* nocapture %5, double* nocapture writeonly %6) {
%8 = alloca double
%9 = alloca i32
%10 = bitcast double* %8 to i8*
%11 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = load i32, i32* %4
br label %16
16: ; preds = %14, %24
%17 = phi i32 [ %12, %14 ], [ %25, %24 ]
%18 = phi i32 [ 0, %14 ], [ %28, %24 ]
%19 = phi i32 [ %15, %14 ], [ %27, %24 ]
%20 = icmp sgt i32 %19, 0
br i1 %20, label %30, label %24
21: ; preds = %24, %7
ret void
22: ; preds = %30
%23 = load i32, i32* %5
br label %24
24: ; preds = %22, %16
%25 = phi i32 [ %23, %22 ], [ %17, %16 ]
%26 = phi i32 [ %46, %22 ], [ %18, %16 ]
%27 = phi i32 [ %45, %22 ], [ %19, %16 ]
%28 = add nsw i32 %26, 1
store i32 %28, i32* %9
%29 = icmp slt i32 %28, %25
br i1 %29, label %16, label %21
30: ; preds = %16, %30
%31 = phi i32 [ %46, %30 ], [ %18, %16 ]
%32 = phi i64 [ %52, %30 ], [ 0, %16 ]
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = sext i32 %31 to i64
%36 = getelementptr inbounds double, double* %2, i64 %35
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %1, i64 %32
%39 = load double, double* %38
%40 = getelementptr inbounds double, double* %3, i64 %35
%41 = load double, double* %40
%42 = fmul double %39, %41
%43 = call double @llvm.fmuladd.f64(double %34, double %37, double %42)
store double %43, double* %8
%44 = call double @C_sumof2uniforms_cdf(double* %8, double* %2, double* %3, i32* %9)
%45 = load i32, i32* %4
%46 = load i32, i32* %9
%47 = mul nsw i32 %46, %45
%48 = trunc i64 %32 to i32
%49 = add nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %6, i64 %50
store double %44, double* %51
%52 = add nuw nsw i64 %32, 1
%53 = sext i32 %45 to i64
%54 = icmp slt i64 %52, %53
br i1 %54, label %30, label %22
}