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

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

declare i32 @cs_sprealloc(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @cs_entry_no_extend(ptr noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store double %3, ptr %9, align 8, !tbaa !11
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.cs_sparse, ptr %10, i32 0, i32 6
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.cs_sparse, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = icmp sge i32 %12, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.cs_sparse, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = mul nsw i32 2, %21
  %23 = call i32 @cs_sprealloc(ptr noundef %18, i32 noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %17
  store i32 0, ptr %5, align 4
  br label %61

26:                                               ; preds = %17, %4
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.cs_sparse, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %41

31:                                               ; preds = %26
  %32 = load double, ptr %9, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.cs_sparse, ptr %33, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cs_sparse, ptr %36, i32 0, i32 6
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %35, i64 %39
  store double %32, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %31, %26
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.cs_sparse, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.cs_sparse, ptr %46, i32 0, i32 6
  %48 = load i32, ptr %47, align 8, !tbaa !13
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %45, i64 %49
  store i32 %42, ptr %50, align 4, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.cs_sparse, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.cs_sparse, ptr %55, i32 0, i32 6
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %56, align 8, !tbaa !13
  %59 = sext i32 %57 to i64
  %60 = getelementptr inbounds i32, ptr %54, i64 %59
  store i32 %51, ptr %60, align 4, !tbaa !9
  store i32 1, ptr %5, align 4
  br label %61

61:                                               ; preds = %41, %25
  %62 = load i32, ptr %5, align 4
  ret i32 %62
}

attributes #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 = { 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" }

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


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

declare i32 @cs_sprealloc(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @cs_entry_no_extend(ptr noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %.not = icmp slt i32 %6, %7
  br i1 %.not, label %11, label %8

8:                                                ; preds = %4
  %9 = shl nsw i32 %7, 1
  %10 = tail call i32 @cs_sprealloc(ptr noundef nonnull %0, i32 noundef %9) #2
  %.not16 = icmp eq i32 %10, 0
  br i1 %.not16, label %25, label %._crit_edge

._crit_edge:                                      ; preds = %8
  %.pre.pre = load i32, ptr %5, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %4
  %.pre = phi i32 [ %.pre.pre, %._crit_edge ], [ %6, %4 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %.not17 = icmp eq ptr %13, null
  %.pre20 = sext i32 %.pre to i64
  br i1 %.not17, label %._crit_edge19, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds double, ptr %13, i64 %.pre20
  store double %3, ptr %15, align 8, !tbaa !13
  br label %._crit_edge19

._crit_edge19:                                    ; preds = %11, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds i32, ptr %17, i64 %.pre20
  store i32 %1, ptr %18, align 4, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load i32, ptr %5, align 8, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 8, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds i32, ptr %20, i64 %23
  store i32 %2, ptr %24, align 4, !tbaa !16
  br label %25

25:                                               ; preds = %8, %._crit_edge19
  %.0 = phi i32 [ 1, %._crit_edge19 ], [ 0, %8 ]
  ret i32 %.0
}

attributes #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 = { 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 #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 0}
!12 = !{!6, !10, i64 32}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = !{!6, !10, i64 24}
!16 = !{!7, !7, i64 0}
!17 = !{!6, !10, i64 16}


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