; LLVM IR from pmla/polyhedral-template-matching :: ptm_polar.ll (ZN3ptm23polar_decomposition_3x3EPdbS0_S0_)

; 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"

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3ptm23polar_decomposition_3x3EPdbS0_S0_(ptr noundef %0, i1 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [9 x double], align 16
  %10 = alloca double, align 8
  %11 = alloca [4 x double], align 16
  %12 = alloca double, align 8
  %13 = alloca [9 x double], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  %14 = zext i1 %1 to i8
  store i8 %14, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 72, ptr %9) #5
  %15 = getelementptr inbounds [9 x double], ptr %9, i64 0, i64 0
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %15, ptr align 8 %16, i64 72, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %17 = getelementptr inbounds [9 x double], ptr %9, i64 0, i64 0
  %18 = call noundef double @_ZN3ptmL22matrix_determinant_3x3EPd(ptr noundef %17)
  store double %18, ptr %10, align 8, !tbaa !11
  %19 = load double, ptr %10, align 8, !tbaa !11
  %20 = fcmp olt double %19, 0.000000e+00
  br i1 %20, label %21, label %23

21:                                               ; preds = %4
  %22 = getelementptr inbounds [9 x double], ptr %9, i64 0, i64 0
  call void @_ZN3ptmL11flip_matrixEPd(ptr noundef %22)
  br label %23

23:                                               ; preds = %21, %4
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  %24 = getelementptr inbounds [9 x double], ptr %9, i64 0, i64 0
  %25 = getelementptr inbounds [4 x double], ptr %11, i64 0, i64 0
  %26 = call noundef zeroext i1 @_ZN3ptmL18optimal_quaternionEPdbdS0_S0_(ptr noundef %24, i1 noundef zeroext true, double noundef -1.000000e+00, ptr noundef %12, ptr noundef %25)
  %27 = getelementptr inbounds [4 x double], ptr %11, i64 0, i64 0
  %28 = load double, ptr %27, align 16, !tbaa !11
  %29 = fneg double %28
  %30 = getelementptr inbounds [4 x double], ptr %11, i64 0, i64 0
  store double %29, ptr %30, align 16, !tbaa !11
  %31 = getelementptr inbounds [4 x double], ptr %11, i64 0, i64 0
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef %31, ptr noundef %32)
  %33 = load double, ptr %10, align 8, !tbaa !11
  %34 = fcmp olt double %33, 0.000000e+00
  br i1 %34, label %35, label %37

35:                                               ; preds = %23
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN3ptmL11flip_matrixEPd(ptr noundef %36)
  br label %37

37:                                               ; preds = %35, %23
  call void @llvm.lifetime.start.p0(i64 72, ptr %13) #5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %38, i64 0
  %40 = load double, ptr %39, align 8, !tbaa !11
  store double %40, ptr %13, align 8, !tbaa !11
  %41 = getelementptr inbounds double, ptr %13, i64 1
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 3
  %44 = load double, ptr %43, align 8, !tbaa !11
  store double %44, ptr %41, align 8, !tbaa !11
  %45 = getelementptr inbounds double, ptr %13, i64 2
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %46, i64 6
  %48 = load double, ptr %47, align 8, !tbaa !11
  store double %48, ptr %45, align 8, !tbaa !11
  %49 = getelementptr inbounds double, ptr %13, i64 3
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %50, i64 1
  %52 = load double, ptr %51, align 8, !tbaa !11
  store double %52, ptr %49, align 8, !tbaa !11
  %53 = getelementptr inbounds double, ptr %13, i64 4
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds double, ptr %54, i64 4
  %56 = load double, ptr %55, align 8, !tbaa !11
  store double %56, ptr %53, align 8, !tbaa !11
  %57 = getelementptr inbounds double, ptr %13, i64 5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds double, ptr %58, i64 7
  %60 = load double, ptr %59, align 8, !tbaa !11
  store double %60, ptr %57, align 8, !tbaa !11
  %61 = getelementptr inbounds double, ptr %13, i64 6
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds double, ptr %62, i64 2
  %64 = load double, ptr %63, align 8, !tbaa !11
  store double %64, ptr %61, align 8, !tbaa !11
  %65 = getelementptr inbounds double, ptr %13, i64 7
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds double, ptr %66, i64 5
  %68 = load double, ptr %67, align 8, !tbaa !11
  store double %68, ptr %65, align 8, !tbaa !11
  %69 = getelementptr inbounds double, ptr %13, i64 8
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds double, ptr %70, i64 8
  %72 = load double, ptr %71, align 8, !tbaa !11
  store double %72, ptr %69, align 8, !tbaa !11
  %73 = load i8, ptr %6, align 1, !tbaa !9, !range !13, !noundef !14
  %74 = trunc i8 %73 to i1
  br i1 %74, label %75, label %79

75:                                               ; preds = %37
  %76 = getelementptr inbounds [9 x double], ptr %13, i64 0, i64 0
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef %76, ptr noundef %77, ptr noundef %78)
  br label %83

