#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 */
scalar_t__ FLT_MIN;
scalar_t__ fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void decompose_vector_basis(double a[2], double x[2], double u[2],
                            double v[2]) {
  double det = u[0] * v[1] - u[1] * v[0];
  if (fabs(det) < FLT_MIN) {
    fprintf(stderr, "ERROR: the given basis is not a basis\n");
    fprintf(stderr, "\tu: (%g, %g), v: (%g, %g)\n", u[0], u[1], v[0], v[1]);
  }
  a[0] = v[1] * x[0] - v[0] * x[1];
  a[1] = -u[1] * x[0] + u[0] * x[1];
  a[0] /= det;
  a[1] /= det;
}


x86 assembly (clang, -O0):
<decompose_vector_basis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
jge    11e8 <decompose_vector_basis+0xc8>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm3
lea    0xe46(%rip),%rsi
mov    $0x4,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompose_vector_basis>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
movsd  (%rcx),%xmm1
mulsd  0x8(%rdx),%xmm1
movsd  (%rdx),%xmm0
mulsd  0x8(%rcx),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,(%rsp)
call   1030 <fabs@plt>
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
jge    11a6 <decompose_vector_basis+0x86>
mov    0x2e6c(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe89(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
movsd  (%r12),%xmm0
movsd  0x8(%r12),%xmm1
movsd  (%rbx),%xmm2
movsd  0x8(%rbx),%xmm3
lea    0xe88(%rip),%rsi
mov    $0x4,%al
call   1040 <fprintf@plt>
movsd  0x8(%r15),%xmm0
mulsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
mulsd  (%r15),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movsd  (%r12),%xmm0
mulsd  0x8(%r15),%xmm0
movsd  0x8(%r12),%xmm2
mulsd  (%r15),%xmm2
subsd  %xmm2,%xmm0
unpcklpd %xmm0,%xmm1
movapd (%rsp),%xmm0
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm1
movupd %xmm1,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FLT_MIN = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"ERROR: the given basis is not a basis\0A\00"
@.str.1 = [27 x i8] c"\09u: (%g, %g), v: (%g, %g)\0A\00"
define void @decompose_vector_basis(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%10 = load double*, double** %7
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %8
%14 = getelementptr inbounds double, double* %13, i64 1
%15 = load double, double* %14
%16 = load double*, double** %7
%17 = getelementptr inbounds double, double* %16, i64 1
%18 = load double, double* %17
%19 = load double*, double** %8
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = fmul double %18, %21
%23 = fneg double %22
%24 = call double @llvm.fmuladd.f64(double %12, double %15, double %23)
store double %24, double* %9
%25 = load double, double* %9
%26 = call i64 @fabs(double %25)
%27 = load i64, i64* @FLT_MIN
%28 = icmp slt i64 %26, %27
br i1 %28, label %29, label %46
29: ; preds = %4
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = load double*, double** %7
%34 = getelementptr inbounds double, double* %33, i64 0
%35 = load double, double* %34
%36 = load double*, double** %7
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
%39 = load double*, double** %8
%40 = getelementptr inbounds double, double* %39, i64 0
%41 = load double, double* %40
%42 = load double*, double** %8
%43 = getelementptr inbounds double, double* %42, i64 1
%44 = load double, double* %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %35, double %38, double %41, double %44)
br label %46
46: ; preds = %29, %4
%47 = load double*, double** %8
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
%50 = load double*, double** %6
%51 = getelementptr inbounds double, double* %50, i64 0
%52 = load double, double* %51
%53 = load double*, double** %8
%54 = getelementptr inbounds double, double* %53, i64 0
%55 = load double, double* %54
%56 = load double*, double** %6
%57 = getelementptr inbounds double, double* %56, i64 1
%58 = load double, double* %57
%59 = fmul double %55, %58
%60 = fneg double %59
%61 = call double @llvm.fmuladd.f64(double %49, double %52, double %60)
%62 = load double*, double** %5
%63 = getelementptr inbounds double, double* %62, i64 0
store double %61, double* %63
%64 = load double*, double** %7
%65 = getelementptr inbounds double, double* %64, i64 1
%66 = load double, double* %65
%67 = fneg double %66
%68 = load double*, double** %6
%69 = getelementptr inbounds double, double* %68, i64 0
%70 = load double, double* %69
%71 = load double*, double** %7
%72 = getelementptr inbounds double, double* %71, i64 0
%73 = load double, double* %72
%74 = load double*, double** %6
%75 = getelementptr inbounds double, double* %74, i64 1
%76 = load double, double* %75
%77 = fmul double %73, %76
%78 = call double @llvm.fmuladd.f64(double %67, double %70, double %77)
%79 = load double*, double** %5
%80 = getelementptr inbounds double, double* %79, i64 1
store double %78, double* %80
%81 = load double, double* %9
%82 = load double*, double** %5
%83 = getelementptr inbounds double, double* %82, i64 0
%84 = load double, double* %83
%85 = fdiv double %84, %81
store double %85, double* %83
%86 = load double, double* %9
%87 = load double*, double** %5
%88 = getelementptr inbounds double, double* %87, i64 1
%89 = load double, double* %88
%90 = fdiv double %89, %86
store double %90, double* %88
ret void
}

LLVM IR (-O2):
@FLT_MIN = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"ERROR: the given basis is not a basis\0A\00"
@.str.1 = [27 x i8] c"\09u: (%g, %g), v: (%g, %g)\0A\00"
define void @decompose_vector_basis(double* nocapture %0, double* nocapture %1, double* nocapture %2, double* nocapture %3) {
%5 = load double, double* %2
%6 = getelementptr inbounds double, double* %3, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %2, i64 1
%9 = load double, double* %8
%10 = load double, double* %3
%11 = fneg double %9
%12 = fmul double %10, %11
%13 = tail call double @llvm.fmuladd.f64(double %5, double %7, double %12)
%14 = tail call i64 @fabs(double %13)
%15 = load i64, i64* @FLT_MIN
%16 = icmp slt i64 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = load double, double* %2
%22 = load double, double* %8
%23 = load double, double* %3
%24 = load double, double* %6
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %21, double %22, double %23, double %24)
br label %26
26: ; preds = %17, %4
%27 = load double, double* %6
%28 = load double, double* %1
%29 = load double, double* %3
%30 = getelementptr inbounds double, double* %1, i64 1
%31 = load double, double* %30
%32 = fneg double %29
%33 = fmul double %31, %32
%34 = tail call double @llvm.fmuladd.f64(double %27, double %28, double %33)
store double %34, double* %0
%35 = load double, double* %8
%36 = fneg double %35
%37 = load double, double* %1
%38 = load double, double* %2
%39 = load double, double* %30
%40 = fmul double %38, %39
%41 = tail call double @llvm.fmuladd.f64(double %36, double %37, double %40)
%42 = insertelement <2 x double> poison, double %34, i64 0
%43 = insertelement <2 x double> %42, double %41, i64 1
%44 = insertelement <2 x double> poison, double %13, i64 0
%45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
%46 = fdiv <2 x double> %43, %45
%47 = bitcast double* %0 to <2 x double>*
store <2 x double> %46, <2 x double>* %47
ret void
}