; LLVM IR from openxrlab/xrsfm :: 3rdparty/apriltag/common (zhash)

; 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.zhash_iterator = type { ptr, ptr, i32 }
%struct.zhash = type { i64, i64, i32, ptr, ptr, i32, ptr, i32 }

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.zhash_iterator_remove = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @zhash_put(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local void @zhash_iterator_remove(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.zhash_iterator, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  br label %12

11:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 322, ptr noundef @__PRETTY_FUNCTION__.zhash_iterator_remove) #6
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.zhash_iterator, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.zhash, ptr %16, i32 0, i32 6
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.zhash_iterator, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.zhash, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = mul nsw i32 %21, %24
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %18, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.zhash, ptr %28, i32 0, i32 5
  %30 = load i32, ptr %29, align 8, !tbaa !18
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %29, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.zhash_iterator, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = add nsw i32 %34, 1
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.zhash, ptr %36, i32 0, i32 7
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = sub nsw i32 %38, 1
  %40 = and i32 %35, %39
  store i32 %40, ptr %4, align 4, !tbaa !20
  br label %41

41:                                               ; preds = %102, %12
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.zhash, ptr %42, i32 0, i32 6
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = load i32, ptr %4, align 4, !tbaa !20
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.zhash, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !16
  %49 = mul nsw i32 %45, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %44, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !17
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %111

54:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.zhash, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !16
  %58 = sext i32 %57 to i64
  %59 = mul i64 1, %58
  %60 = call noalias ptr @malloc(i64 noundef %59) #8
  store ptr %60, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.zhash, ptr %62, i32 0, i32 6
  %64 = load ptr, ptr %63, align 8, !tbaa !12
  %65 = load i32, ptr %4, align 4, !tbaa !20
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.zhash, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 8, !tbaa !16
  %69 = mul nsw i32 %65, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %64, i64 %70
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.zhash, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 8, !tbaa !16
  %75 = sext i32 %74 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %61, ptr align 1 %71, i64 %75, i1 false)
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.zhash, ptr %76, i32 0, i32 6
  %78 = load ptr, ptr %77, align 8, !tbaa !12
  %79 = load i32, ptr %4, align 4, !tbaa !20
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.zhash, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 8, !tbaa !16
  %83 = mul nsw i32 %79, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %78, i64 %84
  store i8 0, ptr %85, align 1, !tbaa !17
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.zhash, ptr %86, i32 0, i32 5
  %88 = load i32, ptr %87, align 8, !tbaa !18
  %89 = add nsw i32 %88, -1
  store i32 %89, ptr %87, align 8, !tbaa !18
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 1
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.zhash, ptr %94, i32 0, i32 0
  %96 = load i64, ptr %95, align 8, !tbaa !21
  %97 = add i64 1, %96
  %98 = getelementptr inbounds i8, ptr %93, i64 %97
  %99 = call i32 @zhash_put(ptr noundef %90, ptr noundef %92, ptr noundef %98, ptr noundef null, ptr noundef null)
  %100 = icmp ne i32 %99, 0
  br i1 %100, label %101, label %102

101:                                              ; preds = %54
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 339, ptr noundef @__PRETTY_FUNCTION__.zhash_iterator_remove) #6
  unreachable

102:                                              ; preds = %54
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %103) #7
  %104 = load i32, ptr %4, align 4, !tbaa !20
  %105 = add nsw i32 %104, 1
  %106 = load ptr, ptr %3, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.zhash, ptr %106, i32 0, i32 7
  %108 = load i32, ptr %107, align 8, !tbaa !19
  %109 = sub nsw i32 %108, 1
  %110 = and i32 %105, %109
  store i32 %110, ptr %4, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  br label %41, !llvm.loop !22

111:                                              ; preds = %41
  %112 = load ptr, ptr %2, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.zhash_iterator, ptr %112, i32 0, i32 2
  %114 = load i32, ptr %113, align 8, !tbaa !15
  %115 = add nsw i32 %114, -1
  store i32 %115, ptr %113, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  ret void
}

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind allocsize(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 #6 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 0}
!10 = !{!"zhash_iterator", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 48}
!13 = !{!"zhash", !14, i64 0, !14, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !11, i64 16}
!16 = !{!13, !11, i64 16}
!17 = !{!7, !7, i64 0}
!18 = !{!13, !11, i64 40}
!19 = !{!13, !11, i64 56}
!20 = !{!11, !11, i64 0}
!21 = !{!13, !14, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@__PRETTY_FUNCTION__.zhash_iterator_remove = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @zhash_put(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @zhash_iterator_remove(ptr nocapture noundef %0) local_unnamed_addr #3 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 322, ptr noundef nonnull @__PRETTY_FUNCTION__.zhash_iterator_remove) #5
  unreachable

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %2, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !15
  %11 = mul nsw i32 %10, %8
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %6, i64 %12
  store i8 0, ptr %13, align 1, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %2, i64 40
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %14, align 8, !tbaa !17
  %17 = load i32, ptr %7, align 8, !tbaa !14
  %18 = add nsw i32 %17, 1
  %19 = getelementptr inbounds i8, ptr %2, i64 56
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %21 = add nsw i32 %20, -1
  %22 = and i32 %21, %18
  %23 = load ptr, ptr %5, align 8, !tbaa !11
  %24 = load i32, ptr %9, align 8, !tbaa !15
  %25 = mul nsw i32 %24, %22
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %.not2931 = icmp eq i8 %28, 0
  br i1 %.not2931, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %45
  %29 = phi ptr [ %50, %45 ], [ %23, %4 ]
  %30 = phi ptr [ %54, %45 ], [ %27, %4 ]
  %31 = phi i32 [ %51, %45 ], [ %24, %4 ]
  %.032 = phi i32 [ %49, %45 ], [ %22, %4 ]
  %32 = sext i32 %31 to i64
  %33 = tail call noalias ptr @malloc(i64 noundef %32) #6
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr nonnull align 1 %30, i64 %32, i1 false)
  %34 = mul nsw i32 %31, %.032
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %29, i64 %35
  store i8 0, ptr %36, align 1, !tbaa !16
  %37 = load i32, ptr %14, align 8, !tbaa !17
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %14, align 8, !tbaa !17
  %39 = getelementptr inbounds i8, ptr %33, i64 1
  %40 = load i64, ptr %2, align 8, !tbaa !19
  %41 = getelementptr i8, ptr %33, i64 %40
  %42 = getelementptr i8, ptr %41, i64 1
  %43 = tail call i32 @zhash_put(ptr noundef nonnull %2, ptr noundef nonnull %39, ptr noundef %42, ptr noundef null, ptr noundef null)
  %.not30 = icmp eq i32 %43, 0
  br i1 %.not30, label %45, label %44

44:                                               ; preds = %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 339, ptr noundef nonnull @__PRETTY_FUNCTION__.zhash_iterator_remove) #5
  unreachable

45:                                               ; preds = %.lr.ph
  tail call void @free(ptr noundef %33) #7
  %46 = add nsw i32 %.032, 1
  %47 = load i32, ptr %19, align 8, !tbaa !18
  %48 = add nsw i32 %47, -1
  %49 = and i32 %48, %46
  %50 = load ptr, ptr %5, align 8, !tbaa !11
  %51 = load i32, ptr %9, align 8, !tbaa !15
  %52 = mul nsw i32 %51, %49
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %50, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !16
  %.not29 = icmp eq i8 %55, 0
  br i1 %.not29, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !20

._crit_edge.loopexit:                             ; preds = %45
  %.pre = load i32, ptr %7, align 8, !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %56 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %17, %4 ]
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr %7, align 8, !tbaa !14
  ret void
}

attributes #0 = { noreturn 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 #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { noreturn nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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 0}
!6 = !{!"zhash_iterator", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 48}
!12 = !{!"zhash", !13, i64 0, !13, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!12, !10, i64 16}
!16 = !{!8, !8, i64 0}
!17 = !{!12, !10, i64 40}
!18 = !{!12, !10, i64 56}
!19 = !{!12, !13, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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