; LLVM IR from VAR-solutions/Algorithms :: data structures/Red Black/CPP/arvore_rb_c.ll (ZN4Tree6insertEi)

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

%class.Tree = type { ptr, ptr }
%struct.node = type { i32, i32, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z8criar_noiP4node(i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Tree6insertEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %9, %11
  br i1 %12, label %13, label %22

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = call noundef ptr @_Z8criar_noiP4node(i32 noundef %14, ptr noundef %16)
  %18 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 0
  store ptr %17, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 1
  store i32 1, ptr %21, align 4, !tbaa !14
  br label %77

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %23 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr %24, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  br label %25

25:                                               ; preds = %45, %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = icmp ne ptr %26, %28
  br i1 %29, label %30, label %46

30:                                               ; preds = %25
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp sgt i32 %34, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %30
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  store ptr %40, ptr %5, align 8, !tbaa !5
  br label %45

41:                                               ; preds = %30
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  store ptr %44, ptr %5, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %41, %37
  br label %25, !llvm.loop !19

46:                                               ; preds = %25
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = call noundef ptr @_Z8criar_noiP4node(i32 noundef %47, ptr noundef %49)
  store ptr %50, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 4
  store ptr %51, ptr %53, align 8, !tbaa !21
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !16
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %61, label %65

61:                                               ; preds = %46
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 2
  store ptr %62, ptr %64, align 8, !tbaa !17
  br label %69

65:                                               ; preds = %46
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 3
  store ptr %66, ptr %68, align 8, !tbaa !18
  br label %69

69:                                               ; preds = %65, %61
  %70 = getelementptr inbounds %class.Tree, ptr %7, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.node, ptr %72, i32 0, i32 2
  store ptr %71, ptr %73, align 8, !tbaa !17
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 3
  store ptr %71, ptr %75, align 8, !tbaa !18
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4Tree12insertFix_RBEP4node(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef %76)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %77

77:                                               ; preds = %69, %13
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Tree12insertFix_RBEP4node(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #0 align 2

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

attributes #0 = { mustprogress 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 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Tree", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !10, i64 4}
!15 = !{!"_ZTS4node", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!15, !10, i64 0}
!17 = !{!15, !6, i64 8}
!18 = !{!15, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!15, !6, i64 24}


; 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z8criar_noiP4node(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Tree6insertEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !10
  %6 = icmp eq ptr %3, %5
  br i1 %6, label %7, label %.preheader

7:                                                ; preds = %2
  %8 = tail call noundef ptr @_Z8criar_noiP4node(i32 noundef %1, ptr noundef %5)
  store ptr %8, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %22

.preheader:                                       ; preds = %2, %.preheader
  %.01923 = phi ptr [ %.1, %.preheader ], [ %3, %2 ]
  %10 = load i32, ptr %.01923, align 8, !tbaa !14
  %11 = icmp sgt i32 %10, %1
  %.1.in.v = select i1 %11, i64 8, i64 16
  %.1.in = getelementptr inbounds i8, ptr %.01923, i64 %.1.in.v
  %.1 = load ptr, ptr %.1.in, align 8, !tbaa !15
  %.not = icmp eq ptr %.1, %5
  br i1 %.not, label %12, label %.preheader, !llvm.loop !16

12:                                               ; preds = %.preheader
  %13 = tail call noundef ptr @_Z8criar_noiP4node(i32 noundef %1, ptr noundef %5)
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %.01923, ptr %14, align 8, !tbaa !18
  %15 = load i32, ptr %13, align 8, !tbaa !14
  %16 = load i32, ptr %.01923, align 8, !tbaa !14
  %17 = icmp slt i32 %15, %16
  %. = select i1 %17, i64 8, i64 16
  %18 = getelementptr inbounds i8, ptr %.01923, i64 %.
  store ptr %13, ptr %18, align 8, !tbaa !15
  %19 = load ptr, ptr %4, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %19, ptr %20, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %19, ptr %21, align 8, !tbaa !20
  tail call void @_ZN4Tree12insertFix_RBEP4node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %13)
  br label %22

22:                                               ; preds = %12, %7
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Tree12insertFix_RBEP4node(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #0 align 2

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


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