; LLVM IR from pranjalwalia/Competitive-programming :: AtCoder/ABC/173/ABC.ll (Z1Cv)

; 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.4 = external hidden unnamed_addr constant [2 x i8], align 1
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@a = external dso_local global [7 x [7 x i8]], align 16

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

; 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)) #1 align 2

; 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) #2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4copyv() #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5colorxx(i64 noundef, i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z1Cv() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = 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)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 8 dereferenceable(8) @m)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) @k)
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %31, %0
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = icmp slt i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  br label %34

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %27, %15
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr @m, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %30

21:                                               ; preds = %16
  %22 = load i64, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds [7 x [7 x i8]], ptr @a, i64 0, i64 %22
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds [7 x i8], ptr %23, i64 0, i64 %24
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %25)
  br label %27

27:                                               ; preds = %21
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %3, align 8, !tbaa !5
  br label %16, !llvm.loop !9

30:                                               ; preds = %20
  br label %31

31:                                               ; preds = %30
  %32 = load i64, ptr %1, align 8, !tbaa !5
  %33 = add nsw i64 %32, 1
  store i64 %33, ptr %1, align 8, !tbaa !5
  br label %10, !llvm.loop !11

34:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %64, %34
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr @n, align 8, !tbaa !5
  %38 = trunc i64 %37 to i32
  %39 = shl i32 1, %38
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %36, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %35
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %67

43:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %60, %43
  %45 = load i64, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr @m, align 8, !tbaa !5
  %47 = trunc i64 %46 to i32
  %48 = shl i32 1, %47
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %45, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %44
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %63

52:                                               ; preds = %44
  call void @_Z4copyv()
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !5
  call void @_Z5colorxx(i64 noundef %53, i64 noundef %54)
  %55 = call noundef zeroext i1 @_Z5checkv()
  br i1 %55, label %56, label %59

56:                                               ; preds = %52
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %4, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %56, %52
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %6, align 8, !tbaa !5
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %6, align 8, !tbaa !5
  br label %44, !llvm.loop !12

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63
  %65 = load i64, ptr %5, align 8, !tbaa !5
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %5, align 8, !tbaa !5
  br label %35, !llvm.loop !13

67:                                               ; preds = %42
  %68 = load i64, ptr %4, align 8, !tbaa !5
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %68)
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %69, ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  ret void
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { "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 = { 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 long", !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}
!13 = distinct !{!13, !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"

%"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.4 = external hidden unnamed_addr constant [2 x i8], align 1
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@a = external dso_local global [7 x [7 x i8]], align 16

; 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 #0 align 2

; 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 #1

; 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 #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4copyv() local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5colorxx(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z1Cv() local_unnamed_addr #0 {
  %1 = 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)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @m)
  %3 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(8) @k)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  %6 = load i64, ptr @m, align 8
  %7 = icmp sgt i64 %6, 0
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %.preheader19, label %.preheader18

.preheader19:                                     ; preds = %0, %._crit_edge
  %8 = phi i64 [ %13, %._crit_edge ], [ %4, %0 ]
  %9 = phi i64 [ %14, %._crit_edge ], [ %6, %0 ]
  %.01721 = phi i64 [ %15, %._crit_edge ], [ 0, %0 ]
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.preheader18:                                     ; preds = %._crit_edge, %0
  %11 = phi i64 [ %4, %0 ], [ %13, %._crit_edge ]
  %12 = and i64 %11, 4294967295
  %.not = icmp eq i64 %12, 31
  br i1 %.not, label %._crit_edge28, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader18
  %.pre32 = load i64, ptr @m, align 8, !tbaa !5
  br label %.preheader

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr @n, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader19
  %13 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %8, %.preheader19 ]
  %14 = phi i64 [ %20, %._crit_edge.loopexit ], [ %9, %.preheader19 ]
  %15 = add nuw nsw i64 %.01721, 1
  %16 = icmp slt i64 %15, %13
  br i1 %16, label %.preheader19, label %.preheader18, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader19, %.lr.ph
  %.01620 = phi i64 [ %19, %.lr.ph ], [ 0, %.preheader19 ]
  %17 = getelementptr inbounds [7 x [7 x i8]], ptr @a, i64 0, i64 %.01721, i64 %.01620
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 1 dereferenceable(1) %17)
  %19 = add nuw nsw i64 %.01620, 1
  %20 = load i64, ptr @m, align 8, !tbaa !5
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge25
  %22 = phi i64 [ %27, %._crit_edge25 ], [ %11, %.preheader.preheader ]
  %23 = phi i64 [ %28, %._crit_edge25 ], [ %.pre32, %.preheader.preheader ]
  %.01427 = phi i64 [ %29, %._crit_edge25 ], [ 0, %.preheader.preheader ]
  %.01526 = phi i64 [ %.1.lcssa, %._crit_edge25 ], [ 0, %.preheader.preheader ]
  %24 = and i64 %23, 4294967295
  %.not30 = icmp eq i64 %24, 31
  br i1 %.not30, label %._crit_edge25, label %.lr.ph24

._crit_edge28:                                    ; preds = %._crit_edge25, %.preheader18
  %.015.lcssa = phi i64 [ 0, %.preheader18 ], [ %.1.lcssa, %._crit_edge25 ]
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.015.lcssa)
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %25, ptr noundef nonnull @.str.4)
  ret void

._crit_edge25.loopexit:                           ; preds = %.lr.ph24
  %.pre33 = load i64, ptr @n, align 8, !tbaa !5
  br label %._crit_edge25

._crit_edge25:                                    ; preds = %._crit_edge25.loopexit, %.preheader
  %27 = phi i64 [ %22, %.preheader ], [ %.pre33, %._crit_edge25.loopexit ]
  %28 = phi i64 [ %23, %.preheader ], [ %37, %._crit_edge25.loopexit ]
  %.1.lcssa = phi i64 [ %.01526, %.preheader ], [ %spec.select, %._crit_edge25.loopexit ]
  %29 = add nuw nsw i64 %.01427, 1
  %30 = trunc i64 %27 to i32
  %31 = shl nuw i32 1, %30
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %29, %32
  br i1 %33, label %.preheader, label %._crit_edge28, !llvm.loop !13

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %.023 = phi i64 [ %36, %.lr.ph24 ], [ 0, %.preheader ]
  %.122 = phi i64 [ %spec.select, %.lr.ph24 ], [ %.01526, %.preheader ]
  tail call void @_Z4copyv()
  tail call void @_Z5colorxx(i64 noundef %.01427, i64 noundef %.023)
  %34 = tail call noundef zeroext i1 @_Z5checkv()
  %35 = zext i1 %34 to i64
  %spec.select = add nsw i64 %.122, %35
  %36 = add nuw nsw i64 %.023, 1
  %37 = load i64, ptr @m, align 8, !tbaa !5
  %38 = trunc i64 %37 to i32
  %39 = shl nuw i32 1, %38
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %36, %40
  br i1 %41, label %.lr.ph24, label %._crit_edge25.loopexit, !llvm.loop !14
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_RS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #3

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass