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

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

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

17:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %90

18:                                               ; preds = %5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = load ptr, ptr %12, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.cs_sparse, ptr %20, i32 0, i32 1
  store i32 %19, ptr %21, align 4, !tbaa !11
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.cs_sparse, ptr %23, i32 0, i32 2
  store i32 %22, ptr %24, align 8, !tbaa !13
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %27, label %29

27:                                               ; preds = %18
  %28 = load i32, ptr %9, align 4, !tbaa !5
  br label %30

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29, %27
  %31 = phi i32 [ %28, %27 ], [ 1, %29 ]
  store i32 %31, ptr %9, align 4, !tbaa !5
  %32 = load ptr, ptr %12, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.cs_sparse, ptr %32, i32 0, i32 0
  store i32 %31, ptr %33, align 8, !tbaa !14
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  %36 = zext i1 %35 to i64
  %37 = select i1 %35, i32 0, i32 -1
  %38 = load ptr, ptr %12, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.cs_sparse, ptr %38, i32 0, i32 6
  store i32 %37, ptr %39, align 8, !tbaa !15
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %30
  %43 = load i32, ptr %9, align 4, !tbaa !5
  br label %47

44:                                               ; preds = %30
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  br label %47

47:                                               ; preds = %44, %42
  %48 = phi i32 [ %43, %42 ], [ %46, %44 ]
  %49 = call ptr @cs_malloc(i32 noundef %48, i64 noundef 4)
  %50 = load ptr, ptr %12, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.cs_sparse, ptr %50, i32 0, i32 3
  store ptr %49, ptr %51, align 8, !tbaa !16
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = call ptr @cs_malloc(i32 noundef %52, i64 noundef 4)
  %54 = load ptr, ptr %12, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.cs_sparse, ptr %54, i32 0, i32 4
  store ptr %53, ptr %55, align 8, !tbaa !17
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %47
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = call ptr @cs_malloc(i32 noundef %59, i64 noundef 8)
  br label %62

61:                                               ; preds = %47
  br label %62

62:                                               ; preds = %61, %58
  %63 = phi ptr [ %60, %58 ], [ null, %61 ]
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.cs_sparse, ptr %64, i32 0, i32 5
  store ptr %63, ptr %65, align 8, !tbaa !18
  %66 = load ptr, ptr %12, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.cs_sparse, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %83

70:                                               ; preds = %62
  %71 = load ptr, ptr %12, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.cs_sparse, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %83

75:                                               ; preds = %70
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %86

78:                                               ; preds = %75
  %79 = load ptr, ptr %12, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.cs_sparse, ptr %79, i32 0, i32 5
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = icmp ne ptr %81, null
  br i1 %82, label %86, label %83

83:                                               ; preds = %78, %70, %62
  %84 = load ptr, ptr %12, align 8, !tbaa !9
  %85 = call ptr @cs_spfree(ptr noundef %84)
  br label %88

86:                                               ; preds = %78, %75
  %87 = load ptr, ptr %12, align 8, !tbaa !9
  br label %88

88:                                               ; preds = %86, %83
  %89 = phi ptr [ %85, %83 ], [ %87, %86 ]
  store ptr %89, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %90

90:                                               ; preds = %88, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %91 = load ptr, ptr %6, align 8
  ret ptr %91
}

; 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_malloc(i32 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @cs_spfree(ptr noundef) #0

; 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 4}
!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 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 40}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 24}
!18 = !{!12, !10, i64 32}


; 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_spalloc(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call ptr @cs_calloc(i32 noundef 1, i64 noundef 48) #3
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %29, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %1, ptr %9, align 8, !tbaa !11
  %10 = tail call i32 @llvm.smax.i32(i32 %2, i32 1)
  store i32 %10, ptr %6, align 8, !tbaa !12
  %.not26 = icmp eq i32 %4, 0
  %11 = sext i1 %.not26 to i32
  %12 = getelementptr inbounds i8, ptr %6, i64 40
  store i32 %11, ptr %12, align 8, !tbaa !13
  %13 = add nsw i32 %1, 1
  %14 = select i1 %.not26, i32 %13, i32 %10
  %15 = tail call ptr @cs_malloc(i32 noundef %14, i64 noundef 4) #3
  %16 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %15, ptr %16, align 8, !tbaa !14
  %17 = tail call ptr @cs_malloc(i32 noundef %10, i64 noundef 4) #3
  %18 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %17, ptr %18, align 8, !tbaa !15
  %.not27 = icmp ne i32 %3, 0
  br i1 %.not27, label %19, label %21

19:                                               ; preds = %7
  %20 = tail call ptr @cs_malloc(i32 noundef %10, i64 noundef 8) #3
  br label %21

21:                                               ; preds = %7, %19
  %22 = phi ptr [ %20, %19 ], [ null, %7 ]
  %23 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr %22, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %16, align 8, !tbaa !14
  %.not28 = icmp eq ptr %24, null
  br i1 %.not28, label %27, label %25

25:                                               ; preds = %21
  %26 = load ptr, ptr %18, align 8, !tbaa !15
  %.not29 = icmp eq ptr %26, null
  %.not30 = icmp eq ptr %22, null
  %or.cond = select i1 %.not27, i1 %.not30, i1 false
  %or.cond31 = select i1 %.not29, i1 true, i1 %or.cond
  br i1 %or.cond31, label %27, label %29

27:                                               ; preds = %25, %21
  %28 = tail call ptr @cs_spfree(ptr noundef nonnull %6)
  br label %29

29:                                               ; preds = %25, %27, %5
  %.0 = phi ptr [ null, %5 ], [ %28, %27 ], [ %6, %25 ]
  ret ptr %.0
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @cs_spfree(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 4}
!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 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 40}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !10, i64 32}


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