; LLVM IR from pranjalwalia/Competitive-programming :: spoj/dquery.ll (Z6getsumxiiii)

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

@nodo = external dso_local global [1000000 x %struct.nodost], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z5merge6nodostS_(i32, i32) #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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; 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 i32 @_Z6getsumxiiii(i64 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #3 {
  %6 = alloca %struct.nodost, align 4
  %7 = alloca i64, align 8
  %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.nodost, align 4
  %15 = alloca %struct.nodost, align 4
  %16 = alloca %struct.nodost, align 4
  %17 = alloca %struct.nodost, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %28

21:                                               ; preds = %5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %27, i64 4, i1 false), !tbaa.struct !11
  br label %87

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

36:                                               ; preds = %28
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = mul nsw i64 2, %37
  %39 = add nsw i64 %38, 1
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = call i32 @_Z6getsumxiiii(i64 noundef %39, i32 noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  %46 = getelementptr inbounds %struct.nodost, ptr %6, i32 0, i32 0
  store i32 %45, ptr %46, align 4
  store i32 1, ptr %13, align 4
  br label %86

47:                                               ; preds = %28
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = icmp sle i32 %48, %49
  br i1 %50, label %51, label %60

51:                                               ; preds = %47
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = mul nsw i64 2, %52
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = load i32, ptr %12, align 4, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = call i32 @_Z6getsumxiiii(i64 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57)
  %59 = getelementptr inbounds %struct.nodost, ptr %6, i32 0, i32 0
  store i32 %58, ptr %59, align 4
  store i32 1, ptr %13, align 4
  br label %86

60:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %61 = load i64, ptr %7, align 8, !tbaa !5
  %62 = mul nsw i64 2, %61
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = call i32 @_Z6getsumxiiii(i64 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  %68 = getelementptr inbounds %struct.nodost, ptr %14, i32 0, i32 0
  store i32 %67, ptr %68, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %69 = load i64, ptr %7, align 8, !tbaa !5
  %70 = mul nsw i64 2, %69
  %71 = add nsw i64 %70, 1
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %12, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = call i32 @_Z6getsumxiiii(i64 noundef %71, i32 noundef %73, i32 noundef %74, i32 noundef %76, i32 noundef %77)
  %79 = getelementptr inbounds %struct.nodost, ptr %15, i32 0, i32 0
  store i32 %78, ptr %79, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %14, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %15, i64 4, i1 false), !tbaa.struct !11
  %80 = getelementptr inbounds %struct.nodost, ptr %16, i32 0, i32 0
  %81 = load i32, ptr %80, align 4
  %82 = getelementptr inbounds %struct.nodost, ptr %17, i32 0, i32 0
  %83 = load i32, ptr %82, align 4
  %84 = call i32 @_Z5merge6nodostS_(i32 %81, i32 %83)
  %85 = getelementptr inbounds %struct.nodost, ptr %6, i32 0, i32 0
  store i32 %84, ptr %85, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %86

86:                                               ; preds = %60, %51, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %87

87:                                               ; preds = %86, %25
  %88 = getelementptr inbounds %struct.nodost, ptr %6, i32 0, i32 0
  %89 = load i32, ptr %88, align 4
  ret i32 %89
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9}


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

@nodo = external dso_local local_unnamed_addr global [1000000 x %struct.nodost], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z5merge6nodostS_(i32, i32) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @_Z6getsumxiiii(i64 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %1, %3
  %7 = icmp eq i32 %2, %4
  %or.cond4967 = and i1 %6, %7
  br i1 %or.cond4967, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %8 = phi i1 [ %24, %tailrecurse.outer ], [ %6, %5 ]
  %.tr40.ph70 = phi i32 [ %.us-phi54, %tailrecurse.outer ], [ %2, %5 ]
  %.tr39.ph69 = phi i32 [ %23, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph68 = phi i64 [ %22, %tailrecurse.outer ], [ %0, %5 ]
  br i1 %8, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %9 = add i32 %.tr40.ph70, %.tr39.ph69
  %10 = sdiv i32 %9, 2
  %11 = icmp slt i32 %10, %3
  br i1 %11, label %tailrecurse.outer, label %.lr.ph63.preheader

.lr.ph63.preheader:                               ; preds = %.lr.ph.split.us
  %.not.us135 = icmp slt i32 %10, %4
  br i1 %.not.us135, label %.split56.us, label %tailrecurse.us

.lr.ph63:                                         ; preds = %tailrecurse.us
  %.not.us = icmp slt i32 %15, %4
  br i1 %.not.us, label %.split56.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph63.preheader, %.lr.ph63
  %.tr50.us62136 = phi i64 [ %13, %.lr.ph63 ], [ %.tr.ph68, %.lr.ph63.preheader ]
  %12 = phi i32 [ %15, %.lr.ph63 ], [ %10, %.lr.ph63.preheader ]
  %13 = shl nsw i64 %.tr50.us62136, 1
  %14 = add i32 %12, %.tr39.ph69
  %15 = sdiv i32 %14, 2
  %16 = icmp slt i32 %15, %3
  br i1 %16, label %tailrecurse.outer, label %.lr.ph63

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.lcssa = phi i64 [ %0, %5 ], [ %27, %tailrecurse ], [ %22, %tailrecurse.outer ]
  %17 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %.tr.lcssa
  %.sroa.034.0.copyload = load i32, ptr %17, align 4, !tbaa !5
  br label %common.ret206

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4051 = phi i32 [ %19, %tailrecurse ], [ %.tr40.ph70, %.lr.ph ]
  %.tr50 = phi i64 [ %27, %tailrecurse ], [ %.tr.ph68, %.lr.ph ]
  %18 = add i32 %.tr4051, %.tr39.ph69
  %19 = sdiv i32 %18, 2
  %20 = icmp slt i32 %19, %3
  br i1 %20, label %tailrecurse.outer, label %26

tailrecurse.outer:                                ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %10, %.lr.ph.split.us ], [ %19, %.lr.ph.split ], [ %15, %tailrecurse.us ]
  %.us-phi53 = phi i64 [ %.tr.ph68, %.lr.ph.split.us ], [ %.tr50, %.lr.ph.split ], [ %13, %tailrecurse.us ]
  %.us-phi54 = phi i32 [ %.tr40.ph70, %.lr.ph.split.us ], [ %.tr4051, %.lr.ph.split ], [ %12, %tailrecurse.us ]
  %21 = shl nsw i64 %.us-phi53, 1
  %22 = or disjoint i64 %21, 1
  %23 = add nsw i32 %.us-phi, 1
  %24 = icmp eq i32 %23, %3
  %25 = icmp eq i32 %.us-phi54, %4
  %or.cond49 = and i1 %24, %25
  br i1 %or.cond49, label %tailrecurse.outer._crit_edge, label %.lr.ph

26:                                               ; preds = %.lr.ph.split
  %.not = icmp slt i32 %19, %4
  br i1 %.not, label %.split56.us, label %tailrecurse

tailrecurse:                                      ; preds = %26
  %27 = shl nsw i64 %.tr50, 1
  %28 = icmp eq i32 %19, %4
  br i1 %28, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

common.ret206:                                    ; preds = %.split56.us, %tailrecurse.outer._crit_edge
  %common.ret206.op = phi i32 [ %.sroa.034.0.copyload, %tailrecurse.outer._crit_edge ], [ %34, %.split56.us ]
  ret i32 %common.ret206.op

.split56.us:                                      ; preds = %.lr.ph63.preheader, %.lr.ph63, %26
  %.us-phi58 = phi i32 [ %19, %26 ], [ %15, %.lr.ph63 ], [ %10, %.lr.ph63.preheader ]
  %.us-phi59 = phi i64 [ %.tr50, %26 ], [ %13, %.lr.ph63 ], [ %.tr.ph68, %.lr.ph63.preheader ]
  %.us-phi60 = phi i32 [ %.tr4051, %26 ], [ %12, %.lr.ph63 ], [ %.tr40.ph70, %.lr.ph63.preheader ]
  %29 = shl nsw i64 %.us-phi59, 1
  %30 = tail call i32 @_Z6getsumxiiii(i64 noundef %29, i32 noundef %.tr39.ph69, i32 noundef %.us-phi58, i32 noundef %3, i32 noundef %.us-phi58)
  %31 = or disjoint i64 %29, 1
  %32 = add nsw i32 %.us-phi58, 1
  %33 = tail call i32 @_Z6getsumxiiii(i64 noundef %31, i32 noundef %32, i32 noundef %.us-phi60, i32 noundef %32, i32 noundef %4)
  %34 = tail call i32 @_Z5merge6nodostS_(i32 %30, i32 %33)
  br label %common.ret206
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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