; LLVM IR from sp-nitech/SPTK :: src/math/matrix2d.ll (ZNK4sptk8Matrix2D6InvertEPS0_)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.sptk::Matrix2D" = type { ptr, %union.anon }
%union.anon = type { [4 x double] }
%struct.anon = type { double, double, double, double }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk8Matrix2D6InvertEPS0_(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds %struct.anon, ptr %10, i32 0, i32 0
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 3
  %15 = load double, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %17 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 1
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 2
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fmul double %18, %21
  %23 = fneg double %22
  %24 = call double @llvm.fmuladd.f64(double %12, double %15, double %23)
  store double %24, ptr %6, align 8, !tbaa !10
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = icmp eq ptr null, %25
  br i1 %26, label %34, label %27

27:                                               ; preds = %2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp eq ptr %9, %28
  br i1 %29, label %34, label %30

30:                                               ; preds = %27
  %31 = load double, ptr %6, align 8, !tbaa !10
  %32 = call double @llvm.fabs.f64(double %31)
  %33 = fcmp olt double %32, 0x3EB0C6F7A0B5ED8D
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %27, %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %72

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %36 = load double, ptr %6, align 8, !tbaa !10
  %37 = fdiv double 1.000000e+00, %36
  store double %37, ptr %8, align 8, !tbaa !10
  %38 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 3
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = load double, ptr %8, align 8, !tbaa !10
  %42 = fmul double %40, %41
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 0
  store double %42, ptr %45, align 8, !tbaa !9
  %46 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %47 = getelementptr inbounds %struct.anon, ptr %46, i32 0, i32 1
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = fneg double %48
  %50 = load double, ptr %8, align 8, !tbaa !10
  %51 = fmul double %49, %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 1
  store double %51, ptr %54, align 8, !tbaa !9
  %55 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %56 = getelementptr inbounds %struct.anon, ptr %55, i32 0, i32 2
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = fneg double %57
  %59 = load double, ptr %8, align 8, !tbaa !10
  %60 = fmul double %58, %59
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.anon, ptr %62, i32 0, i32 2
  store double %60, ptr %63, align 8, !tbaa !9
  %64 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %9, i32 0, i32 1
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 0
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load double, ptr %8, align 8, !tbaa !10
  %68 = fmul double %66, %67
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.sptk::Matrix2D", ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds %struct.anon, ptr %70, i32 0, i32 3
  store double %68, ptr %71, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %72

72:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %73 = load i1, ptr %3, align 1
  ret i1 %73
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk8Matrix2D6InvertEPS0_(ptr noundef nonnull readonly align 8 dereferenceable(40) %0, ptr noundef writeonly %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fneg double %8
  %12 = fmul double %10, %11
  %13 = tail call double @llvm.fmuladd.f64(double %4, double %6, double %12)
  %14 = icmp ne ptr %1, null
  %15 = icmp ne ptr %0, %1
  %or.cond.not20 = and i1 %14, %15
  %16 = tail call double @llvm.fabs.f64(double %13)
  %17 = fcmp uge double %16, 0x3EB0C6F7A0B5ED8D
  %or.cond17.not = select i1 %or.cond.not20, i1 %17, i1 false
  br i1 %or.cond17.not, label %18, label %33

18:                                               ; preds = %2
  %19 = fdiv double 1.000000e+00, %13
  %20 = fmul double %6, %19
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = load double, ptr %7, align 8, !tbaa !5
  %23 = fneg double %22
  %24 = fmul double %19, %23
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  store double %24, ptr %25, align 8, !tbaa !5
  %26 = load double, ptr %9, align 8, !tbaa !5
  %27 = fneg double %26
  %28 = fmul double %19, %27
  %29 = getelementptr inbounds i8, ptr %1, i64 24
  store double %28, ptr %29, align 8, !tbaa !5
  %30 = load double, ptr %3, align 8, !tbaa !5
  %31 = fmul double %19, %30
  %32 = getelementptr inbounds i8, ptr %1, i64 32
  store double %31, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %2, %18
  ret i1 %or.cond17.not
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #0

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass