; LLVM IR from vmartinv/eldiego :: estructuras/rmq.persistent.ll (Z3getiiP4nodeii)

; 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.node = type { i32, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4operRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3getiiP4nodeii(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %27

19:                                               ; preds = %5
  %20 = load i32, ptr %11, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.node, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  store i32 %26, ptr %6, align 4
  br label %77

27:                                               ; preds = %19, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  %31 = ashr i32 %30, 1
  store i32 %31, ptr %12, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %12, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %27
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !5
  %43 = call noundef i32 @_Z3getiiP4nodeii(i32 noundef %36, i32 noundef %37, ptr noundef %40, i32 noundef %41, i32 noundef %42)
  store i32 %43, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

44:                                               ; preds = %27
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = icmp sge i32 %45, %46
  br i1 %47, label %48, label %57

48:                                               ; preds = %44
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = call noundef i32 @_Z3getiiP4nodeii(i32 noundef %49, i32 noundef %50, ptr noundef %53, i32 noundef %54, i32 noundef %55)
  store i32 %56, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %76

57:                                               ; preds = %44
  br label %58

58:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %12, align 4, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = call noundef i32 @_Z3getiiP4nodeii(i32 noundef %59, i32 noundef %60, ptr noundef %63, i32 noundef %64, i32 noundef %65)
  store i32 %66, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.node, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = call noundef i32 @_Z3getiiP4nodeii(i32 noundef %67, i32 noundef %68, ptr noundef %71, i32 noundef %72, i32 noundef %73)
  store i32 %74, ptr %15, align 4, !tbaa !5
  %75 = call noundef i32 @_Z4operRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  store i32 %75, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  store i32 1, ptr %13, align 4
  br label %76

76:                                               ; preds = %58, %48, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %77

77:                                               ; preds = %76, %23
  %78 = load i32, ptr %6, align 4
  ret i32 %78
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}


; 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 i32 @_Z4operRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3getiiP4nodeii(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = icmp eq i32 %0, %3
  %9 = icmp eq i32 %4, %1
  %or.cond4556 = and i1 %8, %9
  br i1 %or.cond4556, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %10 = phi i1 [ %26, %tailrecurse.outer ], [ %8, %5 ]
  %.tr41.ph60 = phi i32 [ %.us-phi50, %tailrecurse.outer ], [ %4, %5 ]
  %.tr40.ph58 = phi i32 [ %.us-phi, %tailrecurse.outer ], [ %3, %5 ]
  %.tr39.ph57 = phi ptr [ %25, %tailrecurse.outer ], [ %2, %5 ]
  br i1 %10, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %11 = add i32 %.tr41.ph60, %.tr40.ph58
  %12 = ashr i32 %11, 1
  %.not.us51 = icmp slt i32 %12, %1
  br i1 %.not.us51, label %.split.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph.split.us, %tailrecurse.us
  %13 = phi i32 [ %17, %tailrecurse.us ], [ %12, %.lr.ph.split.us ]
  %.tr3946.us52 = phi ptr [ %15, %tailrecurse.us ], [ %.tr39.ph57, %.lr.ph.split.us ]
  %14 = getelementptr inbounds i8, ptr %.tr3946.us52, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = add i32 %13, %.tr40.ph58
  %17 = ashr i32 %16, 1
  %.not.us = icmp slt i32 %17, %1
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr39.lcssa = phi ptr [ %2, %5 ], [ %22, %tailrecurse ], [ %25, %tailrecurse.outer ]
  %18 = load i32, ptr %.tr39.lcssa, align 8, !tbaa !11
  br label %common.ret135

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4147 = phi i32 [ %20, %tailrecurse ], [ %.tr41.ph60, %.lr.ph ]
  %.tr3946 = phi ptr [ %22, %tailrecurse ], [ %.tr39.ph57, %.lr.ph ]
  %19 = add i32 %.tr4147, %.tr40.ph58
  %20 = ashr i32 %19, 1
  %.not = icmp slt i32 %20, %1
  br i1 %.not, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %21 = getelementptr inbounds i8, ptr %.tr3946, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = icmp eq i32 %20, %1
  br i1 %23, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %12, %.lr.ph.split.us ], [ %20, %.lr.ph.split ], [ %17, %tailrecurse.us ]
  %.us-phi49 = phi ptr [ %.tr39.ph57, %.lr.ph.split.us ], [ %.tr3946, %.lr.ph.split ], [ %15, %tailrecurse.us ]
  %.us-phi50 = phi i32 [ %.tr41.ph60, %.lr.ph.split.us ], [ %.tr4147, %.lr.ph.split ], [ %13, %tailrecurse.us ]
  %.not37 = icmp sgt i32 %.us-phi, %0
  br i1 %.not37, label %28, label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %.split.us
  %24 = getelementptr inbounds i8, ptr %.us-phi49, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = icmp eq i32 %.us-phi, %0
  %27 = icmp eq i32 %.us-phi50, %1
  %or.cond45 = and i1 %26, %27
  br i1 %or.cond45, label %tailrecurse.outer._crit_edge, label %.lr.ph

common.ret135:                                    ; preds = %28, %tailrecurse.outer._crit_edge
  %common.ret135.op = phi i32 [ %18, %tailrecurse.outer._crit_edge ], [ %35, %28 ]
  ret i32 %common.ret135.op

28:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %29 = getelementptr inbounds i8, ptr %.us-phi49, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = tail call noundef i32 @_Z3getiiP4nodeii(i32 noundef %0, i32 noundef %.us-phi, ptr noundef %30, i32 noundef %.tr40.ph58, i32 noundef %.us-phi)
  store i32 %31, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #2
  %32 = getelementptr inbounds i8, ptr %.us-phi49, i64 16
  %33 = load ptr, ptr %32, align 8, !tbaa !12
  %34 = tail call noundef i32 @_Z3getiiP4nodeii(i32 noundef %.us-phi, i32 noundef %1, ptr noundef %33, i32 noundef %.us-phi, i32 noundef %.us-phi50)
  store i32 %34, ptr %7, align 4, !tbaa !13
  %35 = call noundef i32 @_Z4operRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  br label %common.ret135
}

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!6 = !{!"_ZTS4node", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!7, !7, i64 0}


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