; 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 }

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

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

15:                                               ; preds = %88, %3
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.zhash_iterator, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = add nsw i32 %19, 1
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.zhash, ptr %21, i32 0, i32 7
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = icmp sge i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

26:                                               ; preds = %16
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.zhash_iterator, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 8, !tbaa !12
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.zhash, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.zhash_iterator, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.zhash, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = mul nsw i32 %36, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %33, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !18
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %88

45:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.zhash, ptr %46, i32 0, i32 6
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.zhash_iterator, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !12
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.zhash, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 8, !tbaa !17
  %55 = mul nsw i32 %51, %54
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %48, i64 %57
  store ptr %58, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.zhash, ptr %59, i32 0, i32 6
  %61 = load ptr, ptr %60, align 8, !tbaa !16
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.zhash_iterator, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !12
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.zhash, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !17
  %68 = mul nsw i32 %64, %67
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.zhash, ptr %71, i32 0, i32 0
  %73 = load i64, ptr %72, align 8, !tbaa !19
  %74 = add i64 %70, %73
  %75 = getelementptr inbounds i8, ptr %61, i64 %74
  store ptr %75, ptr %11, align 8, !tbaa !5
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = icmp ne ptr %76, null
  br i1 %77, label %78, label %81

78:                                               ; preds = %45
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %79, ptr %80, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %78, %45
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %87

84:                                               ; preds = %81
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %85, ptr %86, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %84, %81
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %89

88:                                               ; preds = %26
  br label %15

89:                                               ; preds = %87, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %90 = load i32, ptr %4, align 4
  ret i32 %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"zhash_iterator", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!14, !11, i64 56}
!14 = !{!"zhash", !15, i64 0, !15, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !11, i64 56}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 48}
!17 = !{!14, !11, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !15, i64 0}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @zhash_iterator_next_volatile(ptr nocapture noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = getelementptr inbounds i8, ptr %5, i64 56
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %.promoted = load i32, ptr %6, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %5, i64 48
  %10 = getelementptr inbounds i8, ptr %5, i64 16
  br label %11

11:                                               ; preds = %14, %3
  %12 = phi i32 [ %13, %14 ], [ %.promoted, %3 ]
  %13 = add nsw i32 %12, 1
  %.not = icmp slt i32 %13, %8
  br i1 %.not, label %14, label %.loopexit

14:                                               ; preds = %11
  store i32 %13, ptr %6, align 8, !tbaa !14
  %15 = load ptr, ptr %9, align 8, !tbaa !15
  %16 = load i32, ptr %10, align 8, !tbaa !16
  %17 = mul nsw i32 %16, %13
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %15, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !17
  %.not23 = icmp eq i8 %20, 0
  br i1 %.not23, label %11, label %21

21:                                               ; preds = %14
  %22 = add nsw i32 %17, 1
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr %5, align 8, !tbaa !18
  %25 = getelementptr i8, ptr %15, i64 %24
  %26 = getelementptr i8, ptr %25, i64 %23
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %29, label %27

27:                                               ; preds = %21
  %28 = getelementptr inbounds i8, ptr %15, i64 %23
  store ptr %28, ptr %1, align 8, !tbaa !19
  br label %29

29:                                               ; preds = %27, %21
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %.loopexit, label %30

30:                                               ; preds = %29
  store ptr %26, ptr %2, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %11, %29, %30
  %.0 = phi i32 [ 1, %30 ], [ 1, %29 ], [ 0, %11 ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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 8}
!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, !10, i64 56}
!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, !7, i64 48}
!16 = !{!12, !10, i64 16}
!17 = !{!8, !8, i64 0}
!18 = !{!12, !13, i64 0}
!19 = !{!7, !7, i64 0}


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