; 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_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%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 }

; 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 zeroext i1 @gravity_hash_remove(ptr noundef %0, ptr %1, i64 %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca %struct.gravity_value_t, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  store ptr %1, ptr %13, align 8
  %14 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  store i64 %2, ptr %14, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gravity_hash_t, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8
  %20 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  %21 = load i64, ptr %20, align 8
  %22 = call i32 %17(ptr %19, i64 %21)
  store i32 %22, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %23 = load i32, ptr %7, align 4, !tbaa !12
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gravity_hash_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = urem i32 %23, %26
  store i32 %27, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.gravity_hash_t, ptr %28, i32 0, i32 5
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gravity_hash_t, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i32, ptr %8, align 4, !tbaa !12
  %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 %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %38

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

41:                                               ; preds = %38
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.hash_node_s, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %7, align 4, !tbaa !12
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %108

47:                                               ; preds = %41
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gravity_hash_t, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.hash_node_s, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8
  %55 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  %56 = load i64, ptr %55, align 8
  %57 = getelementptr inbounds { ptr, i64 }, ptr %52, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8
  %59 = getelementptr inbounds { ptr, i64 }, ptr %52, i32 0, i32 1
  %60 = load i64, ptr %59, align 8
  %61 = call zeroext i1 %50(ptr %54, i64 %56, ptr %58, i64 %60)
  br i1 %61, label %62, label %108

62:                                               ; preds = %47
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %83

65:                                               ; preds = %62
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.hash_node_s, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.hash_node_s, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gravity_hash_t, ptr %72, i32 0, i32 6
  %74 = load ptr, ptr %73, align 8, !tbaa !20
  %75 = getelementptr inbounds { ptr, i64 }, ptr %69, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8
  %77 = getelementptr inbounds { ptr, i64 }, ptr %69, i32 0, i32 1
  %78 = load i64, ptr %77, align 8
  %79 = getelementptr inbounds { ptr, i64 }, ptr %71, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8
  %81 = getelementptr inbounds { ptr, i64 }, ptr %71, i32 0, i32 1
  %82 = load i64, ptr %81, align 8
  call void %66(ptr noundef %67, ptr %76, i64 %78, ptr %80, i64 %82, ptr noundef %74)
  br label %83

83:                                               ; preds = %65, %62
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %92

86:                                               ; preds = %83
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.hash_node_s, ptr %87, i32 0, i32 3
  %89 = load ptr, ptr %88, align 8, !tbaa !21
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.hash_node_s, ptr %90, i32 0, i32 3
  store ptr %89, ptr %91, align 8, !tbaa !21
  br label %102

92:                                               ; preds = %83
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.hash_node_s, ptr %93, i32 0, i32 3
  %95 = load ptr, ptr %94, align 8, !tbaa !21
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.gravity_hash_t, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !15
  %99 = load i32, ptr %8, align 4, !tbaa !12
  %100 = zext i32 %99 to i64
  %101 = getelementptr inbounds ptr, ptr %98, i64 %100
  store ptr %95, ptr %101, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %92, %86
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %103) #3
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.gravity_hash_t, ptr %104, i32 0, i32 1
  %106 = load i32, ptr %105, align 4, !tbaa !22
  %107 = add i32 %106, -1
  store i32 %107, ptr %105, align 4, !tbaa !22
  store i1 true, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %114

108:                                              ; preds = %47, %41
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %109, ptr %11, align 8, !tbaa !5
  %110 = load ptr, ptr %10, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.hash_node_s, ptr %110, i32 0, i32 3
  %112 = load ptr, ptr %111, align 8, !tbaa !21
  store ptr %112, ptr %10, align 8, !tbaa !5
  br label %38, !llvm.loop !23

113:                                              ; preds = %38
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %114

114:                                              ; preds = %113, %102
  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 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %115 = load i1, ptr %4, align 1
  ret i1 %115
}

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 16}
!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 32}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !11, i64 0}
!17 = !{!"hash_node_s", !11, i64 0, !18, i64 8, !18, i64 24, !6, i64 40}
!18 = !{!"", !6, i64 0, !7, i64 8}
!19 = !{!10, !6, i64 24}
!20 = !{!10, !6, i64 40}
!21 = !{!17, !6, i64 40}
!22 = !{!10, !11, i64 4}
!23 = distinct !{!23, !24}
!24 = !{!"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: 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 noundef zeroext i1 @gravity_hash_remove(ptr noundef %0, ptr %1, i64 %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 %5(ptr %1, i64 %2) #2
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %8 = urem i32 %6, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = zext i32 %8 to i64
  %14 = getelementptr inbounds ptr, ptr %12, i64 %13
  %.02940 = load ptr, ptr %14, align 8, !tbaa !14
  %.not41.not = icmp eq ptr %.02940, null
  br i1 %.not41.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  br label %16

16:                                               ; preds = %.lr.ph, %50
  %.02943 = phi ptr [ %.02940, %.lr.ph ], [ %.029, %50 ]
  %.042 = phi ptr [ null, %.lr.ph ], [ %.02943, %50 ]
  %17 = load i32, ptr %.02943, align 8, !tbaa !15
  %18 = icmp eq i32 %17, %6
  br i1 %18, label %19, label %50

19:                                               ; preds = %16
  %20 = load ptr, ptr %15, align 8, !tbaa !18
  %21 = getelementptr inbounds i8, ptr %.02943, i64 8
  %22 = load ptr, ptr %21, align 8
  %23 = getelementptr inbounds i8, ptr %.02943, i64 16
  %24 = load i64, ptr %23, align 8
  %25 = tail call zeroext i1 %20(ptr %1, i64 %2, ptr %22, i64 %24) #2
  br i1 %25, label %26, label %50

26:                                               ; preds = %19
  %.not32 = icmp eq ptr %10, null
  br i1 %.not32, label %38, label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds i8, ptr %.02943, i64 16
  %29 = getelementptr inbounds i8, ptr %.02943, i64 8
  %30 = getelementptr inbounds i8, ptr %.02943, i64 24
  %31 = getelementptr inbounds i8, ptr %0, i64 40
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = load ptr, ptr %29, align 8
  %34 = load i64, ptr %28, align 8
  %35 = load ptr, ptr %30, align 8
  %36 = getelementptr inbounds i8, ptr %.02943, i64 32
  %37 = load i64, ptr %36, align 8
  tail call void %10(ptr noundef nonnull %0, ptr %33, i64 %34, ptr %35, i64 %37, ptr noundef %32) #2
  br label %38

38:                                               ; preds = %27, %26
  %.not33 = icmp eq ptr %.042, null
  %39 = getelementptr inbounds i8, ptr %.02943, i64 40
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  br i1 %.not33, label %43, label %41

41:                                               ; preds = %38
  %42 = getelementptr inbounds i8, ptr %.042, i64 40
  br label %46

43:                                               ; preds = %38
  %44 = load ptr, ptr %11, align 8, !tbaa !13
  %45 = getelementptr inbounds ptr, ptr %44, i64 %13
  br label %46

46:                                               ; preds = %43, %41
  %.sink = phi ptr [ %45, %43 ], [ %42, %41 ]
  store ptr %40, ptr %.sink, align 8, !tbaa !14
  tail call void @free(ptr noundef nonnull %.02943) #2
  %47 = getelementptr inbounds i8, ptr %0, i64 4
  %48 = load i32, ptr %47, align 4, !tbaa !21
  %49 = add i32 %48, -1
  store i32 %49, ptr %47, align 4, !tbaa !21
  br label %.loopexit

50:                                               ; preds = %19, %16
  %51 = getelementptr inbounds i8, ptr %.02943, i64 40
  %.029 = load ptr, ptr %51, align 8, !tbaa !14
  %.not.not = icmp eq ptr %.029, null
  br i1 %.not.not, label %.loopexit, label %16, !llvm.loop !22

.loopexit:                                        ; preds = %50, %3, %46
  %.not35 = phi i1 [ true, %46 ], [ false, %3 ], [ false, %50 ]
  ret i1 %.not35
}

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


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