; LLVM IR from marcobambini/gravity :: src/shared (gravity_hash)

; 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.gravity_hash_t = type { i32, i32, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct.hash_node_s = type { i32, %struct.gravity_value_t, %struct.gravity_value_t, ptr }
%struct.gravity_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }

; 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 @gravity_hash_free(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  br label %74

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gravity_hash_t, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %14

14:                                               ; preds = %66, %10
  %15 = load i32, ptr %4, align 4, !tbaa !12
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.gravity_hash_t, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ult i32 %15, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %69

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gravity_hash_t, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gravity_hash_t, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr %4, align 4, !tbaa !12
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  store ptr null, ptr %34, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %59, %21
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %65

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %59

41:                                               ; preds = %38
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.hash_node_s, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hash_node_s, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gravity_hash_t, ptr %48, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds { ptr, i64 }, ptr %45, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8
  %53 = getelementptr inbounds { ptr, i64 }, ptr %45, i32 0, i32 1
  %54 = load i64, ptr %53, align 8
  %55 = getelementptr inbounds { ptr, i64 }, ptr %47, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8
  %57 = getelementptr inbounds { ptr, i64 }, ptr %47, i32 0, i32 1
  %58 = load i64, ptr %57, align 8
  call void %42(ptr noundef %43, ptr %52, i64 %54, ptr %56, i64 %58, ptr noundef %50)
  br label %59

59:                                               ; preds = %41, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %60, ptr %6, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.hash_node_s, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  store ptr %63, ptr %5, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %64) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %35, !llvm.loop !19

65:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %4, align 4, !tbaa !12
  %68 = add i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !12
  br label %14, !llvm.loop !21

69:                                               ; preds = %20
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gravity_hash_t, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  call void @free(ptr noundef %72) #3
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %73) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %74

74:                                               ; preds = %69, %9
  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, !6, i64 32}
!10 = !{!"gravity_hash_t", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 40}
!16 = !{!17, !6, i64 40}
!17 = !{!"hash_node_s", !11, i64 0, !18, i64 8, !18, i64 24, !6, i64 40}
!18 = !{!"", !6, i64 0, !7, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 @gravity_hash_free(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %37, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.fr = freeze ptr %4
  %5 = load i32, ptr %0, align 8, !tbaa !11
  %.not31 = icmp eq i32 %5, 0
  br i1 %.not31, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %.not24 = icmp eq ptr %.fr, null
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  br i1 %.not24, label %.lr.ph29.split.us, label %.lr.ph29.split

.lr.ph29.split.us:                                ; preds = %.lr.ph29, %._crit_edge.split.us.us
  %8 = phi i32 [ %12, %._crit_edge.split.us.us ], [ %5, %.lr.ph29 ]
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %._crit_edge.split.us.us ], [ 0, %.lr.ph29 ]
  %9 = load ptr, ptr %6, align 8, !tbaa !12
  %10 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv34
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  store ptr null, ptr %10, align 8, !tbaa !13
  %.not2325.us = icmp eq ptr %11, null
  br i1 %.not2325.us, label %._crit_edge.split.us.us, label %.lr.ph.us

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

._crit_edge.split.us.us:                          ; preds = %._crit_edge.split.us.us.loopexit, %.lr.ph29.split.us
  %12 = phi i32 [ %.pre37, %._crit_edge.split.us.us.loopexit ], [ %8, %.lr.ph29.split.us ]
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %13 = zext i32 %12 to i64
  %14 = icmp ult i64 %indvars.iv.next35, %13
  br i1 %14, label %.lr.ph29.split.us, label %._crit_edge30, !llvm.loop !14

.lr.ph.us:                                        ; preds = %.lr.ph29.split.us, %.lr.ph.us
  %.026.us.us = phi ptr [ %16, %.lr.ph.us ], [ %11, %.lr.ph29.split.us ]
  %15 = getelementptr inbounds i8, ptr %.026.us.us, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  tail call void @free(ptr noundef nonnull %.026.us.us) #2
  %.not23.us.us = icmp eq ptr %16, null
  br i1 %.not23.us.us, label %._crit_edge.split.us.us.loopexit, label %.lr.ph.us, !llvm.loop !19

._crit_edge30:                                    ; preds = %._crit_edge.split, %._crit_edge.split.us.us, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  tail call void @free(ptr noundef %18) #2
  tail call void @free(ptr noundef nonnull %0) #2
  br label %37

.lr.ph29.split:                                   ; preds = %.lr.ph29, %._crit_edge.split
  %19 = phi i32 [ %34, %._crit_edge.split ], [ %5, %.lr.ph29 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge.split ], [ 0, %.lr.ph29 ]
  %20 = load ptr, ptr %6, align 8, !tbaa !12
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  store ptr null, ptr %21, align 8, !tbaa !13
  %.not2325 = icmp eq ptr %22, null
  br i1 %.not2325, label %._crit_edge.split, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph29.split, %.lr.ph
  %.026 = phi ptr [ %33, %.lr.ph ], [ %22, %.lr.ph29.split ]
  %23 = getelementptr inbounds i8, ptr %.026, i64 8
  %24 = getelementptr inbounds i8, ptr %.026, i64 24
  %25 = load ptr, ptr %7, align 8, !tbaa !20
  %26 = load ptr, ptr %23, align 8
  %27 = getelementptr inbounds i8, ptr %.026, i64 16
  %28 = load i64, ptr %27, align 8
  %29 = load ptr, ptr %24, align 8
  %30 = getelementptr inbounds i8, ptr %.026, i64 32
  %31 = load i64, ptr %30, align 8
  tail call void %.fr(ptr noundef nonnull %0, ptr %26, i64 %28, ptr %29, i64 %31, ptr noundef %25) #2
  %32 = getelementptr inbounds i8, ptr %.026, i64 40
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  tail call void @free(ptr noundef nonnull %.026) #2
  %.not23 = icmp eq ptr %33, null
  br i1 %.not23, label %._crit_edge.split.loopexit, label %.lr.ph, !llvm.loop !19

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

._crit_edge.split:                                ; preds = %._crit_edge.split.loopexit, %.lr.ph29.split
  %34 = phi i32 [ %.pre, %._crit_edge.split.loopexit ], [ %19, %.lr.ph29.split ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %indvars.iv.next, %35
  br i1 %36, label %.lr.ph29.split, label %._crit_edge30, !llvm.loop !14

37:                                               ; preds = %1, %._crit_edge30
  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 32}
!6 = !{!"gravity_hash_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52}
!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 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 40}
!17 = !{!"hash_node_s", !7, i64 0, !18, i64 8, !18, i64 24, !10, i64 40}
!18 = !{!"", !10, i64 0, !8, i64 8}
!19 = distinct !{!19, !15}
!20 = !{!6, !10, i64 40}


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