; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Codeforces Round #818 (Div. 2)/C. Madoka and Formal Statement.ll (Z5solvev)

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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %16 = load i64, ptr %1, align 8, !tbaa !5
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %2, align 8
  %18 = alloca i64, i64 %16, align 16
  store i64 %16, ptr %3, align 8
  %19 = load i64, ptr %1, align 8, !tbaa !5
  %20 = alloca i64, i64 %19, align 16
  store i64 %19, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr %18, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = mul nuw i64 8, %16
  %24 = udiv i64 %23, 8
  %25 = getelementptr inbounds i64, ptr %22, i64 %24
  store ptr %25, ptr %7, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %35, %0
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = icmp ne ptr %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %38

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %32, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %35

35:                                               ; preds = %31
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds i64, ptr %36, i32 1
  store ptr %37, ptr %6, align 8, !tbaa !9
  br label %26

38:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store ptr %20, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %39, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = mul nuw i64 8, %19
  %42 = udiv i64 %41, 8
  %43 = getelementptr inbounds i64, ptr %40, i64 %42
  store ptr %43, ptr %11, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %53, %38
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load ptr, ptr %11, align 8, !tbaa !9
  %47 = icmp ne ptr %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %56

49:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %50, ptr %12, align 8, !tbaa !9
  %51 = load ptr, ptr %12, align 8, !tbaa !9
  %52 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %53

53:                                               ; preds = %49
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = getelementptr inbounds i64, ptr %54, i32 1
  store ptr %55, ptr %10, align 8, !tbaa !9
  br label %44

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  store i8 1, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %96, %56
  %58 = load i64, ptr %14, align 8, !tbaa !5
  %59 = load i64, ptr %1, align 8, !tbaa !5
  %60 = icmp slt i64 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %99

62:                                               ; preds = %57
  %63 = load i64, ptr %14, align 8, !tbaa !5
  %64 = getelementptr inbounds i64, ptr %18, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = load i64, ptr %14, align 8, !tbaa !5
  %67 = getelementptr inbounds i64, ptr %20, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = icmp sgt i64 %65, %68
  br i1 %69, label %70, label %71

70:                                               ; preds = %62
  store i8 0, ptr %13, align 1, !tbaa !11
  br label %95

71:                                               ; preds = %62
  %72 = load i64, ptr %14, align 8, !tbaa !5
  %73 = getelementptr inbounds i64, ptr %18, i64 %72
  %74 = load i64, ptr %73, align 8, !tbaa !5
  %75 = load i64, ptr %14, align 8, !tbaa !5
  %76 = getelementptr inbounds i64, ptr %20, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !5
  %78 = icmp eq i64 %74, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %71
  br label %96

80:                                               ; preds = %71
  %81 = load i64, ptr %14, align 8, !tbaa !5
  %82 = add nsw i64 %81, 1
  %83 = load i64, ptr %1, align 8, !tbaa !5
  %84 = srem i64 %82, %83
  %85 = getelementptr inbounds i64, ptr %20, i64 %84
  %86 = load i64, ptr %85, align 8, !tbaa !5
  %87 = load i64, ptr %14, align 8, !tbaa !5
  %88 = getelementptr inbounds i64, ptr %20, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !5
  %90 = sub nsw i64 %86, %89
  %91 = icmp slt i64 %90, -1
  br i1 %91, label %92, label %93

92:                                               ; preds = %80
  store i8 0, ptr %13, align 1, !tbaa !11
  br label %93

93:                                               ; preds = %92, %80
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94, %70
  br label %96

96:                                               ; preds = %95, %79
  %97 = load i64, ptr %14, align 8, !tbaa !5
  %98 = add nsw i64 %97, 1
  store i64 %98, ptr %14, align 8, !tbaa !5
  br label %57, !llvm.loop !13

99:                                               ; preds = %61
  %100 = load i8, ptr %13, align 1, !tbaa !11, !range !15, !noundef !16
  %101 = trunc i8 %100 to i1
  %102 = zext i1 %101 to i64
  %103 = select i1 %101, ptr @.str, ptr @.str.1
  %104 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef %103)
  %105 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %104, ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  %106 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %106)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

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

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i8 0, i8 2}
!16 = !{}


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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %2 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call ptr @llvm.stacksave.p0()
  %5 = alloca i64, i64 %3, align 16
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = alloca i64, i64 %6, align 16
  %8 = getelementptr inbounds i64, ptr %5, i64 %3
  %.not30 = icmp eq i64 %3, 0
  br i1 %.not30, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %9 = getelementptr inbounds i64, ptr %7, i64 %6
  %.not2932 = icmp eq i64 %6, 0
  br i1 %.not2932, label %.preheader, label %.lr.ph35

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.02431 = phi ptr [ %11, %.lr.ph ], [ %5, %0 ]
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %.02431)
  %11 = getelementptr inbounds i8, ptr %.02431, i64 8
  %.not = icmp eq ptr %11, %8
  br i1 %.not, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph35, %._crit_edge
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph38, label %._crit_edge39

.lr.ph35:                                         ; preds = %._crit_edge, %.lr.ph35
  %.02533 = phi ptr [ %15, %.lr.ph35 ], [ %7, %._crit_edge ]
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %.02533)
  %15 = getelementptr inbounds i8, ptr %.02533, i64 8
  %.not29 = icmp eq ptr %15, %9
  br i1 %.not29, label %.preheader, label %.lr.ph35

._crit_edge39.loopexit:                           ; preds = %33
  %16 = select i1 %.1, ptr @.str, ptr @.str.1
  br label %._crit_edge39

._crit_edge39:                                    ; preds = %._crit_edge39.loopexit, %.preheader
  %.023.lcssa = phi ptr [ @.str, %.preheader ], [ %16, %._crit_edge39.loopexit ]
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull %.023.lcssa)
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull @.str.2)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret void

.lr.ph38:                                         ; preds = %.preheader, %33
  %.037 = phi i64 [ %34, %33 ], [ 0, %.preheader ]
  %.02336 = phi i1 [ %.1, %33 ], [ true, %.preheader ]
  %19 = getelementptr inbounds i64, ptr %5, i64 %.037
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i64, ptr %7, i64 %.037
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i64 %20, %22
  br i1 %23, label %33, label %24

24:                                               ; preds = %.lr.ph38
  %25 = icmp eq i64 %20, %22
  br i1 %25, label %33, label %26

26:                                               ; preds = %24
  %27 = add nuw nsw i64 %.037, 1
  %28 = icmp eq i64 %27, %12
  %iv.rem = select i1 %28, i64 0, i64 %27
  %29 = getelementptr inbounds i64, ptr %7, i64 %iv.rem
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = sub nsw i64 %30, %22
  %32 = icmp sgt i64 %31, -2
  %spec.select = select i1 %32, i1 %.02336, i1 false
  br label %33

33:                                               ; preds = %26, %.lr.ph38, %24
  %.1 = phi i1 [ %.02336, %24 ], [ false, %.lr.ph38 ], [ %spec.select, %26 ]
  %34 = add nuw nsw i64 %.037, 1
  %exitcond.not = icmp eq i64 %34, %12
  br i1 %exitcond.not, label %._crit_edge39.loopexit, label %.lr.ph38, !llvm.loop !9
}

; 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 uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERl(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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