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

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

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

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.cs_sparse, ptr %19, i32 0, i32 6
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23, %18, %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %86

27:                                               ; preds = %23
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.cs_sparse, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !15
  store i32 %30, ptr %13, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = call ptr @cs_sqr(i32 noundef %31, ptr noundef %32, i32 noundef 0)
  store ptr %33, ptr %11, align 8, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %11, align 8, !tbaa !9
  %36 = load double, ptr %9, align 8, !tbaa !11
  %37 = call ptr @cs_lu(ptr noundef %34, ptr noundef %35, double noundef %36)
  store ptr %37, ptr %12, align 8, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !5
  %39 = call ptr @cs_malloc(i32 noundef %38, i64 noundef 8)
  store ptr %39, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %48

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

45:                                               ; preds = %42
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = icmp ne ptr %46, null
  br label %48

48:                                               ; preds = %45, %42, %27
  %49 = phi i1 [ false, %42 ], [ false, %27 ], [ %47, %45 ]
  %50 = zext i1 %49 to i32
  store i32 %50, ptr %14, align 4, !tbaa !5
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %78

53:                                               ; preds = %48
  %54 = load ptr, ptr %12, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.cs_numeric, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = call i32 @cs_ipvec(ptr noundef %56, ptr noundef %57, ptr noundef %58, i32 noundef %59)
  %61 = load ptr, ptr %12, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.cs_numeric, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = call i32 @cs_lsolve(ptr noundef %63, ptr noundef %64)
  %66 = load ptr, ptr %12, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.cs_numeric, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !19
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = call i32 @cs_usolve(ptr noundef %68, ptr noundef %69)
  %71 = load ptr, ptr %11, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.cs_symbolic, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  %74 = load ptr, ptr %10, align 8, !tbaa !9
  %75 = load ptr, ptr %8, align 8, !tbaa !9
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = call i32 @cs_ipvec(ptr noundef %73, ptr noundef %74, ptr noundef %75, i32 noundef %76)
  br label %78

78:                                               ; preds = %53, %48
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = call ptr @cs_free(ptr noundef %79)
  %81 = load ptr, ptr %11, align 8, !tbaa !9
  %82 = call ptr @cs_sfree(ptr noundef %81)
  %83 = load ptr, ptr %12, align 8, !tbaa !9
  %84 = call ptr @cs_nfree(ptr noundef %83)
  %85 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %85, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %86

86:                                               ; preds = %78, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

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

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

declare ptr @cs_lu(ptr noundef, ptr noundef, double 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_usolve(ptr noundef, ptr 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 40}
!14 = !{!"cs_sparse", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !10, i64 16}
!17 = !{!"cs_numeric", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!18 = !{!17, !10, i64 0}
!19 = !{!17, !10, i64 8}
!20 = !{!21, !10, i64 8}
!21 = !{!"cs_symbolic", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !12, i64 48, !12, i64 56}


; 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_lusol(i32 noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %36, label %5

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

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

20:                                               ; preds = %10
  %21 = getelementptr inbounds i8, ptr %14, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = tail call i32 @cs_ipvec(ptr noundef %22, ptr noundef nonnull %2, ptr noundef nonnull %15, i32 noundef %12) #2
  %24 = load ptr, ptr %14, align 8, !tbaa !14
  %25 = tail call i32 @cs_lsolve(ptr noundef %24, ptr noundef nonnull %15) #2
  %26 = getelementptr inbounds i8, ptr %14, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = tail call i32 @cs_usolve(ptr noundef %27, ptr noundef nonnull %15) #2
  %29 = getelementptr inbounds i8, ptr %13, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = tail call i32 @cs_ipvec(ptr noundef %30, ptr noundef nonnull %15, ptr noundef nonnull %2, i32 noundef %12) #2
  br label %32

32:                                               ; preds = %20, %10
  %33 = tail call ptr @cs_free(ptr noundef %15) #2
  %34 = tail call ptr @cs_sfree(ptr noundef %13) #2
  %35 = tail call ptr @cs_nfree(ptr noundef %14) #2
  br label %36

36:                                               ; preds = %4, %5, %32
  %.0 = phi i32 [ %19, %32 ], [ 0, %5 ], [ 0, %4 ]
  ret i32 %.0
}

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

declare ptr @cs_lu(ptr noundef, ptr noundef, double 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_usolve(ptr noundef, ptr 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 16}
!13 = !{!"cs_numeric", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!13, !10, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!17, !10, i64 8}
!17 = !{!"cs_symbolic", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !18, i64 48, !18, i64 56}
!18 = !{!"double", !8, i64 0}


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