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

; 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.niosocket_s = type { i32 }
%struct.niohtable_s = type { ptr, i32, i32, 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_set(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %28, label %20

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = call i32 @niohtable_erase(ptr noundef %21, ptr noundef %22, ptr noundef %23)
  %25 = icmp eq i32 0, %24
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, i32 1, i32 -1
  store i32 %27, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

28:                                               ; preds = %17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i32 @htable_expandifneeded(ptr noundef %29)
  %31 = icmp ne i32 0, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

33:                                               ; preds = %28
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.niosocket_s, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !9
  store i32 %36, ptr %12, align 4, !tbaa !12
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.niohtable_s, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr %12, align 4, !tbaa !12
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.niohtable_s, ptr %41, i32 0, i32 3
  %43 = load i32, ptr %42, align 8, !tbaa !15
  %44 = and i32 %40, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %39, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  store ptr %47, ptr %10, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %78, %33
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %82

51:                                               ; preds = %48
  %52 = load i32, ptr %12, align 4, !tbaa !12
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.niohnode_s, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = getelementptr inbounds %struct.niosocket_s, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp eq i32 %52, %57
  br i1 %58, label %59, label %78

59:                                               ; preds = %51
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %67

62:                                               ; preds = %59
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.niohnode_s, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !18
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %65, ptr %66, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %62, %59
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.niohnode_s, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !18
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = icmp ne ptr %70, %71
  br i1 %72, label %73, label %77

73:                                               ; preds = %67
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.niohnode_s, ptr %75, i32 0, i32 1
  store ptr %74, ptr %76, align 8, !tbaa !18
  br label %77

77:                                               ; preds = %73, %67
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

78:                                               ; preds = %51
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.niohnode_s, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !19
  store ptr %81, ptr %10, align 8, !tbaa !5
  br label %48, !llvm.loop !20

82:                                               ; preds = %48
  %83 = call ptr @nio_realloc(ptr noundef null, i64 noundef 24)
  store ptr %83, ptr %10, align 8, !tbaa !5
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

87:                                               ; preds = %82
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.niohnode_s, ptr %89, i32 0, i32 0
  store ptr %88, ptr %90, align 8, !tbaa !16
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.niohnode_s, ptr %92, i32 0, i32 1
  store ptr %91, ptr %93, align 8, !tbaa !18
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.niohtable_s, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !13
  %97 = load i32, ptr %12, align 4, !tbaa !12
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.niohtable_s, ptr %98, i32 0, i32 3
  %100 = load i32, ptr %99, align 8, !tbaa !15
  %101 = and i32 %97, %100
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds ptr, ptr %96, i64 %102
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.niohnode_s, ptr %105, i32 0, i32 2
  store ptr %104, ptr %106, align 8, !tbaa !19
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.niohtable_s, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !13
  %111 = load i32, ptr %12, align 4, !tbaa !12
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.niohtable_s, ptr %112, i32 0, i32 3
  %114 = load i32, ptr %113, align 8, !tbaa !15
  %115 = and i32 %111, %114
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds ptr, ptr %110, i64 %116
  store ptr %107, ptr %117, align 8, !tbaa !5
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.niohtable_s, ptr %118, i32 0, i32 2
  %120 = load i32, ptr %119, align 4, !tbaa !22
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr %119, align 4, !tbaa !22
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %122

122:                                              ; preds = %87, %86, %77, %32, %20, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %123 = load i32, ptr %5, align 4
  ret i32 %123
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @niohtable_erase(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_expandifneeded(ptr noundef) #2

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


; 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, 2) i32 @niohtable_set(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %42, label %5

5:                                                ; preds = %4
  %.not40 = icmp eq ptr %2, null
  br i1 %.not40, label %6, label %10

6:                                                ; preds = %5
  %7 = tail call i32 @niohtable_erase(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %3)
  %8 = icmp eq i32 %7, 0
  %9 = select i1 %8, i32 1, i32 -1
  br label %42

10:                                               ; preds = %5
  %11 = tail call i32 @htable_expandifneeded(ptr noundef %0)
  %.not41 = icmp eq i32 %11, 0
  br i1 %.not41, label %12, label %42

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

.lr.ph:                                           ; preds = %12, %27
  %.03549 = phi ptr [ %.035, %27 ], [ %.03547, %12 ]
  %20 = load ptr, ptr %.03549, align 8, !tbaa !15
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %13, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %.lr.ph
  %.not44 = icmp eq ptr %3, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.03549, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !17
  br i1 %.not44, label %._crit_edge51, label %24

24:                                               ; preds = %23
  store ptr %.pre, ptr %3, align 8, !tbaa !14
  br label %._crit_edge51

._crit_edge51:                                    ; preds = %23, %24
  %.not45 = icmp eq ptr %.pre, %2
  br i1 %.not45, label %42, label %25

25:                                               ; preds = %._crit_edge51
  %26 = getelementptr inbounds i8, ptr %.03549, i64 8
  store ptr %2, ptr %26, align 8, !tbaa !17
  br label %42

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds i8, ptr %.03549, i64 16
  %.035 = load ptr, ptr %28, align 8, !tbaa !14
  %.not42 = icmp eq ptr %.035, null
  br i1 %.not42, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %27, %12
  %29 = tail call ptr @nio_realloc(ptr noundef null, i64 noundef 24) #2
  %.not43 = icmp eq ptr %29, null
  br i1 %.not43, label %42, label %30

30:                                               ; preds = %._crit_edge
  store ptr %1, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %2, ptr %31, align 8, !tbaa !17
  %32 = load ptr, ptr %0, align 8, !tbaa !10
  %33 = load i32, ptr %15, align 8, !tbaa !13
  %34 = and i32 %33, %13
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %32, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %29, i64 16
  store ptr %37, ptr %38, align 8, !tbaa !20
  store ptr %29, ptr %36, align 8, !tbaa !14
  %39 = getelementptr inbounds i8, ptr %0, i64 12
  %40 = load i32, ptr %39, align 4, !tbaa !21
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 4, !tbaa !21
  br label %42

42:                                               ; preds = %._crit_edge, %._crit_edge51, %25, %10, %4, %30, %6
  %.0 = phi i32 [ 0, %30 ], [ %9, %6 ], [ -1, %4 ], [ -1, %10 ], [ 1, %25 ], [ 1, %._crit_edge51 ], [ -1, %._crit_edge ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @niohtable_erase(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @htable_expandifneeded(ptr noundef) local_unnamed_addr #1

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


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