; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Company Contests/Indeed Prime/tree.ll (Z6query2iiiii)

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

@tree2 = external dso_local global [262144 x %struct.node2], align 16

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5node25mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(40), ptr noundef nonnull align 4 dereferenceable(40), ptr noundef nonnull align 4 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6query2iiiii(ptr dead_on_unwind noalias writable sret(%struct.node2) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %struct.node2, align 4
  %15 = alloca %struct.node2, align 4
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  store i32 %5, ptr %11, align 4, !tbaa !5
  %16 = load i32, ptr %8, 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 = %6
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [262144 x %struct.node2], ptr @tree2, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %26, i64 40, i1 false), !tbaa.struct !9
  br label %72

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

35:                                               ; preds = %27
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = mul nsw i32 2, %36
  %38 = add nsw i32 %37, 1
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z6query2iiiii(ptr dead_on_unwind writable sret(%struct.node2) align 4 %0, i32 noundef %38, i32 noundef %40, i32 noundef %41, i32 noundef %42, i32 noundef %43)
  store i32 1, ptr %13, align 4
  br label %71

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

48:                                               ; preds = %44
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = mul nsw i32 2, %49
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z6query2iiiii(ptr dead_on_unwind writable sret(%struct.node2) align 4 %0, i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 1, ptr %13, align 4
  br label %71

55:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 40, ptr %14) #4
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = mul nsw i32 2, %56
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z6query2iiiii(ptr dead_on_unwind writable sret(%struct.node2) align 4 %14, i32 noundef %57, i32 noundef %58, i32 noundef %59, i32 noundef %60, i32 noundef %61)
  call void @llvm.lifetime.start.p0(i64 40, ptr %15) #4
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = mul nsw i32 2, %62
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z6query2iiiii(ptr dead_on_unwind writable sret(%struct.node2) align 4 %15, i32 noundef %64, i32 noundef %66, i32 noundef %67, i32 noundef %69, i32 noundef %70)
  call void @_ZN5node25mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(40) %0, ptr noundef nonnull align 4 dereferenceable(40) %14, ptr noundef nonnull align 4 dereferenceable(40) %15)
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 40, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %14) #4
  br label %71

71:                                               ; preds = %55, %48, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %72

72:                                               ; preds = %71, %23
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 4, !5, i64 28, i64 4, !5, i64 32, i64 4, !5, i64 36, i64 4, !5}


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

%struct.node2 = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@tree2 = external dso_local local_unnamed_addr global [262144 x %struct.node2], align 16

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5node25mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(40), ptr noundef nonnull align 4 dereferenceable(40), ptr noundef nonnull align 4 dereferenceable(40)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6query2iiiii(ptr dead_on_unwind noalias writable sret(%struct.node2) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = alloca %struct.node2, align 4
  %8 = alloca %struct.node2, align 4
  %9 = icmp eq i32 %2, %4
  %10 = icmp eq i32 %3, %5
  %or.cond4664 = and i1 %9, %10
  br i1 %or.cond4664, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %tailrecurse.outer
  %11 = phi i1 [ %28, %tailrecurse.outer ], [ %9, %6 ]
  %.tr37.ph67 = phi i32 [ %.us-phi51, %tailrecurse.outer ], [ %3, %6 ]
  %.tr36.ph66 = phi i32 [ %27, %tailrecurse.outer ], [ %2, %6 ]
  %.tr35.ph65 = phi i32 [ %26, %tailrecurse.outer ], [ %1, %6 ]
  br i1 %11, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %12 = add i32 %.tr37.ph67, %.tr36.ph66
  %13 = sdiv i32 %12, 2
  %14 = icmp slt i32 %13, %4
  br i1 %14, label %tailrecurse.outer, label %.lr.ph60.preheader

.lr.ph60.preheader:                               ; preds = %.lr.ph.split.us
  %.not.us132 = icmp slt i32 %13, %5
  br i1 %.not.us132, label %.split53.us, label %tailrecurse.us

.lr.ph60:                                         ; preds = %tailrecurse.us
  %.not.us = icmp slt i32 %18, %5
  br i1 %.not.us, label %.split53.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph60.preheader, %.lr.ph60
  %.tr3547.us59133 = phi i32 [ %16, %.lr.ph60 ], [ %.tr35.ph65, %.lr.ph60.preheader ]
  %15 = phi i32 [ %18, %.lr.ph60 ], [ %13, %.lr.ph60.preheader ]
  %16 = shl nsw i32 %.tr3547.us59133, 1
  %17 = add i32 %15, %.tr36.ph66
  %18 = sdiv i32 %17, 2
  %19 = icmp slt i32 %18, %4
  br i1 %19, label %tailrecurse.outer, label %.lr.ph60

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %6
  %.tr35.lcssa = phi i32 [ %1, %6 ], [ %31, %tailrecurse ], [ %26, %tailrecurse.outer ]
  %20 = sext i32 %.tr35.lcssa to i64
  %21 = getelementptr inbounds [262144 x %struct.node2], ptr @tree2, i64 0, i64 %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %21, i64 40, i1 false), !tbaa.struct !5
  br label %36

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3748 = phi i32 [ %23, %tailrecurse ], [ %.tr37.ph67, %.lr.ph ]
  %.tr3547 = phi i32 [ %31, %tailrecurse ], [ %.tr35.ph65, %.lr.ph ]
  %22 = add i32 %.tr3748, %.tr36.ph66
  %23 = sdiv i32 %22, 2
  %24 = icmp slt i32 %23, %4
  br i1 %24, label %tailrecurse.outer, label %30

tailrecurse.outer:                                ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %13, %.lr.ph.split.us ], [ %23, %.lr.ph.split ], [ %18, %tailrecurse.us ]
  %.us-phi50 = phi i32 [ %.tr35.ph65, %.lr.ph.split.us ], [ %.tr3547, %.lr.ph.split ], [ %16, %tailrecurse.us ]
  %.us-phi51 = phi i32 [ %.tr37.ph67, %.lr.ph.split.us ], [ %.tr3748, %.lr.ph.split ], [ %15, %tailrecurse.us ]
  %25 = shl nsw i32 %.us-phi50, 1
  %26 = or disjoint i32 %25, 1
  %27 = add nsw i32 %.us-phi, 1
  %28 = icmp eq i32 %27, %4
  %29 = icmp eq i32 %.us-phi51, %5
  %or.cond46 = and i1 %28, %29
  br i1 %or.cond46, label %tailrecurse.outer._crit_edge, label %.lr.ph

30:                                               ; preds = %.lr.ph.split
  %.not = icmp slt i32 %23, %5
  br i1 %.not, label %.split53.us, label %tailrecurse

tailrecurse:                                      ; preds = %30
  %31 = shl nsw i32 %.tr3547, 1
  %32 = icmp eq i32 %23, %5
  br i1 %32, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split53.us:                                      ; preds = %.lr.ph60.preheader, %.lr.ph60, %30
  %.us-phi55 = phi i32 [ %23, %30 ], [ %18, %.lr.ph60 ], [ %13, %.lr.ph60.preheader ]
  %.us-phi56 = phi i32 [ %.tr3547, %30 ], [ %16, %.lr.ph60 ], [ %.tr35.ph65, %.lr.ph60.preheader ]
  %.us-phi57 = phi i32 [ %.tr3748, %30 ], [ %15, %.lr.ph60 ], [ %.tr37.ph67, %.lr.ph60.preheader ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %7) #3
  %33 = shl nsw i32 %.us-phi56, 1
  call void @_Z6query2iiiii(ptr dead_on_unwind nonnull writable sret(%struct.node2) align 4 %7, i32 noundef %33, i32 noundef %.tr36.ph66, i32 noundef %.us-phi55, i32 noundef %4, i32 noundef %.us-phi55)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %8) #3
  %34 = or disjoint i32 %33, 1
  %35 = add nsw i32 %.us-phi55, 1
  call void @_Z6query2iiiii(ptr dead_on_unwind nonnull writable sret(%struct.node2) align 4 %8, i32 noundef %34, i32 noundef %35, i32 noundef %.us-phi57, i32 noundef %35, i32 noundef %5)
  call void @_ZN5node25mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(40) %0, ptr noundef nonnull align 4 dereferenceable(40) %7, ptr noundef nonnull align 4 dereferenceable(40) %8)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %7) #3
  br label %36

36:                                               ; preds = %.split53.us, %tailrecurse.outer._crit_edge
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 4, !6, i64 20, i64 4, !6, i64 24, i64 4, !6, i64 28, i64 4, !6, i64 32, i64 4, !6, i64 36, i64 4, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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