#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 cos(double);
double sin(double);
void dSphr2Cart(int len, double s[len][2], double c[len][3]) {
  for (int i = 0; i < len; i++) {
    double t = cos(s[i][1]);
    c[i][0] = t * cos(s[i][0]);
    c[i][1] = t * sin(s[i][0]);
    c[i][2] = sin(s[i][1]);
  }
}


x86 assembly (clang, -O0):
<dSphr2Cart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1222 <dSphr2Cart+0x102>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
call   1030 <sin@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  %xmm0,0x10(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <dSphr2Cart+0x1a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dSphr2Cart>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11ae <dSphr2Cart+0x8e>
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%eax
add    $0x8,%r12
shl    $0x3,%rax
lea    (%rax,%rax,2),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsd  (%r12),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  -0x8(%r12),%xmm0
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,1)
movsd  -0x8(%r12),%xmm0
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%r14,%rbx,1)
movsd  (%r12),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%r14,%rbx,1)
add    $0x10,%r12
add    $0x18,%rbx
cmp    %rbx,%r15
jne    1150 <dSphr2Cart+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @dSphr2Cart(i32 %0, [2 x double]* nocapture %1, [3 x double]* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %8
7: ; preds = %8, %3
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %25, %8 ]
%10 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %9, i64 1
%11 = load double, double* %10
%12 = tail call double @cos(double %11)
%13 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 %9, i64 0
%14 = load double, double* %13
%15 = tail call double @cos(double %14)
%16 = fmul double %12, %15
%17 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %9, i64 0
store double %16, double* %17
%18 = load double, double* %13
%19 = tail call double @sin(double %18)
%20 = fmul double %12, %19
%21 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %9, i64 1
store double %20, double* %21
%22 = load double, double* %10
%23 = tail call double @sin(double %22)
%24 = getelementptr inbounds [3 x double], [3 x double]* %2, i64 %9, i64 2
store double %23, double* %24
%25 = add nuw nsw i64 %9, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %7, label %8
}