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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @niohtable_next(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = 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
  br label %8

8:                                                ; preds = %81, %3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.niohtableiter_s, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %42, label %13

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

27:                                               ; preds = %13
  br label %82

28:                                               ; preds = %13
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.niohtableiter_s, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.niohtable_s, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.niohtableiter_s, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !12
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %33, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.niohtableiter_s, ptr %40, i32 0, i32 2
  store ptr %39, ptr %41, align 8, !tbaa !9
  br label %48

42:                                               ; preds = %8
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.niohtableiter_s, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.niohtableiter_s, ptr %46, i32 0, i32 2
  store ptr %45, ptr %47, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %42, %28
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.niohtableiter_s, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %81

53:                                               ; preds = %48
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.niohtableiter_s, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.niohnode_s, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.niohtableiter_s, ptr %59, i32 0, i32 3
  store ptr %58, ptr %60, align 8, !tbaa !17
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %70

63:                                               ; preds = %53
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.niohtableiter_s, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.niohnode_s, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %68, ptr %69, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %63, %53
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %80

73:                                               ; preds = %70
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.niohtableiter_s, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.niohnode_s, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %78, ptr %79, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %73, %70
  store i32 0, ptr %4, align 4
  br label %83

81:                                               ; preds = %48
  br label %8

82:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  br label %83

83:                                               ; preds = %82, %80
  %84 = load i32, ptr %4, align 4
  ret i32 %84
}

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

!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 16}
!10 = !{!"niohtableiter_s", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !11, i64 8}
!15 = !{!"niohtable_s", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!16 = !{!15, !6, i64 0}
!17 = !{!10, !6, i64 24}
!18 = !{!19, !6, i64 16}
!19 = !{!"niohnode_s", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!19, !6, i64 0}
!21 = !{!19, !6, i64 8}


; 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 -1, 1) i32 @niohtable_next(ptr nocapture noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
.peel.begin:
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %.promoted = load ptr, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = icmp eq ptr %.promoted, null
  br i1 %6, label %7, label %17

7:                                                ; preds = %.peel.begin
  %8 = load i32, ptr %0, align 8, !tbaa !11
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %0, align 8, !tbaa !11
  %10 = load ptr, ptr %5, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %.not22.peel = icmp slt i32 %9, %12
  br i1 %.not22.peel, label %13, label %.loopexit

13:                                               ; preds = %7
  %14 = load ptr, ptr %10, align 8, !tbaa !15
  %15 = sext i32 %9 to i64
  %16 = getelementptr inbounds ptr, ptr %14, i64 %15
  br label %17

17:                                               ; preds = %13, %.peel.begin
  %storemerge.in.peel = phi ptr [ %16, %13 ], [ %4, %.peel.begin ]
  %storemerge.peel = load ptr, ptr %storemerge.in.peel, align 8, !tbaa !16
  store ptr %storemerge.peel, ptr %3, align 8, !tbaa !5
  %.not23.peel = icmp eq ptr %storemerge.peel, null
  br i1 %.not23.peel, label %.peel.next, label %.loopexit29

.peel.next:                                       ; preds = %17
  %18 = load ptr, ptr %5, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %.promoted31 = load i32, ptr %0, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %.peel.next, %24
  %22 = phi i32 [ %.promoted31, %.peel.next ], [ %23, %24 ]
  %23 = add nsw i32 %22, 1
  %.not22 = icmp slt i32 %23, %20
  br i1 %.not22, label %24, label %.loopexit.loopexit

24:                                               ; preds = %21
  %25 = load ptr, ptr %18, align 8, !tbaa !15
  %26 = sext i32 %23 to i64
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %storemerge = load ptr, ptr %27, align 8, !tbaa !16
  store ptr %storemerge, ptr %3, align 8, !tbaa !5
  %.not23 = icmp eq ptr %storemerge, null
  br i1 %.not23, label %21, label %.loopexit29.loopexit, !llvm.loop !17

.loopexit29.loopexit:                             ; preds = %24
  store i32 %23, ptr %0, align 8, !tbaa !11
  br label %.loopexit29

.loopexit29:                                      ; preds = %.loopexit29.loopexit, %17
  %storemerge.lcssa = phi ptr [ %storemerge.peel, %17 ], [ %storemerge, %.loopexit29.loopexit ]
  %28 = getelementptr inbounds i8, ptr %storemerge.lcssa, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  store ptr %29, ptr %4, align 8, !tbaa !21
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %32, label %30

30:                                               ; preds = %.loopexit29
  %31 = load ptr, ptr %storemerge.lcssa, align 8, !tbaa !22
  store ptr %31, ptr %1, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %30, %.loopexit29
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %.loopexit, label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 8
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  store ptr %36, ptr %2, align 8, !tbaa !16
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %21
  store i32 %23, ptr %0, align 8, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %7, %32, %33
  %.0 = phi i32 [ 0, %33 ], [ 0, %32 ], [ -1, %7 ], [ -1, %.loopexit.loopexit ]
  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, !10, i64 16}
!6 = !{!"niohtableiter_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !7, i64 8}
!14 = !{!"niohtable_s", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.peeled.count", i32 1}
!19 = !{!20, !10, i64 16}
!20 = !{!"niohnode_s", !10, i64 0, !10, i64 8, !10, i64 16}
!21 = !{!6, !10, i64 24}
!22 = !{!20, !10, i64 0}
!23 = !{!20, !10, i64 8}


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