; LLVM IR from davidar/c-hashtable :: hashtable (hashtable_destroy)

; 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.hashtable = type { i32, ptr, i32, i32, i32, ptr, ptr }
%struct.entry = type { ptr, ptr, i32, ptr }

; 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 @hashtable_destroy(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  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
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.hashtable, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %47

14:                                               ; preds = %2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %43, %14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp ult i32 %16, %19
  br i1 %20, label %21, label %46

21:                                               ; preds = %15
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %30, %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp ne ptr null, %28
  br i1 %29, label %30, label %42

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.entry, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.entry, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  call void @free(ptr noundef %37) #3
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.entry, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  call void @free(ptr noundef %40) #3
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %41) #3
  br label %27, !llvm.loop !18

42:                                               ; preds = %27
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = add i32 %44, 1
  store i32 %45, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !20

46:                                               ; preds = %15
  br label %77

47:                                               ; preds = %2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %73, %47
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hashtable, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !13
  %53 = icmp ult i32 %49, %52
  br i1 %53, label %54, label %76

54:                                               ; preds = %48
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %55, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  store ptr %59, ptr %6, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %63, %54
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp ne ptr null, %61
  br i1 %62, label %63, label %72

63:                                               ; preds = %60
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.entry, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  store ptr %67, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.entry, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !16
  call void @free(ptr noundef %70) #3
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %71) #3
  br label %60, !llvm.loop !21

72:                                               ; preds = %60
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = add i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !9
  br label %48, !llvm.loop !22

76:                                               ; preds = %48
  br label %77

77:                                               ; preds = %76, %46
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.hashtable, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  call void @free(ptr noundef %80) #3
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %81) #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
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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 = { 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, !6, i64 8}
!12 = !{!"hashtable", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !6, i64 24}
!15 = !{!"entry", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24}
!16 = !{!15, !6, i64 0}
!17 = !{!15, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}
!22 = distinct !{!22, !19}


; 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: 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 @hashtable_destroy(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %1, 0
  %5 = load i32, ptr %0, align 8, !tbaa !11
  %.not42 = icmp eq i32 %5, 0
  br i1 %.not, label %.preheader, label %.preheader28

.preheader28:                                     ; preds = %2
  br i1 %.not42, label %.loopexit, label %.lr.ph33

.preheader:                                       ; preds = %2
  br i1 %.not42, label %.loopexit, label %.lr.ph40

.lr.ph33:                                         ; preds = %.preheader28, %._crit_edge
  %6 = phi i32 [ %14, %._crit_edge ], [ %5, %.preheader28 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %.preheader28 ]
  %7 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not2730 = icmp eq ptr %8, null
  br i1 %.not2730, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph33, %.lr.ph
  %.02431 = phi ptr [ %10, %.lr.ph ], [ %8, %.lr.ph33 ]
  %9 = getelementptr inbounds i8, ptr %.02431, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = load ptr, ptr %.02431, align 8, !tbaa !15
  tail call void @free(ptr noundef %11) #2
  %12 = getelementptr inbounds i8, ptr %.02431, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  tail call void @free(ptr noundef %13) #2
  tail call void @free(ptr noundef nonnull %.02431) #2
  %.not27 = icmp eq ptr %10, null
  br i1 %.not27, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !17

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %0, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph33
  %14 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %6, %.lr.ph33 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = zext i32 %14 to i64
  %16 = icmp ult i64 %indvars.iv.next, %15
  br i1 %16, label %.lr.ph33, label %.loopexit, !llvm.loop !19

.lr.ph40:                                         ; preds = %.preheader, %._crit_edge38
  %17 = phi i32 [ %23, %._crit_edge38 ], [ %5, %.preheader ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge38 ], [ 0, %.preheader ]
  %18 = getelementptr inbounds ptr, ptr %4, i64 %indvars.iv45
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %.not2634 = icmp eq ptr %19, null
  br i1 %.not2634, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph40, %.lr.ph37
  %.12535 = phi ptr [ %21, %.lr.ph37 ], [ %19, %.lr.ph40 ]
  %20 = getelementptr inbounds i8, ptr %.12535, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %.12535, align 8, !tbaa !15
  tail call void @free(ptr noundef %22) #2
  tail call void @free(ptr noundef nonnull %.12535) #2
  %.not26 = icmp eq ptr %21, null
  br i1 %.not26, label %._crit_edge38.loopexit, label %.lr.ph37, !llvm.loop !20

._crit_edge38.loopexit:                           ; preds = %.lr.ph37
  %.pre48 = load i32, ptr %0, align 8, !tbaa !11
  br label %._crit_edge38

._crit_edge38:                                    ; preds = %._crit_edge38.loopexit, %.lr.ph40
  %23 = phi i32 [ %.pre48, %._crit_edge38.loopexit ], [ %17, %.lr.ph40 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %indvars.iv.next46, %24
  br i1 %25, label %.lr.ph40, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %._crit_edge, %._crit_edge38, %.preheader28, %.preheader
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @free(ptr noundef %26) #2
  tail call void @free(ptr noundef nonnull %0) #2
  ret void
}

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 = { 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, !10, i64 8}
!6 = !{!"hashtable", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, 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 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"entry", !10, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}


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