; LLVM IR from chaoran/fast-wait-free-queue :: hzdptr.ll (hzdptr_retire)

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

; Function Attrs: nounwind uwtable
define dso_local void @_hzdptr_retire(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, 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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._hzdptr_t, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = mul nsw i32 4, %15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._hzdptr_t, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = mul nsw i32 %16, %19
  %21 = sext i32 %20 to i64
  store i64 %21, ptr %5, align 8, !tbaa !13
  %22 = load i64, ptr %5, align 8, !tbaa !13
  %23 = call ptr @llvm.stacksave.p0()
  store ptr %23, ptr %6, align 8
  %24 = alloca ptr, i64 %22, align 16
  store i64 %22, ptr %7, align 8
  %25 = mul nuw i64 8, %22
  call void @llvm.memset.p0.i64(ptr align 16 %24, i8 0, i64 %25, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %26, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  br label %27

27:                                               ; preds = %58, %2
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._hzdptr_t, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  store ptr %30, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = icmp ne ptr %30, %31
  br i1 %32, label %33, label %59

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !16
  br label %34

34:                                               ; preds = %55, %33
  %35 = load i32, ptr %10, align 4, !tbaa !16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._hzdptr_t, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !12
  %39 = icmp slt i32 %35, %38
  br i1 %39, label %40, label %58

40:                                               ; preds = %34
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._hzdptr_t, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load i32, ptr %10, align 4, !tbaa !16
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  store ptr %47, ptr %9, align 8, !tbaa !5
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %54

50:                                               ; preds = %40
  %51 = load i64, ptr %5, align 8, !tbaa !13
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @htable_insert(ptr noundef %24, i64 noundef %51, ptr noundef %52)
  br label %54

54:                                               ; preds = %50, %40
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %10, align 4, !tbaa !16
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !16
  br label %34, !llvm.loop !18

58:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %27, !llvm.loop !20

59:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !16
  br label %60

60:                                               ; preds = %86, %59
  %61 = load i32, ptr %12, align 4, !tbaa !16
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._hzdptr_t, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 8, !tbaa !21
  %65 = icmp slt i32 %61, %64
  br i1 %65, label %66, label %89

66:                                               ; preds = %60
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !16
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  store ptr %71, ptr %9, align 8, !tbaa !5
  %72 = load i64, ptr %5, align 8, !tbaa !13
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call i32 @htable_lookup(ptr noundef %24, i64 noundef %72, ptr noundef %73)
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %83

76:                                               ; preds = %66
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load i32, ptr %11, align 4, !tbaa !16
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !16
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds ptr, ptr %78, i64 %81
  store ptr %77, ptr %82, align 8, !tbaa !5
  br label %85

83:                                               ; preds = %66
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %84) #5
  br label %85

85:                                               ; preds = %83, %76
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %12, align 4, !tbaa !16
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %12, align 4, !tbaa !16
  br label %60, !llvm.loop !22

89:                                               ; preds = %60
  %90 = load i32, ptr %11, align 4, !tbaa !16
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._hzdptr_t, ptr %91, i32 0, i32 3
  store i32 %90, ptr %92, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %93 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; 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
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_insert(ptr noundef, i64 noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_lookup(ptr noundef, i64 noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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, !11, i64 8}
!10 = !{!"_hzdptr_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !6, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!10, !11, i64 16}
!22 = distinct !{!22, !19}


; 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: nounwind uwtable
define dso_local void @_hzdptr_retire(ptr noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = shl nsw i32 %4, 2
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = mul nsw i32 %5, %7
  %9 = sext i32 %8 to i64
  %10 = alloca ptr, i64 %9, align 16
  %11 = shl nuw nsw i64 %9, 3
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %10, i8 0, i64 %11, i1 false)
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  %.not38 = icmp eq ptr %12, %0
  br i1 %.not38, label %.preheader, label %.preheader35

.loopexit:                                        ; preds = %29, %.preheader35
  %13 = load ptr, ptr %14, align 8, !tbaa !12
  %.not = icmp eq ptr %13, %0
  br i1 %.not, label %.preheader, label %.preheader35, !llvm.loop !13

.preheader35:                                     ; preds = %2, %.loopexit
  %14 = phi ptr [ %13, %.loopexit ], [ %12, %2 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader35
  %18 = getelementptr inbounds i8, ptr %14, i64 24
  br label %22

.preheader:                                       ; preds = %.loopexit, %2
  %.lcssa36 = phi ptr [ %12, %2 ], [ %13, %.loopexit ]
  %19 = getelementptr inbounds i8, ptr %.lcssa36, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph41, label %._crit_edge

22:                                               ; preds = %.lr.ph, %29
  %23 = phi i32 [ %16, %.lr.ph ], [ %30, %29 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %24 = load ptr, ptr %18, align 8, !tbaa !16
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %.not34 = icmp eq ptr %26, null
  br i1 %.not34, label %29, label %27

27:                                               ; preds = %22
  %28 = call i32 @htable_insert(ptr noundef nonnull %10, i64 noundef %9, ptr noundef nonnull %26)
  %.pre = load i32, ptr %15, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %22, %27
  %30 = phi i32 [ %23, %22 ], [ %.pre, %27 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next, %31
  br i1 %32, label %22, label %.loopexit, !llvm.loop !18

.lr.ph41:                                         ; preds = %.preheader, %41
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %41 ], [ 0, %.preheader ]
  %.02739 = phi i32 [ %.1, %41 ], [ 0, %.preheader ]
  %33 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv44
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = call i32 @htable_lookup(ptr noundef nonnull %10, i64 noundef %9, ptr noundef %34)
  %.not33 = icmp eq i32 %35, 0
  br i1 %.not33, label %40, label %36

36:                                               ; preds = %.lr.ph41
  %37 = add nsw i32 %.02739, 1
  %38 = sext i32 %.02739 to i64
  %39 = getelementptr inbounds ptr, ptr %1, i64 %38
  store ptr %34, ptr %39, align 8, !tbaa !17
  br label %41

40:                                               ; preds = %.lr.ph41
  call void @free(ptr noundef %34) #3
  br label %41

41:                                               ; preds = %36, %40
  %.1 = phi i32 [ %37, %36 ], [ %.02739, %40 ]
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %42 = load i32, ptr %19, align 8, !tbaa !15
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next45, %43
  br i1 %44, label %.lr.ph41, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %41, %.preheader
  %.027.lcssa = phi i32 [ 0, %.preheader ], [ %.1, %41 ]
  store i32 %.027.lcssa, ptr %19, align 8, !tbaa !15
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_insert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_lookup(ptr noundef, i64 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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, !10, i64 8}
!6 = !{!"_hzdptr_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !7, i64 24}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}


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