; LLVM IR from reyadussalahin/problem-solving :: data_structure/segment_tree/codeforces/F558E (Solution)

; 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 { [28 x i32] }

@t = external dso_local global [400400 x %struct.Node], align 16
@sw = external dso_local global [400400 x i32], 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @split(ptr noundef byval(%struct.Node) align 8, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @lazy(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = sdiv i32 %10, 2
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = and i32 %15, 1
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %36

18:                                               ; preds = %3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = mul nsw i32 2, %22
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = mul nsw i32 2, %27
  %29 = add nsw i32 %28, 2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %30
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sub nsw i32 %32, %33
  %35 = add nsw i32 %34, 1
  call void @split(ptr noundef byval(%struct.Node) align 8 %21, ptr noundef %26, ptr noundef %31, i32 noundef %35)
  br label %53

36:                                               ; preds = %3
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = mul nsw i32 2, %40
  %42 = add nsw i32 %41, 2
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %43
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = mul nsw i32 2, %45
  %47 = add nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sub nsw i32 %50, %51
  call void @split(ptr noundef byval(%struct.Node) align 8 %39, ptr noundef %44, ptr noundef %49, i32 noundef %52)
  br label %53

53:                                               ; preds = %36, %18
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = mul nsw i32 2, %58
  %60 = add nsw i32 %59, 2
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %61
  store i32 %57, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = mul nsw i32 2, %63
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %66
  store i32 %57, ptr %67, align 4, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %69
  store i32 0, ptr %70, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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 { [28 x i32] }

@t = external dso_local global [400400 x %struct.Node], align 16
@sw = external dso_local local_unnamed_addr global [400400 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @split(ptr noundef byval(%struct.Node) align 8, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @lazy(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add nsw i32 %2, %1
  %5 = sdiv i32 %4, 2
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = and i32 %8, 1
  %.not = icmp eq i32 %9, 0
  %10 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %6
  %11 = shl nsw i32 %0, 1
  br i1 %.not, label %20, label %12

12:                                               ; preds = %3
  %13 = or disjoint i32 %11, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %14
  %16 = add nsw i32 %11, 2
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %17
  %reass.sub = sub i32 %5, %1
  %19 = add i32 %reass.sub, 1
  tail call void @split(ptr noundef nonnull byval(%struct.Node) align 8 %10, ptr noundef nonnull %15, ptr noundef nonnull %18, i32 noundef %19)
  br label %28

20:                                               ; preds = %3
  %21 = add nsw i32 %11, 2
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %22
  %24 = or disjoint i32 %11, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %25
  %27 = sub nsw i32 %2, %5
  tail call void @split(ptr noundef nonnull byval(%struct.Node) align 8 %10, ptr noundef nonnull %23, ptr noundef nonnull %26, i32 noundef %27)
  br label %28

28:                                               ; preds = %20, %12
  %.pre-phi20 = phi i64 [ %25, %20 ], [ %14, %12 ]
  %.pre-phi18 = phi i64 [ %22, %20 ], [ %17, %12 ]
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %.pre-phi18
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %.pre-phi20
  store i32 %29, ptr %31, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  ret void
}

attributes #0 = { 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/C++ TBAA"}


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