; LLVM IR from fmela/libdict :: src (rb_tree)

; 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.rb_tree = type { ptr, i64, ptr, i64 }
%struct.rb_node = type { ptr, ptr, i64, ptr, ptr }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@__func__.rb_tree_verify = external hidden unnamed_addr constant [15 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rb_tree_verify(ptr noundef %0) #3 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.rb_tree, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %29

11:                                               ; preds = %1
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.rb_tree, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.rb_node, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = and i64 %17, 1
  %19 = icmp eq i64 %18, 1
  %20 = zext i1 %19 to i32
  %21 = sext i32 %20 to i64
  %22 = call i64 @llvm.expect.i64(i64 %21, i64 1)
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %27, label %24

24:                                               ; preds = %12
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 552, ptr noundef @__func__.rb_tree_verify, ptr noundef @.str.6) #4
  store i1 false, ptr %2, align 1
  br label %96

27:                                               ; preds = %12
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !14
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rb_tree, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %72

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rb_tree, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !16
  %39 = icmp ugt i64 %38, 0
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = call i64 @llvm.expect.i64(i64 %41, i64 1)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %47, label %44

44:                                               ; preds = %35
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 555, ptr noundef @__func__.rb_tree_verify, ptr noundef @.str.7) #4
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %95

47:                                               ; preds = %35
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rb_tree, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  store ptr %52, ptr %6, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %67, %49
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %53
  store i32 6, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %71

57:                                               ; preds = %53
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.rb_node, ptr %58, i32 0, i32 2
  %60 = load i64, ptr %59, align 8, !tbaa !12
  %61 = and i64 %60, 1
  %62 = icmp eq i64 %61, 1
  br i1 %62, label %63, label %66

63:                                               ; preds = %57
  %64 = load i32, ptr %4, align 4, !tbaa !14
  %65 = add i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !14
  br label %66

66:                                               ; preds = %63, %57
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rb_node, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  store ptr %70, ptr %6, align 8, !tbaa !5
  br label %53, !llvm.loop !18

71:                                               ; preds = %56
  br label %88

72:                                               ; preds = %29
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.rb_tree, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !16
  %77 = icmp eq i64 %76, 0
  %78 = zext i1 %77 to i32
  %79 = sext i32 %78 to i64
  %80 = call i64 @llvm.expect.i64(i64 %79, i64 1)
  %81 = icmp ne i64 %80, 0
  br i1 %81, label %85, label %82

82:                                               ; preds = %73
  %83 = load ptr, ptr @stderr, align 8, !tbaa !5
  %84 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 560, ptr noundef @__func__.rb_tree_verify, ptr noundef @.str.4) #4
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %95

85:                                               ; preds = %73
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87, %71
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.rb_tree, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !9
  %93 = load i32, ptr %4, align 4, !tbaa !14
  %94 = call zeroext i1 @node_verify(ptr noundef %89, ptr noundef null, ptr noundef %92, i32 noundef 0, i32 noundef %93)
  store i1 %94, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %95

95:                                               ; preds = %88, %82, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %96

96:                                               ; preds = %95, %24
  %97 = load i1, ptr %2, align 1
  ret i1 %97
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @node_verify(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { 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 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 #4 = { 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, !6, i64 0}
!10 = !{!"rb_tree", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"rb_node", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !11, i64 8}
!17 = !{!13, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [37 x i8], align 1
@__func__.rb_tree_verify = external hidden unnamed_addr constant [15 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rb_tree_verify(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %22, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = and i64 %5, 1
  %.not18 = icmp eq i64 %6, 0
  br i1 %.not18, label %7, label %10, !prof !13

7:                                                ; preds = %3
  %8 = load ptr, ptr @stderr, align 8, !tbaa !14
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 552, ptr noundef nonnull @__func__.rb_tree_verify, ptr noundef nonnull @.str.6) #2
  br label %30

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %.not20 = icmp eq i64 %12, 0
  br i1 %.not20, label %13, label %.preheader, !prof !13

13:                                               ; preds = %10
  %14 = load ptr, ptr @stderr, align 8, !tbaa !14
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 555, ptr noundef nonnull @__func__.rb_tree_verify, ptr noundef nonnull @.str.7) #2
  br label %30

.preheader:                                       ; preds = %10, %.preheader
  %.024 = phi ptr [ %21, %.preheader ], [ %2, %10 ]
  %.01323 = phi i32 [ %spec.select, %.preheader ], [ 0, %10 ]
  %16 = getelementptr inbounds i8, ptr %.024, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = trunc i64 %17 to i32
  %19 = and i32 %18, 1
  %spec.select = add i32 %19, %.01323
  %20 = getelementptr inbounds i8, ptr %.024, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %.not21 = icmp eq ptr %21, null
  br i1 %.not21, label %.loopexit, label %.preheader, !llvm.loop !17

22:                                               ; preds = %1
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %.loopexit, label %26, !prof !19

26:                                               ; preds = %22
  %27 = load ptr, ptr @stderr, align 8, !tbaa !14
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 560, ptr noundef nonnull @__func__.rb_tree_verify, ptr noundef nonnull @.str.4) #2
  br label %30

.loopexit:                                        ; preds = %.preheader, %22
  %.2 = phi i32 [ 0, %22 ], [ %spec.select, %.preheader ]
  %29 = tail call zeroext i1 @node_verify(ptr noundef nonnull %0, ptr noundef null, ptr noundef %2, i32 noundef 0, i32 noundef %.2)
  br label %30

30:                                               ; preds = %13, %26, %.loopexit, %7
  %.115 = phi i1 [ false, %7 ], [ %29, %.loopexit ], [ false, %13 ], [ false, %26 ]
  ret i1 %.115
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @node_verify(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 #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 = { cold 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 = !{!"rb_tree", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"rb_node", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32}
!13 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !10, i64 8}
!16 = !{!12, !7, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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