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

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

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

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

20:                                               ; preds = %15, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %103

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.cs_sparse, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !13
  store i32 %24, ptr %6, align 4, !tbaa !5
  %25 = call ptr @cs_calloc(i32 noundef 1, i64 noundef 64)
  store ptr %25, ptr %11, align 8, !tbaa !9
  %26 = load ptr, ptr %11, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %103

29:                                               ; preds = %21
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = call ptr @cs_amd(i32 noundef %30, ptr noundef %31)
  store ptr %32, ptr %9, align 8, !tbaa !9
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = call ptr @cs_pinv(ptr noundef %33, i32 noundef %34)
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.cs_symbolic, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !14
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = call ptr @cs_free(ptr noundef %38)
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %50

42:                                               ; preds = %29
  %43 = load ptr, ptr %11, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.cs_symbolic, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = icmp ne ptr %45, null
  br i1 %46, label %50, label %47

47:                                               ; preds = %42
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = call ptr @cs_sfree(ptr noundef %48)
  store ptr %49, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %103

50:                                               ; preds = %42, %29
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = load ptr, ptr %11, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.cs_symbolic, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = call ptr @cs_symperm(ptr noundef %51, ptr noundef %54, i32 noundef 0)
  store ptr %55, ptr %10, align 8, !tbaa !9
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = call ptr @cs_etree(ptr noundef %56, i32 noundef 0)
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.cs_symbolic, ptr %58, i32 0, i32 2
  store ptr %57, ptr %59, align 8, !tbaa !17
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.cs_symbolic, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = call ptr @cs_post(ptr noundef %62, i32 noundef %63)
  store ptr %64, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.cs_symbolic, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = call ptr @cs_counts(ptr noundef %65, ptr noundef %68, ptr noundef %69, i32 noundef 0)
  store ptr %70, ptr %7, align 8, !tbaa !9
  %71 = load ptr, ptr %8, align 8, !tbaa !9
  %72 = call ptr @cs_free(ptr noundef %71)
  %73 = load ptr, ptr %10, align 8, !tbaa !9
  %74 = call ptr @cs_spfree(ptr noundef %73)
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = call ptr @cs_malloc(i32 noundef %76, i64 noundef 4)
  %78 = load ptr, ptr %11, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.cs_symbolic, ptr %78, i32 0, i32 3
  store ptr %77, ptr %79, align 8, !tbaa !18
  %80 = load ptr, ptr %11, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.cs_symbolic, ptr %80, i32 0, i32 3
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = call double @cs_cumsum(ptr noundef %82, ptr noundef %83, i32 noundef %84)
  %86 = load ptr, ptr %11, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.cs_symbolic, ptr %86, i32 0, i32 6
  store double %85, ptr %87, align 8, !tbaa !19
  %88 = load ptr, ptr %11, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.cs_symbolic, ptr %88, i32 0, i32 7
  store double %85, ptr %89, align 8, !tbaa !20
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  %91 = call ptr @cs_free(ptr noundef %90)
  %92 = load ptr, ptr %11, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.cs_symbolic, ptr %92, i32 0, i32 6
  %94 = load double, ptr %93, align 8, !tbaa !19
  %95 = fcmp oge double %94, 0.000000e+00
  br i1 %95, label %96, label %98

96:                                               ; preds = %50
  %97 = load ptr, ptr %11, align 8, !tbaa !9
  br label %101

98:                                               ; preds = %50
  %99 = load ptr, ptr %11, align 8, !tbaa !9
  %100 = call ptr @cs_sfree(ptr noundef %99)
  br label %101

101:                                              ; preds = %98, %96
  %102 = phi ptr [ %97, %96 ], [ %100, %98 ]
  store ptr %102, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %103

103:                                              ; preds = %101, %47, %28, %20
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %104 = load ptr, ptr %3, align 8
  ret ptr %104
}

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

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

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

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

declare ptr @cs_free(ptr noundef) #2

declare ptr @cs_sfree(ptr noundef) #2

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

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

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

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

declare ptr @cs_spfree(ptr noundef) #2

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

declare double @cs_cumsum(ptr noundef, ptr noundef, i32 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 = !{!15, !10, i64 16}
!18 = !{!15, !10, i64 24}
!19 = !{!15, !16, i64 48}
!20 = !{!15, !16, 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 ptr @cs_schol(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %34, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 40
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %7, label %34

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = tail call ptr @cs_calloc(i32 noundef 1, i64 noundef 64) #2
  %.not37 = icmp eq ptr %10, null
  br i1 %.not37, label %34, label %11

11:                                               ; preds = %7
  %12 = tail call ptr @cs_amd(i32 noundef %0, ptr noundef nonnull %1) #2
  %13 = tail call ptr @cs_pinv(ptr noundef %12, i32 noundef %9) #2
  store ptr %13, ptr %10, align 8, !tbaa !12
  %14 = tail call ptr @cs_free(ptr noundef %12) #2
  %.not38 = icmp ne i32 %0, 0
  %.pre = load ptr, ptr %10, align 8, !tbaa !12
  %.not39 = icmp eq ptr %.pre, null
  %or.cond = select i1 %.not38, i1 %.not39, i1 false
  br i1 %or.cond, label %.sink.split, label %15

15:                                               ; preds = %11
  %16 = tail call ptr @cs_symperm(ptr noundef nonnull %1, ptr noundef %.pre, i32 noundef 0) #2
  %17 = tail call ptr @cs_etree(ptr noundef %16, i32 noundef 0) #2
  %18 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %17, ptr %18, align 8, !tbaa !15
  %19 = tail call ptr @cs_post(ptr noundef %17, i32 noundef %9) #2
  %20 = load ptr, ptr %18, align 8, !tbaa !15
  %21 = tail call ptr @cs_counts(ptr noundef %16, ptr noundef %20, ptr noundef %19, i32 noundef 0) #2
  %22 = tail call ptr @cs_free(ptr noundef %19) #2
  %23 = tail call ptr @cs_spfree(ptr noundef %16) #2
  %24 = add nsw i32 %9, 1
  %25 = tail call ptr @cs_malloc(i32 noundef %24, i64 noundef 4) #2
  %26 = getelementptr inbounds i8, ptr %10, i64 24
  store ptr %25, ptr %26, align 8, !tbaa !16
  %27 = tail call double @cs_cumsum(ptr noundef %25, ptr noundef %21, i32 noundef %9) #2
  %28 = getelementptr inbounds i8, ptr %10, i64 48
  store double %27, ptr %28, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %10, i64 56
  store double %27, ptr %29, align 8, !tbaa !18
  %30 = tail call ptr @cs_free(ptr noundef %21) #2
  %31 = load double, ptr %28, align 8, !tbaa !17
  %32 = fcmp ult double %31, 0.000000e+00
  br i1 %32, label %.sink.split, label %34

.sink.split:                                      ; preds = %15, %11
  %33 = tail call ptr @cs_sfree(ptr noundef nonnull %10) #2
  br label %34

34:                                               ; preds = %.sink.split, %15, %7, %2, %3
  %.0 = phi ptr [ null, %3 ], [ null, %2 ], [ null, %7 ], [ %10, %15 ], [ %33, %.sink.split ]
  ret ptr %.0
}

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

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

declare ptr @cs_pinv(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_symperm(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

declare ptr @cs_spfree(ptr noundef) local_unnamed_addr #1

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

declare double @cs_cumsum(ptr noundef, ptr noundef, i32 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 = !{!13, !10, i64 16}
!16 = !{!13, !10, i64 24}
!17 = !{!13, !14, i64 48}
!18 = !{!13, !14, i64 56}


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