#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 const);
double sin(double const);
void unit_vect_latlon(int size, const double *lon, const double *lat,
                      double *vlon, double *vlat) {
  double sin_lon, cos_lon, sin_lat, cos_lat;
  int n;
  for (n = 0; n < size; n++) {
    sin_lon = sin(lon[n]);
    cos_lon = cos(lon[n]);
    sin_lat = sin(lat[n]);
    cos_lat = cos(lat[n]);
    vlon[3 * n] = -sin_lon;
    vlon[3 * n + 1] = cos_lon;
    vlon[3 * n + 2] = 0.;
    vlat[3 * n] = -sin_lat * cos_lon;
    vlat[3 * n + 1] = -sin_lat * sin_lon;
    vlat[3 * n + 2] = cos_lat;
  }
}


x86 assembly (clang, -O0):
<unit_vect_latlon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128f <unit_vect_latlon+0x16f>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
imul   $0x3,-0x4c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1142 <unit_vect_latlon+0x22>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_vect_latlon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
jle    1206 <unit_vect_latlon+0xe6>
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x2,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r12,%r13,8),%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x30(%rsp)
movsd  (%r12,%r13,8),%xmm0
call   1040 <cos@plt>
movaps %xmm0,0x20(%rsp)
movsd  (%r15,%r13,8),%xmm0
call   1030 <sin@plt>
movaps %xmm0,0x10(%rsp)
movsd  (%r15,%r13,8),%xmm0
call   1040 <cos@plt>
movdqa 0x30(%rsp),%xmm3
movdqa %xmm3,%xmm1
movdqa 0xe53(%rip),%xmm2
pxor   %xmm2,%xmm1
movq   %xmm1,-0x10(%rbx,%rbp,8)
movdqa 0x20(%rsp),%xmm1
movq   %xmm1,-0x8(%rbx,%rbp,8)
movq   $0x0,(%rbx,%rbp,8)
movdqa 0x10(%rsp),%xmm4
pxor   %xmm2,%xmm4
punpcklqdq %xmm3,%xmm1
movdqa %xmm1,%xmm2
pshufd $0x44,%xmm4,%xmm1
mulpd  %xmm2,%xmm1
movupd %xmm1,-0x10(%r14,%rbp,8)
movsd  %xmm0,(%r14,%rbp,8)
add    $0x1,%r13
add    $0x3,%rbp
cmp    %r13,0x8(%rsp)
jne    1160 <unit_vect_latlon+0x40>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @unit_vect_latlon(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %39
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %37, %9 ]
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = tail call double @sin(double %12)
%14 = load double, double* %11
%15 = tail call double @cos(double %14)
%16 = getelementptr inbounds double, double* %2, i64 %10
%17 = load double, double* %16
%18 = tail call double @sin(double %17)
%19 = load double, double* %16
%20 = tail call double @cos(double %19)
%21 = fneg double %13
%22 = mul nuw nsw i64 %10, 3
%23 = getelementptr inbounds double, double* %3, i64 %22
store double %21, double* %23
%24 = add nuw nsw i64 %22, 1
%25 = getelementptr inbounds double, double* %3, i64 %24
store double %15, double* %25
%26 = add nuw nsw i64 %22, 2
%27 = getelementptr inbounds double, double* %3, i64 %26
store double 0.000000e+00, double* %27
%28 = fneg double %18
%29 = getelementptr inbounds double, double* %4, i64 %22
%30 = insertelement <2 x double> poison, double %15, i64 0
%31 = insertelement <2 x double> %30, double %13, i64 1
%32 = insertelement <2 x double> poison, double %28, i64 0
%33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
%34 = fmul <2 x double> %31, %33
%35 = bitcast double* %29 to <2 x double>*
store <2 x double> %34, <2 x double>* %35
%36 = getelementptr inbounds double, double* %4, i64 %26
store double %20, double* %36
%37 = add nuw nsw i64 %10, 1
%38 = icmp eq i64 %37, %8
br i1 %38, label %39, label %9
39: ; preds = %9, %5
ret void
}