; LLVM IR from YuchenHHH/Sparse-linear-systems :: Source (cs_find)

; 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_find(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, 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
  store i64 0, ptr %8, align 8, !tbaa !9
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cs_sparse, ptr %22, i32 0, i32 6
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = icmp eq i64 %24, -1
  br i1 %25, label %27, label %26

26:                                               ; preds = %21, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %18, align 4
  br label %118

27:                                               ; preds = %21
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cs_sparse, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !13
  store i64 %30, ptr %6, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cs_sparse, ptr %31, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !14
  store i64 %33, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cs_sparse, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  store ptr %36, ptr %11, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.cs_sparse, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  store ptr %39, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.cs_sparse, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  store ptr %42, ptr %15, align 8, !tbaa !5
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  %48 = zext i1 %47 to i32
  %49 = sext i32 %48 to i64
  %50 = call ptr @cs_spalloc(i64 noundef %43, i64 noundef %44, i64 noundef %45, i64 noundef %49, i64 noundef 1)
  store ptr %50, ptr %17, align 8, !tbaa !5
  %51 = load i64, ptr %7, align 8, !tbaa !9
  %52 = call ptr @cs_calloc(i64 noundef %51, i64 noundef 8)
  store ptr %52, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %17, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %27
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %62, label %58

58:                                               ; preds = %55, %27
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = call ptr @cs_done(ptr noundef %59, ptr noundef %60, ptr noundef null, i64 noundef 0)
  store ptr %61, ptr %3, align 8
  store i32 1, ptr %18, align 4
  br label %118

62:                                               ; preds = %55
  %63 = load ptr, ptr %17, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.cs_sparse, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  store ptr %65, ptr %13, align 8, !tbaa !5
  %66 = load ptr, ptr %17, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.cs_sparse, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  store ptr %68, ptr %14, align 8, !tbaa !5
  %69 = load ptr, ptr %17, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.cs_sparse, ptr %69, i32 0, i32 5
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  store ptr %71, ptr %16, align 8, !tbaa !5
  %72 = load i64, ptr %5, align 8, !tbaa !9
  %73 = load ptr, ptr %17, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cs_sparse, ptr %73, i32 0, i32 6
  store i64 %72, ptr %74, align 8, !tbaa !11
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %111, %62
  %76 = load i64, ptr %9, align 8, !tbaa !9
  %77 = load i64, ptr %5, align 8, !tbaa !9
  %78 = icmp slt i64 %76, %77
  br i1 %78, label %79, label %114

79:                                               ; preds = %75
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load i64, ptr %9, align 8, !tbaa !9
  %82 = getelementptr inbounds i64, ptr %80, i64 %81
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = load i64, ptr %9, align 8, !tbaa !9
  %86 = getelementptr inbounds i64, ptr %84, i64 %85
  store i64 %83, ptr %86, align 8, !tbaa !9
  %87 = load ptr, ptr %15, align 8, !tbaa !5
  %88 = load i64, ptr %9, align 8, !tbaa !9
  %89 = getelementptr inbounds double, ptr %87, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !18
  %91 = load ptr, ptr %16, align 8, !tbaa !5
  %92 = load i64, ptr %9, align 8, !tbaa !9
  %93 = getelementptr inbounds double, ptr %91, i64 %92
  store double %90, ptr %93, align 8, !tbaa !18
  %94 = load i64, ptr %9, align 8, !tbaa !9
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = load i64, ptr %8, align 8, !tbaa !9
  %97 = getelementptr inbounds i64, ptr %95, i64 %96
  %98 = load i64, ptr %97, align 8, !tbaa !9
  %99 = icmp sge i64 %94, %98
  br i1 %99, label %100, label %103

100:                                              ; preds = %79
  %101 = load i64, ptr %8, align 8, !tbaa !9
  %102 = add nsw i64 %101, 1
  store i64 %102, ptr %8, align 8, !tbaa !9
  br label %103

103:                                              ; preds = %100, %79
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  %105 = load i64, ptr %8, align 8, !tbaa !9
  %106 = getelementptr inbounds i64, ptr %104, i64 %105
  %107 = load i64, ptr %106, align 8, !tbaa !9
  %108 = load ptr, ptr %14, align 8, !tbaa !5
  %109 = load i64, ptr %9, align 8, !tbaa !9
  %110 = getelementptr inbounds i64, ptr %108, i64 %109
  store i64 %107, ptr %110, align 8, !tbaa !9
  br label %111

111:                                              ; preds = %103
  %112 = load i64, ptr %9, align 8, !tbaa !9
  %113 = add nsw i64 %112, 1
  store i64 %113, ptr %9, align 8, !tbaa !9
  br label %75, !llvm.loop !20

114:                                              ; preds = %75
  %115 = load ptr, ptr %17, align 8, !tbaa !5
  %116 = load ptr, ptr %12, align 8, !tbaa !5
  %117 = call ptr @cs_done(ptr noundef %115, ptr noundef %116, ptr noundef null, i64 noundef 1)
  store ptr %117, ptr %3, align 8
  store i32 1, ptr %18, align 4
  br label %118

118:                                              ; preds = %114, %58, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  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 8, ptr %6) #3
  %119 = load ptr, ptr %3, align 8
  ret ptr %119
}

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

