; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/247 Division 2/Problem C (C)

; 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_ostream" = type { ptr, %"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 }

@MOD = external dso_local global i64, align 8
@dp = external dso_local global [101 x [2 x i64]], align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@_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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k, ptr noundef @d)
  store i64 1, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %104, %0
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = load i32, ptr @n, align 4, !tbaa !9
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %100, %11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = load i32, ptr @k, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = add nsw i32 %18, %19
  %21 = icmp sle i32 %20, 100
  br i1 %21, label %22, label %99

22:                                               ; preds = %17
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = load i32, ptr @d, align 4, !tbaa !9
  %25 = icmp sge i32 %23, %24
  br i1 %25, label %26, label %53

26:                                               ; preds = %22
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %28
  %30 = getelementptr inbounds [2 x i64], ptr %29, i64 0, i64 0
  %31 = load i64, ptr %30, align 16, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %35
  %37 = getelementptr inbounds [2 x i64], ptr %36, i64 0, i64 1
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %31
  store i64 %39, ptr %37, align 8, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %41
  %43 = getelementptr inbounds [2 x i64], ptr %42, i64 0, i64 1
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %48
  %50 = getelementptr inbounds [2 x i64], ptr %49, i64 0, i64 1
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = add nsw i64 %51, %44
  store i64 %52, ptr %50, align 8, !tbaa !5
  br label %80

53:                                               ; preds = %22
  %54 = load i32, ptr %2, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %55
  %57 = getelementptr inbounds [2 x i64], ptr %56, i64 0, i64 1
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %2, align 4, !tbaa !9
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %62
  %64 = getelementptr inbounds [2 x i64], ptr %63, i64 0, i64 1
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = add nsw i64 %65, %58
  store i64 %66, ptr %64, align 8, !tbaa !5
  %67 = load i32, ptr %2, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %68
  %70 = getelementptr inbounds [2 x i64], ptr %69, i64 0, i64 0
  %71 = load i64, ptr %70, align 16, !tbaa !5
  %72 = load i32, ptr %2, align 4, !tbaa !9
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %75
  %77 = getelementptr inbounds [2 x i64], ptr %76, i64 0, i64 0
  %78 = load i64, ptr %77, align 16, !tbaa !5
  %79 = add nsw i64 %78, %71
  store i64 %79, ptr %77, align 16, !tbaa !5
  br label %80

80:                                               ; preds = %53, %26
  %81 = load i64, ptr @MOD, align 8, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !9
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = add nsw i32 %82, %83
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %85
  %87 = getelementptr inbounds [2 x i64], ptr %86, i64 0, i64 0
  %88 = load i64, ptr %87, align 16, !tbaa !5
  %89 = srem i64 %88, %81
  store i64 %89, ptr %87, align 16, !tbaa !5
  %90 = load i64, ptr @MOD, align 8, !tbaa !5
  %91 = load i32, ptr %2, align 4, !tbaa !9
  %92 = load i32, ptr %4, align 4, !tbaa !9
  %93 = add nsw i32 %91, %92
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %94
  %96 = getelementptr inbounds [2 x i64], ptr %95, i64 0, i64 1
  %97 = load i64, ptr %96, align 8, !tbaa !5
  %98 = srem i64 %97, %90
  store i64 %98, ptr %96, align 8, !tbaa !5
  br label %99

99:                                               ; preds = %80, %17
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %4, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !11

103:                                              ; preds = %16
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %2, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %2, align 4, !tbaa !9
  br label %6, !llvm.loop !13

107:                                              ; preds = %10
  %108 = load i32, ptr @n, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %109
  %111 = getelementptr inbounds [2 x i64], ptr %110, i64 0, i64 1
  %112 = load i64, ptr %111, align 8, !tbaa !5
  %113 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %112)
  %114 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %113, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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

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

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

; 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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #4

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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_ostream" = type { ptr, %"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 }

@MOD = external dso_local local_unnamed_addr global i64, align 8
@dp = external dso_local local_unnamed_addr global [101 x [2 x i64]], align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@_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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k, ptr noundef nonnull @d)
  store i64 1, ptr @dp, align 16, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %.not30 = icmp slt i32 %2, 0
  br i1 %.not30, label %._crit_edge32, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %0
  %3 = load i32, ptr @k, align 4, !tbaa !9
  %.not2628 = icmp slt i32 %3, 1
  %4 = load i64, ptr @MOD, align 8
  br i1 %.not2628, label %._crit_edge32, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %5 = load i32, ptr @d, align 4
  %6 = sext i32 %5 to i64
  %7 = add nuw i32 %3, 1
  %8 = add nuw i32 %2, 1
  %wide.trip.count38 = zext i32 %8 to i64
  %wide.trip.count = zext i32 %7 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv35 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next36, %._crit_edge ]
  %9 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %indvars.iv35
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  br label %16

._crit_edge32:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %0
  %11 = sext i32 %2 to i64
  %12 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %11, i64 1
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %13)
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

._crit_edge:                                      ; preds = %43
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge32, label %.preheader, !llvm.loop !11

16:                                               ; preds = %.preheader, %43
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %43 ]
  %17 = add nuw nsw i64 %indvars.iv, %indvars.iv35
  %18 = icmp ult i64 %17, 101
  br i1 %18, label %19, label %43

19:                                               ; preds = %16
  %.not27 = icmp slt i64 %indvars.iv, %6
  br i1 %.not27, label %27, label %20

20:                                               ; preds = %19
  %21 = load i64, ptr %9, align 16, !tbaa !5
  %22 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %17, i64 1
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = add nsw i64 %23, %21
  %25 = load i64, ptr %10, align 8, !tbaa !5
  %26 = add nsw i64 %25, %24
  %.phi.trans.insert = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %17
  %.pre = load i64, ptr %.phi.trans.insert, align 16, !tbaa !5
  br label %36

27:                                               ; preds = %19
  %28 = load i64, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %17
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = add nsw i64 %31, %28
  %33 = load i64, ptr %9, align 16, !tbaa !5
  %34 = load i64, ptr %29, align 16, !tbaa !5
  %35 = add nsw i64 %34, %33
  br label %36

36:                                               ; preds = %27, %20
  %37 = phi i64 [ %32, %27 ], [ %26, %20 ]
  %38 = phi i64 [ %35, %27 ], [ %.pre, %20 ]
  %39 = getelementptr inbounds [101 x [2 x i64]], ptr @dp, i64 0, i64 %17
  %40 = srem i64 %38, %4
  store i64 %40, ptr %39, align 16, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %39, i64 8
  %42 = srem i64 %37, %4
  store i64 %42, ptr %41, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %16, %36
  %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 %16, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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 #2 align 2

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

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

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


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