; LLVM IR from MRPT/mrpt :: libs/math/src/CSparse (cs_cholsol)

; 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.cs_sparse = type { i32, i32, i32, ptr, ptr, ptr, i32 }
%struct.cs_symbolic = type { ptr, ptr, ptr, ptr, ptr, i32, double, double }
%struct.cs_numeric = type { ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @cs_cholsol(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %24

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.cs_sparse, ptr %17, i32 0, i32 6
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21, %16, %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %83

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.cs_sparse, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !13
  store i32 %28, ptr %11, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = call ptr @cs_schol(i32 noundef %29, ptr noundef %30)
  store ptr %31, ptr %9, align 8, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = call ptr @cs_chol(ptr noundef %32, ptr noundef %33)
  store ptr %34, ptr %10, align 8, !tbaa !9
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = call ptr @cs_malloc(i32 noundef %35, i64 noundef 8)
  store ptr %36, ptr %8, align 8, !tbaa !9
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %45

39:                                               ; preds = %25
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = icmp ne ptr %43, null
  br label %45

45:                                               ; preds = %42, %39, %25
  %46 = phi i1 [ false, %39 ], [ false, %25 ], [ %44, %42 ]
  %47 = zext i1 %46 to i32
  store i32 %47, ptr %12, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %75

50:                                               ; preds = %45
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.cs_symbolic, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = call i32 @cs_ipvec(ptr noundef %53, ptr noundef %54, ptr noundef %55, i32 noundef %56)
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.cs_numeric, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = call i32 @cs_lsolve(ptr noundef %60, ptr noundef %61)
  %63 = load ptr, ptr %10, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.cs_numeric, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = call i32 @cs_ltsolve(ptr noundef %65, ptr noundef %66)
  %68 = load ptr, ptr %9, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.cs_symbolic, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = load ptr, ptr %8, align 8, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !9
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = call i32 @cs_pvec(ptr noundef %70, ptr noundef %71, ptr noundef %72, i32 noundef %73)
  br label %75

75:                                               ; preds = %50, %45
  %76 = load ptr, ptr %8, align 8, !tbaa !9
  %77 = call ptr @cs_free(ptr noundef %76)
  %78 = load ptr, ptr %9, align 8, !tbaa !9
  %79 = call ptr @cs_sfree(ptr noundef %78)
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = call ptr @cs_nfree(ptr noundef %80)
  %82 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %82, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %83

83:                                               ; preds = %75, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %84 = load i32, ptr %4, align 4
  ret i32 %84
}

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

declare ptr @cs_schol(i32 noundef, ptr noundef) #2

declare ptr @cs_chol(ptr noundef, ptr noundef) #2

declare ptr @cs_malloc(i32 noundef, i64 noundef) #2

declare i32 @cs_ipvec(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @cs_lsolve(ptr noundef, ptr noundef) #2

declare i32 @cs_ltsolve(ptr noundef, ptr noundef) #2

declare i32 @cs_pvec(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @cs_free(ptr noundef) #2

declare ptr @cs_sfree(ptr noundef) #2

declare ptr @cs_nfree(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"cs_sparse", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !10, i64 0}
!15 = !{!"cs_symbolic", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !16, i64 48, !16, i64 56}
!16 = !{!"double", !7, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"cs_numeric", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}


; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cs_cholsol(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %32, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, -1
  %8 = icmp ne ptr %2, null
  %or.cond = and i1 %8, %7
  br i1 %or.cond, label %9, label %32

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = tail call ptr @cs_schol(i32 noundef %0, ptr noundef nonnull %1) #2
  %13 = tail call ptr @cs_chol(ptr noundef nonnull %1, ptr noundef %12) #2
  %14 = tail call ptr @cs_malloc(i32 noundef %11, i64 noundef 8) #2
  %15 = icmp ne ptr %12, null
  %16 = icmp ne ptr %13, null
  %or.cond3 = select i1 %15, i1 %16, i1 false
  %17 = icmp ne ptr %14, null
  %spec.select = select i1 %or.cond3, i1 %17, i1 false
  %18 = zext i1 %spec.select to i32
  br i1 %spec.select, label %19, label %28

19:                                               ; preds = %9
  %20 = load ptr, ptr %12, align 8, !tbaa !12
  %21 = tail call i32 @cs_ipvec(ptr noundef %20, ptr noundef nonnull %2, ptr noundef nonnull %14, i32 noundef %11) #2
  %22 = load ptr, ptr %13, align 8, !tbaa !15
  %23 = tail call i32 @cs_lsolve(ptr noundef %22, ptr noundef nonnull %14) #2
  %24 = load ptr, ptr %13, align 8, !tbaa !15
  %25 = tail call i32 @cs_ltsolve(ptr noundef %24, ptr noundef nonnull %14) #2
  %26 = load ptr, ptr %12, align 8, !tbaa !12
  %27 = tail call i32 @cs_pvec(ptr noundef %26, ptr noundef nonnull %14, ptr noundef nonnull %2, i32 noundef %11) #2
  br label %28

28:                                               ; preds = %19, %9
  %29 = tail call ptr @cs_free(ptr noundef %14) #2
  %30 = tail call ptr @cs_sfree(ptr noundef %12) #2
  %31 = tail call ptr @cs_nfree(ptr noundef %13) #2
  br label %32

32:                                               ; preds = %3, %4, %28
  %.0 = phi i32 [ %18, %28 ], [ 0, %4 ], [ 0, %3 ]
  ret i32 %.0
}

declare ptr @cs_schol(i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @cs_chol(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @cs_malloc(i32 noundef, i64 noundef) local_unnamed_addr #1

declare i32 @cs_ipvec(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @cs_lsolve(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @cs_ltsolve(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @cs_pvec(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @cs_free(ptr noundef) local_unnamed_addr #1

declare ptr @cs_sfree(ptr noundef) local_unnamed_addr #1

declare ptr @cs_nfree(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 40}
!6 = !{!"cs_sparse", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !10, i64 0}
!13 = !{!"cs_symbolic", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !14, i64 48, !14, i64 56}
!14 = !{!"double", !8, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"cs_numeric", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}


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