declare ptr @cs_spalloc(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #2

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

declare ptr @cs_done(ptr noundef, ptr noundef, ptr noundef, i64 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"cs_sparse", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !6, i64 40}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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_find(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %49, label %3

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

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = icmp ne ptr %17, null
  %19 = zext i1 %18 to i64
  %20 = tail call ptr @cs_spalloc(i64 noundef %9, i64 noundef %11, i64 noundef %1, i64 noundef %19, i64 noundef 1) #2
  %21 = tail call ptr @cs_calloc(i64 noundef %11, i64 noundef 8) #2
  %22 = icmp ne ptr %20, null
  %23 = icmp ne ptr %21, null
  %or.cond = select i1 %22, i1 %23, i1 false
  br i1 %or.cond, label %26, label %24

24:                                               ; preds = %7
  %25 = tail call ptr @cs_done(ptr noundef nonnull %0, ptr noundef %21, ptr noundef null, i64 noundef 0) #2
  br label %49

26:                                               ; preds = %7
  %27 = getelementptr inbounds i8, ptr %20, i64 32
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %20, i64 24
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %20, i64 40
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %20, i64 48
  store i64 %1, ptr %33, align 8, !tbaa !5
  %34 = icmp sgt i64 %1, 0
  br i1 %34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %26, %.lr.ph
  %.04350 = phi i64 [ %spec.select, %.lr.ph ], [ 0, %26 ]
  %.04449 = phi i64 [ %47, %.lr.ph ], [ 0, %26 ]
  %35 = getelementptr inbounds i64, ptr %13, i64 %.04449
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds i64, ptr %28, i64 %.04449
  store i64 %36, ptr %37, align 8, !tbaa !16
  %38 = getelementptr inbounds double, ptr %17, i64 %.04449
  %39 = load double, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds double, ptr %32, i64 %.04449
  store double %39, ptr %40, align 8, !tbaa !17
  %41 = getelementptr inbounds i64, ptr %15, i64 %.04350
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %.not48 = icmp sge i64 %.04449, %42
  %43 = zext i1 %.not48 to i64
  %spec.select = add nuw nsw i64 %.04350, %43
  %44 = getelementptr inbounds i64, ptr %15, i64 %spec.select
  %45 = load i64, ptr %44, align 8, !tbaa !16
  %46 = getelementptr inbounds i64, ptr %30, i64 %.04449
  store i64 %45, ptr %46, align 8, !tbaa !16
  %47 = add nuw nsw i64 %.04449, 1
  %exitcond.not = icmp eq i64 %47, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %26
  %48 = tail call ptr @cs_done(ptr noundef nonnull %20, ptr noundef nonnull %21, ptr noundef null, i64 noundef 1) #2
  br label %49

49:                                               ; preds = %2, %3, %._crit_edge, %24
  %.0 = phi ptr [ %48, %._crit_edge ], [ %25, %24 ], [ null, %3 ], [ null, %2 ]
  ret ptr %.0
}

declare ptr @cs_spalloc(i64 noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

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

declare ptr @cs_done(ptr noundef, ptr noundef, ptr noundef, i64 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 48}
!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 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !10, i64 40}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass