; LLVM IR from KamilSJaron/smudgeplot :: src_ploidyplot (matrix)

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

%struct.Double_Matrix = type { i32, ptr }
%struct.LU_Factor = type { ptr, ptr, i32 }

@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1

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

declare ptr @Malloc(i64 noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @LU_Solve(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @Transpose_Matrix(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @LU_Invert(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.Double_Matrix, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LU_Factor, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.Double_Matrix, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !13
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = call ptr @Malloc(i64 noundef 16, ptr noundef @.str.5)
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = mul i64 8, %19
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = mul i64 %20, %22
  %24 = call ptr @Malloc(i64 noundef %23, ptr noundef @.str.5)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %30, label %27

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

30:                                               ; preds = %27, %2
  call void @exit(i32 noundef 1) #5
  unreachable

31:                                               ; preds = %27
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Double_Matrix, ptr %33, i32 0, i32 0
  store i32 %32, ptr %34, align 8, !tbaa !13
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Double_Matrix, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !15
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = getelementptr inbounds %struct.Double_Matrix, ptr %9, i32 0, i32 0
  store i32 %38, ptr %39, align 8, !tbaa !13
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %40, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %71, %31
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %74

45:                                               ; preds = %41
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Double_Matrix, ptr %9, i32 0, i32 1
  store ptr %46, ptr %47, align 8, !tbaa !15
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %57, %45
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %60

52:                                               ; preds = %48
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  store double 0.000000e+00, ptr %56, align 8, !tbaa !16
  br label %57

57:                                               ; preds = %52
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %7, align 4, !tbaa !9
  br label %48, !llvm.loop !18

60:                                               ; preds = %48
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  store double 1.000000e+00, ptr %64, align 8, !tbaa !16
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = call ptr @LU_Solve(ptr noundef %9, ptr noundef %65)
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds double, ptr %68, i64 %69
  store ptr %70, ptr %11, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %60
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %6, align 4, !tbaa !9
  br label %41, !llvm.loop !20

74:                                               ; preds = %41
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %80, label %77

77:                                               ; preds = %74
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = call ptr @Transpose_Matrix(ptr noundef %78)
  br label %80

80:                                               ; preds = %77, %74
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret ptr %81
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { noreturn nounwind "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 #3 = { 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 = { nounwind }
attributes #5 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.Double_Matrix = type { i32, ptr }

@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1

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

declare ptr @Malloc(i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @LU_Solve(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @Transpose_Matrix(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @LU_Invert(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.Double_Matrix, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = tail call ptr @Malloc(i64 noundef 16, ptr noundef nonnull @.str.5) #5
  %7 = sext i32 %5 to i64
  %8 = shl nsw i64 %7, 3
  %9 = mul i64 %8, %7
  %10 = tail call ptr @Malloc(i64 noundef %9, ptr noundef nonnull @.str.5) #5
  %11 = icmp eq ptr %6, null
  %12 = icmp eq ptr %10, null
  %or.cond = select i1 %11, i1 true, i1 %12
  br i1 %or.cond, label %13, label %14

13:                                               ; preds = %2
  tail call void @exit(i32 noundef 1) #6
  unreachable

14:                                               ; preds = %2
  store i32 %5, ptr %6, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %10, ptr %15, align 8, !tbaa !13
  store i32 %5, ptr %3, align 8, !tbaa !11
  %16 = icmp sgt i32 %5, 0
  br i1 %16, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %14
  %17 = getelementptr inbounds i8, ptr %3, i64 8
  %18 = zext nneg i32 %5 to i64
  %19 = shl nuw nsw i64 %18, 3
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us, %.lr.ph37
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.us ], [ 0, %.lr.ph37 ]
  %.035.us = phi ptr [ %22, %.lr.ph.us ], [ %10, %.lr.ph37 ]
  store ptr %.035.us, ptr %17, align 8, !tbaa !13
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %.035.us, i8 0, i64 %19, i1 false), !tbaa !14
  %20 = getelementptr inbounds double, ptr %.035.us, i64 %indvars.iv
  store double 1.000000e+00, ptr %20, align 8, !tbaa !14
  %21 = call ptr @LU_Solve(ptr noundef nonnull %3, ptr noundef nonnull %0)
  %22 = getelementptr inbounds double, ptr %.035.us, i64 %7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %18
  br i1 %exitcond.not, label %._crit_edge38, label %.lr.ph.us, !llvm.loop !16

._crit_edge38:                                    ; preds = %.lr.ph.us, %14
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %23, label %25

23:                                               ; preds = %._crit_edge38
  %24 = call ptr @Transpose_Matrix(ptr noundef nonnull %6)
  br label %25

25:                                               ; preds = %23, %._crit_edge38
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  ret ptr %6
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { noreturn nounwind "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 #3 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !7, i64 8}
!13 = !{!12, !7, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass