; LLVM IR from ippeb/ACM-ICPC :: data_structure/binary_indexed_tree (2d_binary_indexed_tree)

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

@tree = external dso_local global [1025 x [1025 x i32]], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@F = external dso_local global [1025 x [1025 x i32]], align 16
@S = external dso_local global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %3

3:                                                ; preds = %62, %0
  %4 = load i32, ptr @t, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !5
  %6 = icmp ne i32 %4, 0
  br i1 %6, label %7, label %64

7:                                                ; preds = %3
  call void @llvm.memset.p0.i64(ptr align 16 @tree, i8 0, i64 4202500, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @F, i8 0, i64 4202500, i1 false)
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %9

9:                                                ; preds = %61, %7
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @S)
  %11 = load i8, ptr @S, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 69
  br i1 %13, label %14, label %15

14:                                               ; preds = %9
  br label %62

15:                                               ; preds = %9
  %16 = load i8, ptr getelementptr inbounds ([4 x i8], ptr @S, i64 0, i64 2), align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 84
  br i1 %18, label %19, label %39

19:                                               ; preds = %15
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @a, ptr noundef @b, ptr noundef @c)
  %21 = load i32, ptr @a, align 4, !tbaa !5
  %22 = load i32, ptr @b, align 4, !tbaa !5
  %23 = load i32, ptr @c, align 4, !tbaa !5
  %24 = load i32, ptr @a, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1025 x [1025 x i32]], ptr @F, i64 0, i64 %25
  %27 = load i32, ptr @b, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1025 x i32], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sub nsw i32 %23, %30
  call void @_Z6updateiii(i32 noundef %21, i32 noundef %22, i32 noundef %31)
  %32 = load i32, ptr @c, align 4, !tbaa !5
  %33 = load i32, ptr @a, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1025 x [1025 x i32]], ptr @F, i64 0, i64 %34
  %36 = load i32, ptr @b, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1025 x i32], ptr %35, i64 0, i64 %37
  store i32 %32, ptr %38, align 4, !tbaa !5
  br label %61

39:                                               ; preds = %15
  %40 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.3, ptr noundef @a, ptr noundef @b, ptr noundef @c, ptr noundef @d)
  %41 = load i32, ptr @c, align 4, !tbaa !5
  %42 = load i32, ptr @d, align 4, !tbaa !5
  %43 = call noundef i32 @_Z4readii(i32 noundef %41, i32 noundef %42)
  %44 = load i32, ptr @a, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = load i32, ptr @b, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = call noundef i32 @_Z4readii(i32 noundef %45, i32 noundef %47)
  %49 = add nsw i32 %43, %48
  %50 = load i32, ptr @a, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = load i32, ptr @d, align 4, !tbaa !5
  %53 = call noundef i32 @_Z4readii(i32 noundef %51, i32 noundef %52)
  %54 = sub nsw i32 %49, %53
  %55 = load i32, ptr @c, align 4, !tbaa !5
  %56 = load i32, ptr @b, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = call noundef i32 @_Z4readii(i32 noundef %55, i32 noundef %57)
  %59 = sub nsw i32 %54, %58
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %59)
  br label %61

61:                                               ; preds = %39, %19
  br label %9, !llvm.loop !10

62:                                               ; preds = %14
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %3, !llvm.loop !12

64:                                               ; preds = %3
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @printf(ptr noundef, ...) #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 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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

@tree = external dso_local local_unnamed_addr global [1025 x [1025 x i32]], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@c = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@F = external dso_local local_unnamed_addr global [1025 x [1025 x i32]], align 16
@S = external dso_local global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not3 = icmp eq i32 %2, 0
  br i1 %.not3, label %._crit_edge6, label %.lr.ph5

.lr.ph5:                                          ; preds = %0, %._crit_edge
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4202500) @tree, i8 0, i64 4202500, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4202500) @F, i8 0, i64 4202500, i1 false)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @S)
  %6 = load i8, ptr @S, align 1, !tbaa !9
  %7 = icmp eq i8 %6, 69
  br i1 %7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph5, %47
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @S, i64 2), align 1, !tbaa !9
  %9 = icmp eq i8 %8, 84
  br i1 %9, label %10, label %26

10:                                               ; preds = %.lr.ph
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c)
  %12 = load i32, ptr @a, align 4, !tbaa !5
  %13 = load i32, ptr @b, align 4, !tbaa !5
  %14 = load i32, ptr @c, align 4, !tbaa !5
  %15 = sext i32 %12 to i64
  %16 = sext i32 %13 to i64
  %17 = getelementptr inbounds [1025 x [1025 x i32]], ptr @F, i64 0, i64 %15, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sub nsw i32 %14, %18
  tail call void @_Z6updateiii(i32 noundef %12, i32 noundef %13, i32 noundef %19)
  %20 = load i32, ptr @c, align 4, !tbaa !5
  %21 = load i32, ptr @a, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = load i32, ptr @b, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1025 x [1025 x i32]], ptr @F, i64 0, i64 %22, i64 %24
  store i32 %20, ptr %25, align 4, !tbaa !5
  br label %47

26:                                               ; preds = %.lr.ph
  %27 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.3, ptr noundef nonnull @a, ptr noundef nonnull @b, ptr noundef nonnull @c, ptr noundef nonnull @d)
  %28 = load i32, ptr @c, align 4, !tbaa !5
  %29 = load i32, ptr @d, align 4, !tbaa !5
  %30 = tail call noundef i32 @_Z4readii(i32 noundef %28, i32 noundef %29)
  %31 = load i32, ptr @a, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  %33 = load i32, ptr @b, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  %35 = tail call noundef i32 @_Z4readii(i32 noundef %32, i32 noundef %34)
  %36 = load i32, ptr @a, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  %38 = load i32, ptr @d, align 4, !tbaa !5
  %39 = tail call noundef i32 @_Z4readii(i32 noundef %37, i32 noundef %38)
  %40 = load i32, ptr @c, align 4, !tbaa !5
  %41 = load i32, ptr @b, align 4, !tbaa !5
  %42 = add nsw i32 %41, -1
  %43 = tail call noundef i32 @_Z4readii(i32 noundef %40, i32 noundef %42)
  %.neg2 = add i32 %35, %30
  %44 = add i32 %39, %43
  %45 = sub i32 %.neg2, %44
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %45)
  br label %47

47:                                               ; preds = %26, %10
  %48 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @S)
  %49 = load i8, ptr @S, align 1, !tbaa !9
  %50 = icmp eq i8 %49, 69
  br i1 %50, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %47, %.lr.ph5
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %52 = load i32, ptr @t, align 4, !tbaa !5
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %52, 0
  br i1 %.not, label %._crit_edge6, label %.lr.ph5, !llvm.loop !12

._crit_edge6:                                     ; preds = %._crit_edge, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 norecurse 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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

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


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