; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan/654.ll (Z5queryiii)

; 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, i32, i32, i32 }

@tr = external dso_local global [800040 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #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 { i64, i64 } @_Z5queryiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca %struct.Node, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.Node, align 4
  %11 = alloca %struct.Node, align 4
  %12 = alloca %struct.Node, align 4
  %13 = alloca %struct.Node, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.Node, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 16, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp sge i32 %18, %19
  br i1 %20, label %21, label %33

21:                                               ; preds = %3
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %21
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 16 %32, i64 16, i1 false), !tbaa.struct !12
  br label %95

33:                                               ; preds = %21, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 16, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = add nsw i32 %38, %43
  %45 = ashr i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %49, label %59

49:                                               ; preds = %33
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = shl i32 %50, 1
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = call { i64, i64 } @_Z5queryiii(i32 noundef %51, i32 noundef %52, i32 noundef %53)
  %55 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  %56 = extractvalue { i64, i64 } %54, 0
  store i64 %56, ptr %55, align 4
  %57 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  %58 = extractvalue { i64, i64 } %54, 1
  store i64 %58, ptr %57, align 4
  store i32 1, ptr %9, align 4
  br label %94

59:                                               ; preds = %33
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = icmp sgt i32 %60, %61
  br i1 %62, label %63, label %74

63:                                               ; preds = %59
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = shl i32 %64, 1
  %66 = or i32 %65, 1
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = call { i64, i64 } @_Z5queryiii(i32 noundef %66, i32 noundef %67, i32 noundef %68)
  %70 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  %71 = extractvalue { i64, i64 } %69, 0
  store i64 %71, ptr %70, align 4
  %72 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  %73 = extractvalue { i64, i64 } %69, 1
  store i64 %73, ptr %72, align 4
  store i32 1, ptr %9, align 4
  br label %94

74:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = shl i32 %75, 1
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = call { i64, i64 } @_Z5queryiii(i32 noundef %76, i32 noundef %77, i32 noundef %78)
  %80 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %81 = extractvalue { i64, i64 } %79, 0
  store i64 %81, ptr %80, align 4
  %82 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %83 = extractvalue { i64, i64 } %79, 1
  store i64 %83, ptr %82, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %12, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = shl i32 %84, 1
  %86 = or i32 %85, 1
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = call { i64, i64 } @_Z5queryiii(i32 noundef %86, i32 noundef %87, i32 noundef %88)
  %90 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %91 = extractvalue { i64, i64 } %89, 0
  store i64 %91, ptr %90, align 4
  %92 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %93 = extractvalue { i64, i64 } %89, 1
  store i64 %93, ptr %92, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %13, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  call void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(16) %10, ptr noundef nonnull align 4 dereferenceable(16) %11)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  br label %94

94:                                               ; preds = %74, %63, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %95

95:                                               ; preds = %94, %29
  %96 = load { i64, i64 }, ptr %4, align 4
  ret { i64, i64 } %96
}

; 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) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, 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.Node = type { i32, i32, i32, i32 }

@tr = external dso_local local_unnamed_addr global [800040 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) 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 { i64, i64 } @_Z5queryiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Node, align 8
  %5 = alloca %struct.Node, align 8
  %6 = alloca %struct.Node, align 8
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [800040 x %struct.Node], ptr @tr, i64 0, i64 %7
  %9 = load i32, ptr %8, align 16, !tbaa !5
  %.not = icmp slt i32 %9, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %8, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  %.not28 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not28
  br i1 %or.cond, label %._crit_edge, label %10

10:                                               ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %8, i64 16, i1 false), !tbaa.struct !11
  br label %37

._crit_edge:                                      ; preds = %3
  %11 = add nsw i32 %.pre, %9
  %12 = ashr i32 %11, 1
  %.not29 = icmp slt i32 %12, %2
  br i1 %.not29, label %19, label %13

13:                                               ; preds = %._crit_edge
  %14 = shl i32 %0, 1
  %15 = tail call { i64, i64 } @_Z5queryiii(i32 noundef %14, i32 noundef %1, i32 noundef %2)
  %16 = extractvalue { i64, i64 } %15, 0
  store i64 %16, ptr %4, align 8
  %17 = getelementptr inbounds i8, ptr %4, i64 8
  %18 = extractvalue { i64, i64 } %15, 1
  store i64 %18, ptr %17, align 8
  br label %37

19:                                               ; preds = %._crit_edge
  %20 = icmp slt i32 %12, %1
  br i1 %20, label %21, label %28

21:                                               ; preds = %19
  %22 = shl i32 %0, 1
  %23 = or disjoint i32 %22, 1
  %24 = tail call { i64, i64 } @_Z5queryiii(i32 noundef %23, i32 noundef %1, i32 noundef %2)
  %25 = extractvalue { i64, i64 } %24, 0
  store i64 %25, ptr %4, align 8
  %26 = getelementptr inbounds i8, ptr %4, i64 8
  %27 = extractvalue { i64, i64 } %24, 1
  store i64 %27, ptr %26, align 8
  br label %37

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %29 = shl i32 %0, 1
  %30 = tail call { i64, i64 } @_Z5queryiii(i32 noundef %29, i32 noundef %1, i32 noundef %2)
  %31 = extractvalue { i64, i64 } %30, 0
  %32 = extractvalue { i64, i64 } %30, 1
  store i64 %31, ptr %5, align 8
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %32, ptr %.sroa.42.0..sroa_idx, align 8
  %33 = or disjoint i32 %29, 1
  %34 = tail call { i64, i64 } @_Z5queryiii(i32 noundef %33, i32 noundef %1, i32 noundef %2)
  %35 = extractvalue { i64, i64 } %34, 0
  %36 = extractvalue { i64, i64 } %34, 1
  store i64 %35, ptr %6, align 8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %36, ptr %.sroa.4.0..sroa_idx, align 8
  call void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 4 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  br label %37

37:                                               ; preds = %13, %21, %28, %10
  %.fca.0.load = load i64, ptr %4, align 8
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %4, i64 8
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { i64, i64 } %.fca.1.insert
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass