; LLVM IR from hanzohasashi33/Competetive_programming :: HackerEarth/Segment Trees (Zeros_And_Ones)

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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5buildPii(ptr noundef, i32 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %2)
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = call ptr @llvm.stacksave.p0()
  store ptr %15, ptr %3, align 8
  %16 = alloca i32, i64 %14, align 16
  store i64 %14, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %26, %0
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %29

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %16, i64 %24
  store i32 1, ptr %25, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %22
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !9

29:                                               ; preds = %21
  %30 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z5buildPii(ptr noundef %16, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %6)
  br label %32

32:                                               ; preds = %79, %29
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %82

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %7)
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %40 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %8)
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6updatePiiii(ptr noundef %16, i32 noundef %42, i32 noundef 0, i32 noundef %43)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %79

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

46:                                               ; preds = %68, %44
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %71

50:                                               ; preds = %46
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %16, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %56, label %67

56:                                               ; preds = %50
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %10, align 4, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = icmp eq i32 %59, %60
  br i1 %61, label %62, label %66

62:                                               ; preds = %56
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %64)
  br label %71

66:                                               ; preds = %56
  br label %67

67:                                               ; preds = %66, %50
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %11, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %11, align 4, !tbaa !5
  br label %46, !llvm.loop !11

71:                                               ; preds = %62, %46
  %72 = load i32, ptr %11, align 4, !tbaa !5
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = icmp eq i32 %72, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %71
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %77

77:                                               ; preds = %75, %71
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %79

79:                                               ; preds = %77, %39
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %32, !llvm.loop !12

82:                                               ; preds = %32
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %83 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %83)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

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 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #5 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

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

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

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

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %1)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = call ptr @llvm.stacksave.p0()
  %10 = alloca i32, i64 %8, align 16
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %11 to i64
  %min.iters.check = icmp ult i32 %11, 8
  br i1 %min.iters.check, label %.lr.ph.preheader37, label %vector.ph

.lr.ph.preheader37:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds i32, ptr %10, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %13, align 16, !tbaa !5
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %14, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader37

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %0
  call void @_Z5buildPii(ptr noundef nonnull %10, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %2)
  %.pr = load i32, ptr %2, align 4, !tbaa !5
  %17 = icmp sgt i32 %.pr, 0
  br i1 %17, label %.lr.ph24, label %._crit_edge25

.lr.ph:                                           ; preds = %.lr.ph.preheader37, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader37 ]
  %18 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  store i32 1, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

.lr.ph24:                                         ; preds = %._crit_edge, %49
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %3)
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %.lr.ph24
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %4)
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  %26 = load i32, ptr %1, align 4, !tbaa !5
  call void @_Z6updatePiiii(ptr noundef nonnull %10, i32 noundef %25, i32 noundef 0, i32 noundef %26)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  br label %49

27:                                               ; preds = %.lr.ph24
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %5)
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph21, label %.loopexit

.lr.ph21:                                         ; preds = %27
  %31 = load i32, ptr %5, align 4
  %wide.trip.count31 = zext nneg i32 %29 to i64
  br label %32

32:                                               ; preds = %.lr.ph21, %43
  %indvars.iv28 = phi i64 [ 0, %.lr.ph21 ], [ %indvars.iv.next29, %43 ]
  %.01118 = phi i32 [ 0, %.lr.ph21 ], [ %.1, %43 ]
  %33 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv28
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %43

36:                                               ; preds = %32
  %37 = add nsw i32 %.01118, 1
  %38 = icmp eq i32 %37, %31
  br i1 %38, label %39, label %43

39:                                               ; preds = %36
  %40 = trunc nuw nsw i64 %indvars.iv28 to i32
  %41 = add nuw nsw i32 %40, 1
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %41)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %.loopexit

43:                                               ; preds = %32, %36
  %.1 = phi i32 [ %37, %36 ], [ %.01118, %32 ]
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count31
  br i1 %exitcond32.not, label %.loopexit.thread, label %32, !llvm.loop !14

.loopexit:                                        ; preds = %27, %39
  %44 = phi i32 [ %.pre, %39 ], [ %29, %27 ]
  %.016 = phi i32 [ %40, %39 ], [ 0, %27 ]
  %45 = icmp eq i32 %.016, %44
  br i1 %45, label %.loopexit.thread, label %47

.loopexit.thread:                                 ; preds = %43, %.loopexit
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %47

47:                                               ; preds = %.loopexit.thread, %.loopexit
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  br label %49

49:                                               ; preds = %47, %22
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  %52 = icmp sgt i32 %50, 1
  br i1 %52, label %.lr.ph24, label %._crit_edge25, !llvm.loop !15

._crit_edge25:                                    ; preds = %49, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.stackrestore.p0(ptr %9)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  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 nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #4 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #5 = { 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++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass