; LLVM IR from shixiongfei/nio4c :: nio4c_htable (niohtable_erase)

; 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.niohtable_s = type { ptr, i32, i32, i32 }
%struct.niosocket_s = type { i32 }
%struct.niohnode_s = type { ptr, ptr, ptr }

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

declare ptr @nio_realloc(ptr noundef, i64 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 i32 @niohtable_erase(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %24

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.niohtable_s, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i32 0, %17
  br i1 %18, label %24, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.niohtable_s, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp eq i32 0, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %19, %14, %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %95

25:                                               ; preds = %19
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.niosocket_s, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !13
  store i32 %28, ptr %10, align 4, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.niohtable_s, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %10, align 4, !tbaa !15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.niohtable_s, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 8, !tbaa !17
  %36 = and i32 %32, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %31, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %8, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %89, %25
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %94

43:                                               ; preds = %40
  %44 = load i32, ptr %10, align 4, !tbaa !15
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.niohnode_s, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %struct.niosocket_s, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = icmp eq i32 %44, %49
  br i1 %50, label %51, label %89

51:                                               ; preds = %43
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %60

54:                                               ; preds = %51
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.niohnode_s, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.niohnode_s, ptr %58, i32 0, i32 2
  store ptr %57, ptr %59, align 8, !tbaa !20
  br label %74

60:                                               ; preds = %51
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.niohnode_s, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.niohtable_s, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load i32, ptr %10, align 4, !tbaa !15
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.niohtable_s, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 8, !tbaa !17
  %71 = and i32 %67, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds ptr, ptr %66, i64 %72
  store ptr %63, ptr %73, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %60, %54
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %82

77:                                               ; preds = %74
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.niohnode_s, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !21
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %80, ptr %81, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %77, %74
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = call ptr @nio_realloc(ptr noundef %83, i64 noundef 0)
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.niohtable_s, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 4, !tbaa !12
  %88 = sub nsw i32 %87, 1
  store i32 %88, ptr %86, align 4, !tbaa !12
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %95

89:                                               ; preds = %43
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %90, ptr %9, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.niohnode_s, ptr %91, i32 0, i32 2
  %93 = load ptr, ptr %92, align 8, !tbaa !20
  store ptr %93, ptr %8, align 8, !tbaa !5
  br label %40, !llvm.loop !22

94:                                               ; preds = %40
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %95

95:                                               ; preds = %94, %82, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %96 = load i32, ptr %4, align 4
  ret i32 %96
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #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, !11, i64 8}
!10 = !{!"niohtable_s", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!14, !11, i64 0}
!14 = !{!"niosocket_s", !11, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !11, i64 16}
!18 = !{!19, !6, i64 0}
!19 = !{!"niohnode_s", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!19, !6, i64 16}
!21 = !{!19, !6, i64 8}
!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"

declare ptr @nio_realloc(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @niohtable_erase(ptr nocapture noundef %0, ptr noundef readonly %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %8
  %13 = load i32, ptr %1, align 4, !tbaa !12
  %14 = load ptr, ptr %0, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %17 = and i32 %16, %13
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %14, i64 %18
  %.02534 = load ptr, ptr %19, align 8, !tbaa !16
  %.not2935 = icmp eq ptr %.02534, null
  br i1 %.not2935, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  %20 = load ptr, ptr %.02534, align 8, !tbaa !17
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = icmp eq i32 %13, %21
  br i1 %22, label %.lr.ph._crit_edge, label %.lr.ph45

.lr.ph:                                           ; preds = %.lr.ph45
  %23 = load ptr, ptr %.025, align 8, !tbaa !17
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = icmp eq i32 %13, %24
  br i1 %25, label %.lr.ph._crit_edge, label %.lr.ph45, !llvm.loop !19

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %.lr.ph.preheader
  %.02537.lcssa = phi ptr [ %.02534, %.lr.ph.preheader ], [ %.025, %.lr.ph ]
  %.02436.lcssa = phi ptr [ null, %.lr.ph.preheader ], [ %.0253744, %.lr.ph ]
  %.not30 = icmp eq ptr %.02436.lcssa, null
  %26 = getelementptr inbounds i8, ptr %.02537.lcssa, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %.02436.lcssa, i64 16
  %.sink = select i1 %.not30, ptr %19, ptr %28
  store ptr %27, ptr %.sink, align 8, !tbaa !16
  %.not31 = icmp eq ptr %2, null
  br i1 %.not31, label %32, label %29

29:                                               ; preds = %.lr.ph._crit_edge
  %30 = getelementptr inbounds i8, ptr %.02537.lcssa, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  store ptr %31, ptr %2, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %29, %.lr.ph._crit_edge
  %33 = tail call ptr @nio_realloc(ptr noundef nonnull %.02537.lcssa, i64 noundef 0) #2
  %34 = load i32, ptr %9, align 4, !tbaa !11
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %9, align 4, !tbaa !11
  br label %.loopexit

.lr.ph45:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0253744 = phi ptr [ %.025, %.lr.ph ], [ %.02534, %.lr.ph.preheader ]
  %36 = getelementptr inbounds i8, ptr %.0253744, i64 16
  %.025 = load ptr, ptr %36, align 8, !tbaa !16
  %.not29 = icmp eq ptr %.025, null
  br i1 %.not29, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %.lr.ph45, %12, %3, %4, %8, %32
  %.0 = phi i32 [ 0, %32 ], [ -1, %8 ], [ -1, %4 ], [ -1, %3 ], [ -1, %12 ], [ -1, %.lr.ph45 ]
  ret i32 %.0
}

attributes #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 = { 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 8}
!6 = !{!"niohtable_s", !7, i64 0, !10, i64 8, !10, i64 12, !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 = !{!6, !10, i64 12}
!12 = !{!13, !10, i64 0}
!13 = !{!"niosocket_s", !10, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !10, i64 16}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"niohnode_s", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!18, !7, i64 16}
!22 = !{!18, !7, i64 8}


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