#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 const cos(double);
double const sin(double);
int amsp_coord_rotate(double out[3], double const v[3], double q, int axis) {
  int a1, a2;
  if (axis == 0) {
    a1 = 1;
    a2 = 2;
  } else if (axis == 1) {
    a1 = 2;
    a2 = 0;
  } else {
    a1 = 0;
    a2 = 1;
  }
  out[axis] = v[axis];
  out[a1] = v[a1] * cos(q) - v[a2] * sin(q);
  out[a2] = v[a1] * sin(q) + v[a2] * cos(q);
  return 0;
}


x86 assembly (clang, -O0):
<amsp_coord_rotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1155 <amsp_coord_rotate+0x35>
movl   $0x1,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
jmp    1185 <amsp_coord_rotate+0x65>
cmpl   $0x1,-0x1c(%rbp)
jne    1172 <amsp_coord_rotate+0x52>
movl   $0x2,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    1180 <amsp_coord_rotate+0x60>
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1185 <amsp_coord_rotate+0x65>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amsp_coord_rotate>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %edx,%edx
je     1145 <amsp_coord_rotate+0x25>
cmp    $0x1,%edx
jne    1153 <amsp_coord_rotate+0x33>
mov    $0x2,%r12d
xor    %r15d,%r15d
jmp    115c <amsp_coord_rotate+0x3c>
mov    $0x2,%r15d
mov    $0x1,%r12d
jmp    115c <amsp_coord_rotate+0x3c>
mov    $0x1,%r15d
xor    %r12d,%r12d
movslq %edx,%rax
movsd  (%rbx,%rax,8),%xmm1
movsd  %xmm1,(%r14,%rax,8)
movsd  (%rbx,%r12,8),%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx,%r15,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%r12,8)
movsd  (%rbx,%r12,8),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx,%r15,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r14,%r15,8)
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @amsp_coord_rotate(double* nocapture writeonly %0, double* nocapture %1, double %2, i32 %3) {
switch i32 %3, label %6 [
i32 0, label %7
i32 1, label %5
]
5: ; preds = %4
br label %7
6: ; preds = %4
br label %7
7: ; preds = %4, %5, %6
%8 = phi i64 [ 2, %5 ], [ 0, %6 ], [ 1, %4 ]
%9 = phi i64 [ 0, %5 ], [ 1, %6 ], [ 2, %4 ]
%10 = sext i32 %3 to i64
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %0, i64 %10
store double %12, double* %13
%14 = getelementptr inbounds double, double* %1, i64 %8
%15 = load double, double* %14
%16 = tail call double @cos(double %2)
%17 = getelementptr inbounds double, double* %1, i64 %9
%18 = load double, double* %17
%19 = tail call double @sin(double %2)
%20 = fneg double %18
%21 = fmul double %19, %20
%22 = tail call double @llvm.fmuladd.f64(double %15, double %16, double %21)
%23 = getelementptr inbounds double, double* %0, i64 %8
store double %22, double* %23
%24 = load double, double* %14
%25 = tail call double @sin(double %2)
%26 = load double, double* %17
%27 = tail call double @cos(double %2)
%28 = fmul double %26, %27
%29 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %28)
%30 = getelementptr inbounds double, double* %0, i64 %9
store double %29, double* %30
ret i32 0
}