; LLVM IR from YuchenHHH/Sparse-linear-systems :: Source (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 { i64, i64, i64, ptr, ptr, ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local ptr @cs_spalloc(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = call ptr @cs_calloc(i64 noundef 1, i64 noundef 56)
  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 %91

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

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

29:                                               ; preds = %18
  br label %30

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

43:                                               ; preds = %30
  %44 = load i64, ptr %9, align 8, !tbaa !5
  br label %48

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

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

59:                                               ; preds = %48
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = call ptr @cs_malloc(i64 noundef %60, i64 noundef 8)
  br label %63

62:                                               ; preds = %48
  br label %63

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

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

76:                                               ; preds = %71
  %77 = load i64, ptr %10, align 8, !tbaa !5
  %78 = icmp ne i64 %77, 0
  br i1 %78, label %79, label %87

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

84:                                               ; preds = %79, %71, %63
  %85 = load ptr, ptr %12, align 8, !tbaa !9
  %86 = call ptr @cs_spfree(ptr noundef %85)
  br label %89

87:                                               ; preds = %79, %76
  %88 = load ptr, ptr %12, align 8, !tbaa !9
  br label %89

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

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

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

declare ptr @cs_malloc(i64 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 = !{!"long", !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 8}
!12 = !{!"cs_sparse", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !6, i64 48}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 48}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !10, i64 32}
!18 = !{!12, !10, i64 40}


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

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

19:                                               ; preds = %7
  %20 = tail call ptr @cs_malloc(i64 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 40
  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(i64 noundef, i64 noundef) local_unnamed_addr #1

declare ptr @cs_malloc(i64 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 i64 @llvm.smax.i64(i64, i64) #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 8}
!6 = !{!"cs_sparse", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !10, i64 32}
!16 = !{!6, !10, i64 40}


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