; LLVM IR from eyangch/competitive-programming :: Codeforces/1712 (b)

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

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@T = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@P = external dso_local global [100001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %4 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %5 = getelementptr i8, ptr %4, i64 -24
  %6 = load i64, ptr %5, align 8
  %7 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %6
  %8 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %7, ptr noundef null)
  %9 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @T)
  br label %11

11:                                               ; preds = %54, %0
  %12 = load i64, ptr @T, align 8, !tbaa !8
  %13 = add nsw i64 %12, -1
  store i64 %13, ptr @T, align 8, !tbaa !8
  %14 = icmp ne i64 %12, 0
  br i1 %14, label %15, label %56

15:                                               ; preds = %11
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  %17 = load i64, ptr @N, align 8, !tbaa !8
  store i64 %17, ptr %2, align 8, !tbaa !8
  br label %18

18:                                               ; preds = %31, %15
  %19 = load i64, ptr %2, align 8, !tbaa !8
  %20 = icmp sge i64 %19, 1
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  br label %34

22:                                               ; preds = %18
  %23 = load i64, ptr %2, align 8, !tbaa !8
  %24 = sub nsw i64 %23, 1
  %25 = load i64, ptr %2, align 8, !tbaa !8
  %26 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %25
  store i64 %24, ptr %26, align 8, !tbaa !8
  %27 = load i64, ptr %2, align 8, !tbaa !8
  %28 = load i64, ptr %2, align 8, !tbaa !8
  %29 = sub nsw i64 %28, 1
  %30 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %29
  store i64 %27, ptr %30, align 8, !tbaa !8
  br label %31

31:                                               ; preds = %22
  %32 = load i64, ptr %2, align 8, !tbaa !8
  %33 = sub nsw i64 %32, 2
  store i64 %33, ptr %2, align 8, !tbaa !8
  br label %18, !llvm.loop !11

34:                                               ; preds = %21
  %35 = load i64, ptr @N, align 8, !tbaa !8
  %36 = srem i64 %35, 2
  %37 = icmp eq i64 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i64 1, ptr getelementptr inbounds ([100001 x i64], ptr @P, i64 0, i64 1), align 8, !tbaa !8
  br label %39

39:                                               ; preds = %38, %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 1, ptr %3, align 8, !tbaa !8
  br label %40

40:                                               ; preds = %51, %39
  %41 = load i64, ptr %3, align 8, !tbaa !8
  %42 = load i64, ptr @N, align 8, !tbaa !8
  %43 = icmp sle i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  br label %54

45:                                               ; preds = %40
  %46 = load i64, ptr %3, align 8, !tbaa !8
  %47 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !8
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %48)
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %49, i8 noundef signext 32)
  br label %51

51:                                               ; preds = %45
  %52 = load i64, ptr %3, align 8, !tbaa !8
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %3, align 8, !tbaa !8
  br label %40, !llvm.loop !13

54:                                               ; preds = %44
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i8 noundef signext 10)
  br label %11, !llvm.loop !14

56:                                               ; preds = %11
  %57 = load i32, ptr %1, align 4
  ret i32 %57
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #1 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #5

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3 align 2

