; 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 = type { i64, i64, i32, ptr, ptr, i32, ptr, i32 }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.zhash_create_capacity = external hidden unnamed_addr constant [117 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @zhash_create_capacity(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %5
  br label %18

17:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 61, ptr noundef @__PRETTY_FUNCTION__.zhash_create_capacity) #4
  unreachable

18:                                               ; preds = %16
  %19 = load ptr, ptr %9, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  br label %23

22:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 62, ptr noundef @__PRETTY_FUNCTION__.zhash_create_capacity) #4
  unreachable

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = mul nsw i32 4, %24
  store i32 %25, ptr %11, align 4, !tbaa !11
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = icmp slt i32 %26, 8
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 8, ptr %11, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %28, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %30 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %30, ptr %12, align 4, !tbaa !11
  %31 = load i32, ptr %12, align 4, !tbaa !11
  %32 = load i32, ptr %12, align 4, !tbaa !11
  %33 = sub nsw i32 %32, 1
  %34 = and i32 %31, %33
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %45

36:                                               ; preds = %29
  store i32 8, ptr %12, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %41, %36
  %38 = load i32, ptr %12, align 4, !tbaa !11
  %39 = load i32, ptr %11, align 4, !tbaa !11
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %37
  %42 = load i32, ptr %12, align 4, !tbaa !11
  %43 = mul nsw i32 %42, 2
  store i32 %43, ptr %12, align 4, !tbaa !11
  br label %37, !llvm.loop !13

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %46 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 64) #6
  store ptr %46, ptr %13, align 8, !tbaa !9
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %13, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.zhash, ptr %48, i32 0, i32 0
  store i64 %47, ptr %49, align 8, !tbaa !15
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.zhash, ptr %51, i32 0, i32 1
  store i64 %50, ptr %52, align 8, !tbaa !17
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = load ptr, ptr %13, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.zhash, ptr %54, i32 0, i32 3
  store ptr %53, ptr %55, align 8, !tbaa !18
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  %57 = load ptr, ptr %13, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.zhash, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !19
  %59 = load i32, ptr %12, align 4, !tbaa !11
  %60 = load ptr, ptr %13, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.zhash, ptr %60, i32 0, i32 7
  store i32 %59, ptr %61, align 8, !tbaa !20
  %62 = load ptr, ptr %13, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.zhash, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !15
  %65 = add i64 1, %64
  %66 = load ptr, ptr %13, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.zhash, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !17
  %69 = add i64 %65, %68
  %70 = trunc i64 %69 to i32
  %71 = load ptr, ptr %13, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.zhash, ptr %71, i32 0, i32 2
  store i32 %70, ptr %72, align 8, !tbaa !21
  %73 = load ptr, ptr %13, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.zhash, ptr %73, i32 0, i32 7
  %75 = load i32, ptr %74, align 8, !tbaa !20
  %76 = sext i32 %75 to i64
  %77 = load ptr, ptr %13, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.zhash, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !21
  %80 = sext i32 %79 to i64
  %81 = call noalias ptr @calloc(i64 noundef %76, i64 noundef %80) #6
  %82 = load ptr, ptr %13, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.zhash, ptr %82, i32 0, i32 6
  store ptr %81, ptr %83, align 8, !tbaa !22
  %84 = load i32, ptr %12, align 4, !tbaa !11
  %85 = load ptr, ptr %13, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.zhash, ptr %85, i32 0, i32 7
  store i32 %84, ptr %86, align 8, !tbaa !20
  %87 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  ret ptr %87
}

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

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #3

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

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"zhash", !6, i64 0, !6, i64 8, !12, i64 16, !10, i64 24, !10, i64 32, !12, i64 40, !10, i64 48, !12, i64 56}
!17 = !{!16, !6, i64 8}
!18 = !{!16, !10, i64 24}
!19 = !{!16, !10, i64 32}
!20 = !{!16, !12, i64 56}
!21 = !{!16, !12, i64 16}
!22 = !{!16, !10, i64 48}


; 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 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.zhash_create_capacity = external hidden unnamed_addr constant [117 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @zhash_create_capacity(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %6, label %7

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

7:                                                ; preds = %5
  %.not30 = icmp eq ptr %3, null
  br i1 %.not30, label %8, label %9

8:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 62, ptr noundef nonnull @__PRETTY_FUNCTION__.zhash_create_capacity) #4
  unreachable

9:                                                ; preds = %7
  %10 = shl nsw i32 %4, 2
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %10, i32 8)
  %11 = tail call range(i32 0, 30) i32 @llvm.ctpop.i32(i32 %spec.store.select)
  %.not31 = icmp ult i32 %11, 2
  br i1 %.not31, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %9, %.preheader
  %.0 = phi i32 [ %13, %.preheader ], [ 8, %9 ]
  %12 = icmp ult i32 %.0, %spec.store.select
  %13 = shl nsw i32 %.0, 1
  br i1 %12, label %.preheader, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %.preheader, %9
  %.1 = phi i32 [ %spec.store.select, %9 ], [ %.0, %.preheader ]
  %14 = tail call noalias dereferenceable_or_null(64) ptr @calloc(i64 noundef 1, i64 noundef 64) #5
  store i64 %0, ptr %14, align 8, !tbaa !7
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store i64 %1, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr %2, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %14, i64 32
  store ptr %3, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %14, i64 56
  %19 = add i64 %0, 1
  %20 = add i64 %19, %1
  %21 = trunc i64 %20 to i32
  %22 = getelementptr inbounds i8, ptr %14, i64 16
  store i32 %21, ptr %22, align 8, !tbaa !17
  %23 = sext i32 %.1 to i64
  %sext = shl i64 %20, 32
  %24 = ashr exact i64 %sext, 32
  %25 = tail call noalias ptr @calloc(i64 noundef %23, i64 noundef %24) #5
  %26 = getelementptr inbounds i8, ptr %14, i64 48
  store ptr %25, ptr %26, align 8, !tbaa !18
  store i32 %.1, ptr %18, align 8, !tbaa !19
  ret ptr %14
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #3

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { noreturn nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 0}
!8 = !{!"zhash", !9, i64 0, !9, i64 8, !12, i64 16, !13, i64 24, !13, i64 32, !12, i64 40, !13, i64 48, !12, i64 56}
!9 = !{!"long", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!8, !9, i64 8}
!15 = !{!8, !13, i64 24}
!16 = !{!8, !13, i64 32}
!17 = !{!8, !12, i64 16}
!18 = !{!8, !13, i64 48}
!19 = !{!8, !12, i64 56}


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