; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2019-20/Jan/Bronze (race)

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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@K = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@X = external dso_local global i64, align 8

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #2 align 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 i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %7 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %8 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %10
  %12 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %11, ptr noundef null)
  call void @_ZN5input2reIxJxEEEvRT_DpRT0_(ptr noundef nonnull align 8 dereferenceable(8) @K, ptr noundef nonnull align 8 dereferenceable(8) @N)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %13

13:                                               ; preds = %51, %0
  %14 = load i32, ptr %2, align 4, !tbaa !8
  %15 = sext i32 %14 to i64
  %16 = load i64, ptr @N, align 8, !tbaa !11
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %13
  call void @_ZN5input2reIxEEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @X)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 1, ptr %6, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %46, %19
  %21 = load i64, ptr %6, align 8, !tbaa !11
  %22 = load i64, ptr %4, align 8, !tbaa !11
  %23 = add nsw i64 %22, %21
  store i64 %23, ptr %4, align 8, !tbaa !11
  %24 = load i64, ptr %5, align 8, !tbaa !11
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %5, align 8, !tbaa !11
  %26 = load i64, ptr %4, align 8, !tbaa !11
  %27 = load i64, ptr @K, align 8, !tbaa !11
  %28 = icmp sge i64 %26, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  store i32 5, ptr %3, align 4
  br label %49

30:                                               ; preds = %20
  %31 = load i64, ptr %6, align 8, !tbaa !11
  %32 = load i64, ptr @X, align 8, !tbaa !11
  %33 = icmp sge i64 %31, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %30
  %35 = load i64, ptr %6, align 8, !tbaa !11
  %36 = load i64, ptr %4, align 8, !tbaa !11
  %37 = add nsw i64 %36, %35
  store i64 %37, ptr %4, align 8, !tbaa !11
  %38 = load i64, ptr %5, align 8, !tbaa !11
  %39 = add nsw i64 %38, 1
  store i64 %39, ptr %5, align 8, !tbaa !11
  %40 = load i64, ptr %4, align 8, !tbaa !11
  %41 = load i64, ptr @K, align 8, !tbaa !11
  %42 = icmp sge i64 %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %34
  store i32 5, ptr %3, align 4
  br label %49

44:                                               ; preds = %34
  br label %45

45:                                               ; preds = %44, %30
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %6, align 8, !tbaa !11
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %6, align 8, !tbaa !11
  br label %20, !llvm.loop !13

49:                                               ; preds = %43, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %50

50:                                               ; preds = %49
  call void @_ZN6output2psIxJEEEvRKT_DpRKT0_(ptr noundef nonnull align 8 dereferenceable(8) %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %2, align 4, !tbaa !8
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %2, align 4, !tbaa !8
  br label %13, !llvm.loop !15

54:                                               ; preds = %18
  %55 = load i32, ptr %1, align 4
  ret i32 %55
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5input2reIxJxEEEvRT_DpRT0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5input2reIxEEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6output2psIxJEEEvRKT_DpRKT0_(ptr noundef nonnull align 8 dereferenceable(8)) #4

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


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

@_ZSt3cin = external global %"class.std::basic_istream", align 8
@K = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@X = external dso_local global i64, align 8

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

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i64, align 8
  %2 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %3 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %4 = getelementptr i8, ptr %3, i64 -24
  %5 = load i64, ptr %4, align 8
  %6 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %5
  %7 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %6, ptr noundef null)
  tail call void @_ZN5input2reIxJxEEEvRT_DpRT0_(ptr noundef nonnull align 8 dereferenceable(8) @K, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %8 = load i64, ptr @N, align 8, !tbaa !8
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph23, label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge, %0
  ret i32 0

.lr.ph23:                                         ; preds = %0, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %0 ]
  call void @_ZN5input2reIxEEvRT_(ptr noundef nonnull align 8 dereferenceable(8) @X)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %10 = load i64, ptr @K, align 8, !tbaa !8
  %.not17 = icmp sgt i64 %10, 1
  br i1 %.not17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph23
  %11 = load i64, ptr @X, align 8, !tbaa !8
  br label %12

12:                                               ; preds = %.lr.ph, %19
  %13 = phi i64 [ 1, %.lr.ph ], [ %23, %19 ]
  %14 = phi i64 [ 1, %.lr.ph ], [ %22, %19 ]
  %.018 = phi i64 [ 1, %.lr.ph ], [ %21, %19 ]
  %15 = phi i64 [ 0, %.lr.ph ], [ %20, %19 ]
  %.not15 = icmp slt i64 %.018, %11
  br i1 %.not15, label %19, label %16

16:                                               ; preds = %12
  %17 = add nsw i64 %14, %.018
  %18 = add nsw i64 %15, 2
  %.not16 = icmp slt i64 %17, %10
  br i1 %.not16, label %19, label %._crit_edge

19:                                               ; preds = %12, %16
  %20 = phi i64 [ %18, %16 ], [ %13, %12 ]
  %.1 = phi i64 [ %17, %16 ], [ %14, %12 ]
  %21 = add nuw nsw i64 %.018, 1
  %22 = add nsw i64 %21, %.1
  %23 = add nsw i64 %20, 1
  %.not = icmp slt i64 %22, %10
  br i1 %.not, label %12, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %19, %16, %.lr.ph23
  %24 = phi i64 [ 1, %.lr.ph23 ], [ %18, %16 ], [ %23, %19 ]
  store i64 %24, ptr %1, align 8, !tbaa !8
  call void @_ZN6output2psIxJEEEvRKT_DpRKT0_(ptr noundef nonnull align 8 dereferenceable(8) %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i64, ptr @N, align 8, !tbaa !8
  %26 = icmp sgt i64 %25, %indvars.iv.next
  br i1 %26, label %.lr.ph23, label %._crit_edge24, !llvm.loop !13
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5input2reIxJxEEEvRT_DpRT0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5input2reIxEEvRT_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6output2psIxJEEEvRKT_DpRKT0_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = { 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 = !{!"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}


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