; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/sglib_rbtree/rbtree.ll_sglib (rbtree_it_init)

; 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.sglib_rbtree_iterator = type { ptr, [128 x i8], [128 x ptr], i16, i16, ptr, ptr }
%struct.rbtree = type { i32, i8, ptr, ptr }

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

; 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
declare dso_local void @sglib__rbtree_it_compute_current_elem(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sglib__rbtree_it_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = trunc i32 %16 to i16
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %18, i32 0, i32 4
  store i16 %17, ptr %19, align 2, !tbaa !11
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %21, i32 0, i32 5
  store ptr %20, ptr %22, align 8, !tbaa !14
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %24, i32 0, i32 6
  store ptr %23, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %30

28:                                               ; preds = %5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %29, ptr %11, align 8, !tbaa !5
  br label %93

30:                                               ; preds = %5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %64

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %34, ptr %12, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %61, %33
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %62

38:                                               ; preds = %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.rbtree, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rbtree, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = sub nsw i32 %41, %44
  store i32 %45, ptr %13, align 4, !tbaa !9
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = icmp slt i32 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %38
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.rbtree, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  store ptr %51, ptr %12, align 8, !tbaa !5
  br label %61

52:                                               ; preds = %38
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %59

55:                                               ; preds = %52
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rbtree, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  store ptr %58, ptr %12, align 8, !tbaa !5
  br label %60

59:                                               ; preds = %52
  br label %62

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60, %48
  br label %35, !llvm.loop !20

62:                                               ; preds = %59, %35
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %63, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %92

64:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %65, ptr %14, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %89, %64
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %90

69:                                               ; preds = %66
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = call i32 %70(ptr noundef %71, ptr noundef %72)
  store i32 %73, ptr %15, align 4, !tbaa !9
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = icmp slt i32 %74, 0
  br i1 %75, label %76, label %80

76:                                               ; preds = %69
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rbtree, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !18
  store ptr %79, ptr %14, align 8, !tbaa !5
  br label %89

80:                                               ; preds = %69
  %81 = load i32, ptr %15, align 4, !tbaa !9
  %82 = icmp sgt i32 %81, 0
  br i1 %82, label %83, label %87

83:                                               ; preds = %80
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.rbtree, ptr %84, i32 0, i32 3
  %86 = load ptr, ptr %85, align 8, !tbaa !19
  store ptr %86, ptr %14, align 8, !tbaa !5
  br label %88

87:                                               ; preds = %80
  br label %90

88:                                               ; preds = %83
  br label %89

89:                                               ; preds = %88, %76
  br label %66, !llvm.loop !22

90:                                               ; preds = %87, %66
  %91 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %91, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %92

92:                                               ; preds = %90, %62
  br label %93

93:                                               ; preds = %92, %28
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = icmp eq ptr %94, null
  br i1 %95, label %96, label %101

96:                                               ; preds = %93
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %97, i32 0, i32 3
  store i16 0, ptr %98, align 8, !tbaa !23
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %99, i32 0, i32 0
  store ptr null, ptr %100, align 8, !tbaa !24
  br label %120

101:                                              ; preds = %93
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %102, i32 0, i32 3
  store i16 1, ptr %103, align 8, !tbaa !23
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %104, i32 0, i32 1
  %106 = getelementptr inbounds [128 x i8], ptr %105, i64 0, i64 0
  store i8 0, ptr %106, align 8, !tbaa !25
  %107 = load ptr, ptr %11, align 8, !tbaa !5
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %108, i32 0, i32 2
  %110 = getelementptr inbounds [128 x ptr], ptr %109, i64 0, i64 0
  store ptr %107, ptr %110, align 8, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !9
  %112 = icmp eq i32 %111, 0
  br i1 %112, label %113, label %117

113:                                              ; preds = %101
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %115, i32 0, i32 0
  store ptr %114, ptr %116, align 8, !tbaa !24
  br label %119

117:                                              ; preds = %101
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sglib__rbtree_it_compute_current_elem(ptr noundef %118)
  br label %119

119:                                              ; preds = %117, %113
  br label %120

120:                                              ; preds = %119, %96
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.sglib_rbtree_iterator, ptr %121, i32 0, i32 0
  %123 = load ptr, ptr %122, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret ptr %123
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 1162}
!12 = !{!"sglib_rbtree_iterator", !6, i64 0, !7, i64 8, !7, i64 136, !13, i64 1160, !13, i64 1162, !6, i64 1168, !6, i64 1176}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 1168}
!15 = !{!12, !6, i64 1176}
!16 = !{!17, !10, i64 0}
!17 = !{!"rbtree", !10, i64 0, !7, i64 4, !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 = distinct !{!22, !21}
!23 = !{!12, !13, i64 1160}
!24 = !{!12, !6, i64 0}
!25 = !{!7, !7, i64 0}


; 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
declare dso_local void @sglib__rbtree_it_compute_current_elem(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @sglib__rbtree_it_init(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = trunc i32 %2 to i16
  %7 = getelementptr inbounds i8, ptr %0, i64 1162
  store i16 %6, ptr %7, align 2, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 1168
  store ptr %4, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 1176
  store ptr %3, ptr %9, align 8, !tbaa !12
  %10 = icmp eq ptr %4, null
  br i1 %10, label %25, label %11

11:                                               ; preds = %5
  %12 = icmp eq ptr %3, null
  %.not4761 = icmp eq ptr %1, null
  br i1 %12, label %.preheader, label %.preheader54

.preheader54:                                     ; preds = %11
  br i1 %.not4761, label %.thread, label %.lr.ph

.preheader:                                       ; preds = %11
  br i1 %.not4761, label %.thread, label %.lr.ph63

.lr.ph63:                                         ; preds = %.preheader
  %13 = load i32, ptr %4, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %.lr.ph63, %18
  %.04062 = phi ptr [ %1, %.lr.ph63 ], [ %.141, %18 ]
  %15 = load i32, ptr %.04062, align 8, !tbaa !13
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  %.not48 = icmp eq i32 %13, %15
  br i1 %.not48, label %.thread51, label %18

18:                                               ; preds = %17, %14
  %.sink = phi i64 [ 8, %14 ], [ 16, %17 ]
  %19 = getelementptr inbounds i8, ptr %.04062, i64 %.sink
  %.141 = load ptr, ptr %19, align 8, !tbaa !16
  %.not47 = icmp eq ptr %.141, null
  br i1 %.not47, label %.thread, label %14, !llvm.loop !17

.lr.ph:                                           ; preds = %.preheader54, %23
  %.03960 = phi ptr [ %.1, %23 ], [ %1, %.preheader54 ]
  %20 = tail call i32 %3(ptr noundef nonnull %4, ptr noundef nonnull %.03960) #1
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %.lr.ph
  %.not46 = icmp eq i32 %20, 0
  br i1 %.not46, label %.thread51, label %23

23:                                               ; preds = %22, %.lr.ph
  %.sink72 = phi i64 [ 8, %.lr.ph ], [ 16, %22 ]
  %24 = getelementptr inbounds i8, ptr %.03960, i64 %.sink72
  %.1 = load ptr, ptr %24, align 8, !tbaa !16
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !19

25:                                               ; preds = %5
  %26 = icmp eq ptr %1, null
  br i1 %26, label %.thread, label %.thread51

.thread:                                          ; preds = %23, %18, %.preheader54, %.preheader, %25
  %27 = getelementptr inbounds i8, ptr %0, i64 1160
  store i16 0, ptr %27, align 8, !tbaa !20
  store ptr null, ptr %0, align 8, !tbaa !21
  br label %34

.thread51:                                        ; preds = %22, %17, %25
  %.053 = phi ptr [ %1, %25 ], [ %.04062, %17 ], [ %.03960, %22 ]
  %28 = getelementptr inbounds i8, ptr %0, i64 1160
  store i16 1, ptr %28, align 8, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 0, ptr %29, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %0, i64 136
  store ptr %.053, ptr %30, align 8, !tbaa !16
  %31 = icmp eq i32 %2, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %.thread51
  store ptr %.053, ptr %0, align 8, !tbaa !21
  br label %34

33:                                               ; preds = %.thread51
  tail call void @sglib__rbtree_it_compute_current_elem(ptr noundef nonnull %0)
  %.pre = load ptr, ptr %0, align 8, !tbaa !21
  br label %34

34:                                               ; preds = %32, %33, %.thread
  %35 = phi ptr [ %.053, %32 ], [ %.pre, %33 ], [ null, %.thread ]
  ret ptr %35
}

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 = { 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 1162}
!6 = !{!"sglib_rbtree_iterator", !7, i64 0, !8, i64 8, !8, i64 136, !10, i64 1160, !10, i64 1162, !7, i64 1168, !7, i64 1176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 1168}
!12 = !{!6, !7, i64 1176}
!13 = !{!14, !15, i64 0}
!14 = !{!"rbtree", !15, i64 0, !8, i64 4, !7, i64 8, !7, i64 16}
!15 = !{!"int", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!6, !10, i64 1160}
!21 = !{!6, !7, i64 0}
!22 = !{!8, !8, i64 0}


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