79:                                               ; preds = %37
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds [9 x double], ptr %13, i64 0, i64 0
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef %80, ptr noundef %81, ptr noundef %82)
  br label %83

83:                                               ; preds = %79, %75
  call void @llvm.lifetime.end.p0(i64 72, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 72, ptr %9) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN3ptmL22matrix_determinant_3x3EPd(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN3ptmL11flip_matrixEPd(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN3ptmL18optimal_quaternionEPdbdS0_S0_(ptr noundef, i1 noundef zeroext, double noundef, ptr noundef, ptr noundef) #1

declare void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef, ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef, ptr noundef, ptr noundef) #3

; 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 nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #4 = { "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 #5 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3ptm23polar_decomposition_3x3EPdbS0_S0_(ptr noundef %0, i1 noundef zeroext %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca [9 x double], align 16
  %6 = alloca [4 x double], align 16
  %7 = alloca double, align 8
  %8 = alloca [9 x double], align 16
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(72) %5, ptr noundef nonnull align 8 dereferenceable(72) %0, i64 72, i1 false)
  %9 = call noundef double @_ZN3ptmL22matrix_determinant_3x3EPd(ptr noundef nonnull %5)
  %10 = fcmp olt double %9, 0.000000e+00
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %4
  call void @_ZN3ptmL11flip_matrixEPd(ptr noundef nonnull %5)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  %12 = call noundef zeroext i1 @_ZN3ptmL18optimal_quaternionEPdbdS0_S0_(ptr noundef nonnull %5, i1 noundef zeroext true, double noundef -1.000000e+00, ptr noundef nonnull %7, ptr noundef nonnull %6)
  %13 = load double, ptr %6, align 16, !tbaa !5
  %14 = fneg double %13
  store double %14, ptr %6, align 16, !tbaa !5
  call void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef nonnull %6, ptr noundef %2)
  call void @_ZN3ptmL11flip_matrixEPd(ptr noundef %2)
  br label %18

.critedge:                                        ; preds = %4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN3ptmL18optimal_quaternionEPdbdS0_S0_(ptr noundef nonnull %5, i1 noundef zeroext true, double noundef -1.000000e+00, ptr noundef nonnull %7, ptr noundef nonnull %6)
  %16 = load double, ptr %6, align 16, !tbaa !5
  %17 = fneg double %16
  store double %17, ptr %6, align 16, !tbaa !5
  call void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef nonnull %6, ptr noundef %2)
  br label %18

18:                                               ; preds = %.critedge, %11
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %8) #5
  %19 = load double, ptr %2, align 8, !tbaa !5
  store double %19, ptr %8, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %8, i64 8
  %21 = getelementptr inbounds i8, ptr %2, i64 24
  %22 = load double, ptr %21, align 8, !tbaa !5
  store double %22, ptr %20, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %8, i64 16
  %24 = getelementptr inbounds i8, ptr %2, i64 48
  %25 = load double, ptr %24, align 8, !tbaa !5
  store double %25, ptr %23, align 16, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %8, i64 24
  %27 = getelementptr inbounds i8, ptr %2, i64 8
  %28 = load double, ptr %27, align 8, !tbaa !5
  store double %28, ptr %26, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %8, i64 32
  %30 = getelementptr inbounds i8, ptr %2, i64 32
  %31 = load double, ptr %30, align 8, !tbaa !5
  store double %31, ptr %29, align 16, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %8, i64 40
  %33 = getelementptr inbounds i8, ptr %2, i64 56
  %34 = load double, ptr %33, align 8, !tbaa !5
  store double %34, ptr %32, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %8, i64 48
  %36 = getelementptr inbounds i8, ptr %2, i64 16
  %37 = load double, ptr %36, align 8, !tbaa !5
  store double %37, ptr %35, align 16, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %8, i64 56
  %39 = getelementptr inbounds i8, ptr %2, i64 40
  %40 = load double, ptr %39, align 8, !tbaa !5
  store double %40, ptr %38, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %8, i64 64
  %42 = getelementptr inbounds i8, ptr %2, i64 64
  %43 = load double, ptr %42, align 8, !tbaa !5
  store double %43, ptr %41, align 16, !tbaa !5
  br i1 %1, label %44, label %45

44:                                               ; preds = %18
  call void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef nonnull %8, ptr noundef nonnull %0, ptr noundef %3)
  br label %46

45:                                               ; preds = %18
  call void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef nonnull %0, ptr noundef nonnull %8, ptr noundef %3)
  br label %46

46:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %5) #5
  ret i32 0
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZN3ptmL22matrix_determinant_3x3EPd(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN3ptmL11flip_matrixEPd(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN3ptmL18optimal_quaternionEPdbdS0_S0_(ptr noundef, i1 noundef zeroext, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @_ZN3ptm29quaternion_to_rotation_matrixEPdS0_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN3ptmL10matmul_3x3EPdS0_S0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass