; LLVM IR from ADJA/algos :: DataStructures (ImplicitSegmentTree)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@val = external dso_local global i32, align 4
@c = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addP4Nodeiiiix(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #0

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; 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
declare dso_local noundef i64 @_Z3getP4Nodeiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #5 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #7
  %7 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #8
  invoke void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7)
          to label %8 unwind label %15

8:                                                ; preds = %0
  store ptr %7, ptr %2, align 8, !tbaa !5
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %28, %8
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr @n, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %19, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %31

15:                                               ; preds = %0
  %16 = landingpad { ptr, i32 }
          cleanup
  %17 = extractvalue { ptr, i32 } %16, 0
  store ptr %17, ptr %3, align 8
  %18 = extractvalue { ptr, i32 } %16, 1
  store i32 %18, ptr %4, align 4
  call void @_ZdlPvm(ptr noundef %7, i64 noundef 24) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  br label %68

19:                                               ; preds = %10
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 1
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = load i32, ptr @x, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  call void @_Z3addP4Nodeiiiix(ptr noundef %21, i32 noundef 0, i32 noundef %23, i32 noundef %24, i32 noundef %25, i64 noundef %27)
  br label %28

28:                                               ; preds = %19
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %10, !llvm.loop !11

31:                                               ; preds = %14
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %64, %31
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr @m, align 4, !tbaa !9
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %67

38:                                               ; preds = %33
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @c)
  %40 = load i8, ptr @c, align 1, !tbaa !13
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 %41, 97
  br i1 %42, label %43, label %54

43:                                               ; preds = %38
  %44 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @x, ptr noundef @y, ptr noundef @val)
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load i32, ptr @n, align 4, !tbaa !9
  %47 = sub nsw i32 %46, 1
  %48 = load i32, ptr @x, align 4, !tbaa !9
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr @x, align 4, !tbaa !9
  %50 = load i32, ptr @y, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @y, align 4, !tbaa !9
  %52 = load i32, ptr @val, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  call void @_Z3addP4Nodeiiiix(ptr noundef %45, i32 noundef 0, i32 noundef %47, i32 noundef %49, i32 noundef %51, i64 noundef %53)
  br label %63

54:                                               ; preds = %38
  %55 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1
  %59 = load i32, ptr @x, align 4, !tbaa !9
  %60 = add nsw i32 %59, -1
  store i32 %60, ptr @x, align 4, !tbaa !9
  %61 = call noundef i64 @_Z3getP4Nodeiii(ptr noundef %56, i32 noundef 0, i32 noundef %58, i32 noundef %60)
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %61)
  br label %63

63:                                               ; preds = %54, %43
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !9
  br label %33, !llvm.loop !14

67:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #7
  ret i32 0

68:                                               ; preds = %15
  %69 = load ptr, ptr %3, align 8
  %70 = load i32, ptr %4, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #6

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 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 #4 = { nobuiltin 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" }
attributes #5 = { mustprogress norecurse 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 #6 = { "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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@val = external dso_local global i32, align 4
@c = external dso_local global i8, align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addP4Nodeiiiix(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3getP4Nodeiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %1 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #5
  tail call void @_ZN4NodeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m)
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph12, label %._crit_edge13

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.089 = phi i32 [ %13, %.lr.ph ], [ 0, %0 ]
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  %11 = load i32, ptr @x, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  tail call void @_Z3addP4Nodeiiiix(ptr noundef nonnull %1, i32 noundef 0, i32 noundef %10, i32 noundef %.089, i32 noundef %.089, i64 noundef %12)
  %13 = add nuw nsw i32 %.089, 1
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge13:                                    ; preds = %37, %._crit_edge
  ret i32 0

.lr.ph12:                                         ; preds = %._crit_edge, %37
  %.010 = phi i32 [ %38, %37 ], [ 0, %._crit_edge ]
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @c)
  %17 = load i8, ptr @c, align 1, !tbaa !11
  %18 = icmp eq i8 %17, 97
  br i1 %18, label %19, label %29

19:                                               ; preds = %.lr.ph12
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @x, ptr noundef nonnull @y, ptr noundef nonnull @val)
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  %23 = load i32, ptr @x, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr @x, align 4, !tbaa !5
  %25 = load i32, ptr @y, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr @y, align 4, !tbaa !5
  %27 = load i32, ptr @val, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  tail call void @_Z3addP4Nodeiiiix(ptr noundef nonnull %1, i32 noundef 0, i32 noundef %22, i32 noundef %24, i32 noundef %26, i64 noundef %28)
  br label %37

29:                                               ; preds = %.lr.ph12
  %30 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  %33 = load i32, ptr @x, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr @x, align 4, !tbaa !5
  %35 = tail call noundef i64 @_Z3getP4Nodeiii(ptr noundef nonnull %1, i32 noundef 0, i32 noundef %32, i32 noundef %34)
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %35)
  br label %37

37:                                               ; preds = %19, %29
  %38 = add nuw nsw i32 %.010, 1
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %.lr.ph12, label %._crit_edge13, !llvm.loop !12
}

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

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

attributes #0 = { 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 #1 = { nobuiltin allocsize(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 = { 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 norecurse 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 = { 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" }
attributes #5 = { builtin allocsize(0) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass