_Bool rotation_matrix_2D(double R[][2], double alpha) {
  static double I[2][2] = {{1, 0}, {0, 1}};
  if (fabs(alpha) < 0.001) {
    memcpy(R, I, sizeof(I));
    return 0;
  } else {
    R[0][0] = cos(alpha);
    R[0][1] = -sin(alpha);
    R[1][0] = sin(alpha);
    R[1][1] = cos(alpha);
    return 1;
  }
}


x86 assembly (clang, -O0):
<rotation_matrix_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movaps 0xed3(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xeb7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    118b <rotation_matrix_2D+0x6b>
mov    -0x10(%rbp),%rax
mov    0x2ee2(%rip),%rcx
mov    %rcx,(%rax)
mov    0x2ee0(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    0x2edd(%rip),%rcx
mov    %rcx,0x10(%rax)
mov    0x2eda(%rip),%rcx
mov    %rcx,0x18(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11f1 <rotation_matrix_2D+0xd1>
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x18(%rbp),%xmm0
call   1040 <cos@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x18(%rax)
movb   $0x1,-0x1(%rbp)
mov    -0x1(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotation_matrix_2D>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movapd 0xed0(%rip),%xmm1
andpd  %xmm0,%xmm1
movsd  0xee4(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1159 <rotation_matrix_2D+0x39>
movaps 0xef7(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movaps 0xedc(%rip),%xmm0
movups %xmm0,(%rbx)
jmp    11ab <rotation_matrix_2D+0x8b>
movapd %xmm0,(%rsp)
movapd %xmm1,0x10(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,(%rbx)
movaps (%rsp),%xmm0
call   1030 <sin@plt>
xorps  0xe93(%rip),%xmm0
movlps %xmm0,0x8(%rbx)
movaps (%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rbx)
movaps (%rsp),%xmm0
call   1040 <cos@plt>
movsd  0xe80(%rip),%xmm2
movapd 0x10(%rsp),%xmm1
movsd  %xmm0,0x18(%rbx)
ucomisd %xmm1,%xmm2
setbe  %al
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@rotation_matrix_2D.I = internal global [2 x [2 x double]] [[2 x double] [double 1.000000e+00, double 0.000000e+00], [2 x double] [double 0.000000e+00, double 1.000000e+00]]
define zeroext i1 @rotation_matrix_2D([2 x double]* %0, double %1) {
%3 = alloca i1
%4 = alloca [2 x double]*
%5 = alloca double
store [2 x double]* %0, [2 x double]** %4
store double %1, double* %5
%6 = load double, double* %5
%7 = call double @llvm.fabs.f64(double %6)
%8 = fcmp olt double %7, 1.000000e-03
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load [2 x double]*, [2 x double]** %4
%11 = bitcast [2 x double]* %10 to i8*
store i1 false, i1* %3
br label %34
12: ; preds = %2
%13 = load double, double* %5
%14 = call double @cos(double %13)
%15 = load [2 x double]*, [2 x double]** %4
%16 = getelementptr inbounds [2 x double], [2 x double]* %15, i64 0
%17 = getelementptr inbounds [2 x double], [2 x double]* %16, i64 0, i64 0
store double %14, double* %17
%18 = load double, double* %5
%19 = call double @sin(double %18)
%20 = fneg double %19
%21 = load [2 x double]*, [2 x double]** %4
%22 = getelementptr inbounds [2 x double], [2 x double]* %21, i64 0
%23 = getelementptr inbounds [2 x double], [2 x double]* %22, i64 0, i64 1
store double %20, double* %23
%24 = load double, double* %5
%25 = call double @sin(double %24)
%26 = load [2 x double]*, [2 x double]** %4
%27 = getelementptr inbounds [2 x double], [2 x double]* %26, i64 1
%28 = getelementptr inbounds [2 x double], [2 x double]* %27, i64 0, i64 0
store double %25, double* %28
%29 = load double, double* %5
%30 = call double @cos(double %29)
%31 = load [2 x double]*, [2 x double]** %4
%32 = getelementptr inbounds [2 x double], [2 x double]* %31, i64 1
%33 = getelementptr inbounds [2 x double], [2 x double]* %32, i64 0, i64 1
store double %30, double* %33
store i1 true, i1* %3
br label %34
34: ; preds = %12, %9
%35 = load i1, i1* %3
ret i1 %35
}

LLVM IR (-O2):
@rotation_matrix_2D.I = internal unnamed_addr constant [2 x [2 x double]] [[2 x double] [double 1.000000e+00, double 0.000000e+00], [2 x double] [double 0.000000e+00, double 1.000000e+00]]
define zeroext i1 @rotation_matrix_2D([2 x double]* nocapture writeonly %0, double %1) {
%3 = tail call double @llvm.fabs.f64(double %1)
%4 = fcmp olt double %3, 1.000000e-03
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = bitcast [2 x double]* %0 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(32) %6, i8* align 16 dereferenceable(32) bitcast ([2 x [2 x double]]* @rotation_matrix_2D.I to i8*), i64 32, i1 false)
br label %17
7: ; preds = %2
%8 = tail call double @cos(double %1)
%9 = getelementptr inbounds [2 x double], [2 x double]* %0, i64 0, i64 0
store double %8, double* %9
%10 = tail call double @sin(double %1)
%11 = fneg double %10
%12 = getelementptr inbounds [2 x double], [2 x double]* %0, i64 0, i64 1
store double %11, double* %12
%13 = tail call double @sin(double %1)
%14 = getelementptr inbounds [2 x double], [2 x double]* %0, i64 1, i64 0
store double %13, double* %14
%15 = tail call double @cos(double %1)
%16 = getelementptr inbounds [2 x double], [2 x double]* %0, i64 1, i64 1
store double %15, double* %16
br label %17
17: ; preds = %7, %5
%18 = xor i1 %4, true
ret i1 %18
}