; LLVM IR from clibs/clib :: src/common (clib-package)

; 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.kh_ptr_t = type { i32, i32, i32, i32, ptr, ptr, ptr }

@clib_package_curl_share = external dso_local global ptr, align 8
@visited_packages = external hidden global ptr, align 8

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @clib_package_cleanup() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %5 = icmp ne ptr null, %4
  br i1 %5, label %6, label %52

6:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %47, %6
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.kh_ptr_t, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %50

14:                                               ; preds = %7
  %15 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.kh_ptr_t, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = lshr i32 %18, 4
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %17, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = and i32 %23, 15
  %25 = shl i32 %24, 1
  %26 = lshr i32 %22, %25
  %27 = and i32 %26, 3
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %14
  br label %47

30:                                               ; preds = %14
  %31 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.kh_ptr_t, ptr %31, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %1, align 8, !tbaa !5
  %38 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.kh_ptr_t, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  store ptr %44, ptr %2, align 8, !tbaa !5
  %45 = load ptr, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %45) #5
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %30, %29
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !16

50:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  %51 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  call void @kh_destroy_ptr(ptr noundef %51)
  store ptr null, ptr @visited_packages, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %50, %0
  %53 = load ptr, ptr @clib_package_curl_share, align 8, !tbaa !5
  %54 = call i32 @curl_share_cleanup(ptr noundef %53)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @kh_destroy_ptr(ptr noundef) #3

declare i32 @curl_share_cleanup(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #3 = { inlinehint 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 #4 = { "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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@clib_package_curl_share = external dso_local local_unnamed_addr global ptr, align 8
@visited_packages = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @clib_package_cleanup() local_unnamed_addr #1 {
  %1 = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %25, label %.preheader

.preheader:                                       ; preds = %0
  %2 = load i32, ptr %1, align 8, !tbaa !9
  %.not9 = icmp eq i32 %2, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %20, %.preheader
  %.lcssa = phi ptr [ %1, %.preheader ], [ %22, %20 ]
  tail call void @kh_destroy_ptr(ptr noundef nonnull %.lcssa)
  store ptr null, ptr @visited_packages, align 8, !tbaa !5
  br label %25

.lr.ph:                                           ; preds = %.preheader, %20
  %3 = phi i32 [ %21, %20 ], [ %2, %.preheader ]
  %4 = phi ptr [ %22, %20 ], [ %1, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %20 ], [ 0, %.preheader ]
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = trunc nuw i64 %indvars.iv to i32
  %8 = lshr i64 %indvars.iv, 4
  %9 = getelementptr inbounds i32, ptr %6, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %11 = shl i32 %7, 1
  %12 = and i32 %11, 30
  %13 = shl nuw i32 3, %12
  %14 = and i32 %10, %13
  %.not7 = icmp eq i32 %14, 0
  br i1 %.not7, label %15, label %20

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %4, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  tail call void @free(ptr noundef %19) #4
  %.pre = load ptr, ptr @visited_packages, align 8, !tbaa !5
  %.pre12 = load i32, ptr %.pre, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %.lr.ph, %15
  %21 = phi i32 [ %3, %.lr.ph ], [ %.pre12, %15 ]
  %22 = phi ptr [ %4, %.lr.ph ], [ %.pre, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = zext i32 %21 to i64
  %24 = icmp ult i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !15

25:                                               ; preds = %._crit_edge, %0
  %26 = load ptr, ptr @clib_package_curl_share, align 8, !tbaa !5
  %27 = tail call i32 @curl_share_cleanup(ptr noundef %26) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @kh_destroy_ptr(ptr noundef) local_unnamed_addr #2

declare i32 @curl_share_cleanup(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { inlinehint 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 #3 = { "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 #4 = { 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass