; 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
@a = external dso_local global [100100 x i8], align 16
@sw = external dso_local global [400400 x i32], align 16
@flag = external dso_local global [400400 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; 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 @lazy(i32 noundef, i32 noundef, i32 noundef) #1

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @show(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %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
  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
  store i32 %3, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [400400 x i32], ptr @flag, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = or i32 %14, %13
  store i32 %15, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %34

19:                                               ; preds = %4
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %29, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100100 x i8], ptr @a, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %27)
  br label %33

29:                                               ; preds = %19
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %31
  call void @show_char(ptr noundef byval(%struct.Node) align 8 %32)
  br label %33

33:                                               ; preds = %29, %22
  br label %62

34:                                               ; preds = %4
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %34
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  call void @lazy(i32 noundef %41, i32 noundef %42, i32 noundef %43)
  br label %44

44:                                               ; preds = %40, %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sdiv i32 %47, 2
  store i32 %48, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = mul nsw i32 2, %49
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  call void @show(i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = mul nsw i32 2, %55
  %57 = add nsw i32 %56, 2
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  call void @show(i32 noundef %57, i32 noundef %59, i32 noundef %60, i32 noundef %61)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %62

62:                                               ; preds = %44, %33
  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 = { "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/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; 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
@a = external dso_local local_unnamed_addr global [100100 x i8], align 16
@sw = external dso_local local_unnamed_addr global [400400 x i32], align 16
@flag = external dso_local local_unnamed_addr global [400400 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @lazy(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @show(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [400400 x i32], ptr @flag, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = or i32 %7, %3
  %9 = icmp eq i32 %1, %2
  br i1 %9, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.tr23.lcssa = phi i32 [ %1, %4 ], [ %2, %tailrecurse ]
  %.lcssa26 = phi i64 [ %5, %4 ], [ %29, %tailrecurse ]
  %.lcssa = phi i32 [ %8, %4 ], [ %32, %tailrecurse ]
  %.not22 = icmp eq i32 %.lcssa, 0
  br i1 %.not22, label %10, label %16

10:                                               ; preds = %tailrecurse._crit_edge
  %11 = sext i32 %.tr23.lcssa to i64
  %12 = getelementptr inbounds [100100 x i8], ptr @a, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %14)
  br label %34

16:                                               ; preds = %tailrecurse._crit_edge
  %17 = getelementptr inbounds [400400 x %struct.Node], ptr @t, i64 0, i64 %.lcssa26
  tail call void @show_char(ptr noundef nonnull byval(%struct.Node) align 8 %17)
  br label %34

.lr.ph:                                           ; preds = %4, %tailrecurse
  %18 = phi i32 [ %32, %tailrecurse ], [ %8, %4 ]
  %19 = phi i64 [ %29, %tailrecurse ], [ %5, %4 ]
  %.tr2328 = phi i32 [ %28, %tailrecurse ], [ %1, %4 ]
  %.tr27 = phi i32 [ %27, %tailrecurse ], [ %0, %4 ]
  %20 = getelementptr inbounds [400400 x i32], ptr @sw, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %tailrecurse, label %22

22:                                               ; preds = %.lr.ph
  tail call void @lazy(i32 noundef %.tr27, i32 noundef %.tr2328, i32 noundef %2)
  br label %tailrecurse

tailrecurse:                                      ; preds = %22, %.lr.ph
  %23 = add nsw i32 %.tr2328, %2
  %24 = sdiv i32 %23, 2
  %25 = shl nsw i32 %.tr27, 1
  %26 = or disjoint i32 %25, 1
  tail call void @show(i32 noundef %26, i32 noundef %.tr2328, i32 noundef %24, i32 noundef %18)
  %27 = add nsw i32 %25, 2
  %28 = add nsw i32 %24, 1
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [400400 x i32], ptr @flag, i64 0, i64 %29
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = or i32 %31, %18
  %33 = icmp eq i32 %28, %2
  br i1 %33, label %tailrecurse._crit_edge, label %.lr.ph

34:                                               ; preds = %10, %16
  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" }
attributes #1 = { nofree nounwind "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"}
!9 = !{!7, !7, i64 0}


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