attributes #0 = { 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 #1 = { 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 #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 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 memory(argmem: readwrite) }
attributes #5 = { inlinehint 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 #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@T = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@P = external dso_local local_unnamed_addr global [100001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %2 = getelementptr i8, ptr %1, i64 -24
  %3 = load i64, ptr %2, align 8
  %4 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %3
  %5 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %4, ptr noundef null)
  %6 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %7 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @T)
  %8 = load i64, ptr @T, align 8, !tbaa !8
  %9 = add nsw i64 %8, -1
  store i64 %9, ptr @T, align 8, !tbaa !8
  %.not18 = icmp eq i64 %8, 0
  br i1 %.not18, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %0, %._crit_edge17
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %11 = load i64, ptr @N, align 8, !tbaa !8
  %12 = icmp sgt i64 %11, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph20
  %13 = add nsw i64 %11, -1
  %14 = lshr i64 %13, 1
  %15 = add nuw i64 %14, 1
  %xtraiter = and i64 %15, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.01012.prol = phi i64 [ %19, %.lr.ph.prol ], [ %11, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %16 = add nsw i64 %.01012.prol, -1
  %17 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %.01012.prol
  store i64 %16, ptr %17, align 8, !tbaa !8
  %18 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %16
  store i64 %.01012.prol, ptr %18, align 8, !tbaa !8
  %19 = add nsw i64 %.01012.prol, -2
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !11

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.01012.unr = phi i64 [ %11, %.lr.ph.preheader ], [ %19, %.lr.ph.prol ]
  %20 = icmp ult i64 %11, 7
  br i1 %20, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph20
  %21 = and i64 %11, -9223372036854775807
  %22 = icmp eq i64 %21, 1
  br i1 %22, label %.thread, label %40

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.01012 = phi i64 [ %38, %.lr.ph ], [ %.01012.unr, %.lr.ph.prol.loopexit ]
  %23 = add nsw i64 %.01012, -1
  %24 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %.01012
  store i64 %23, ptr %24, align 8, !tbaa !8
  %25 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %23
  store i64 %.01012, ptr %25, align 8, !tbaa !8
  %26 = add nsw i64 %.01012, -2
  %27 = add nsw i64 %.01012, -3
  %28 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %26
  store i64 %27, ptr %28, align 8, !tbaa !8
  %29 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %27
  store i64 %26, ptr %29, align 8, !tbaa !8
  %30 = add nsw i64 %.01012, -4
  %31 = add nsw i64 %.01012, -5
  %32 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %30
  store i64 %31, ptr %32, align 8, !tbaa !8
  %33 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %31
  store i64 %30, ptr %33, align 8, !tbaa !8
  %34 = add nsw i64 %.01012, -6
  %35 = add nsw i64 %.01012, -7
  %36 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %34
  store i64 %35, ptr %36, align 8, !tbaa !8
  %37 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %35
  store i64 %34, ptr %37, align 8, !tbaa !8
  %38 = add nsw i64 %.01012, -8
  %39 = icmp ugt i64 %34, 2
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !13

.thread:                                          ; preds = %._crit_edge
  store i64 1, ptr getelementptr inbounds (i8, ptr @P, i64 8), align 8, !tbaa !8
  br label %.lr.ph16.preheader

40:                                               ; preds = %._crit_edge
  %.not1113 = icmp slt i64 %11, 1
  br i1 %.not1113, label %._crit_edge17, label %.lr.ph16.preheader

.lr.ph16.preheader:                               ; preds = %.thread, %40
  br label %.lr.ph16

._crit_edge17:                                    ; preds = %.lr.ph16, %40
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i8 noundef signext 10)
  %42 = load i64, ptr @T, align 8, !tbaa !8
  %43 = add nsw i64 %42, -1
  store i64 %43, ptr @T, align 8, !tbaa !8
  %.not = icmp eq i64 %42, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !15

.lr.ph16:                                         ; preds = %.lr.ph16.preheader, %.lr.ph16
  %.014 = phi i64 [ %48, %.lr.ph16 ], [ 1, %.lr.ph16.preheader ]
  %44 = getelementptr inbounds [100001 x i64], ptr @P, i64 0, i64 %.014
  %45 = load i64, ptr %44, align 8, !tbaa !8
  %46 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %45)
  %47 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %46, i8 noundef signext 32)
  %48 = add nuw nsw i64 %.014, 1
  %49 = load i64, ptr @N, align 8, !tbaa !8
  %.not11.not = icmp slt i64 %.014, %49
  br i1 %.not11.not, label %.lr.ph16, label %._crit_edge17, !llvm.loop !16

._crit_edge21:                                    ; preds = %._crit_edge17, %0
  ret i32 0
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #1 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #3 align 2

attributes #0 = { 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 #1 = { 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 #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 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 = { inlinehint 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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