; LLVM IR from manishbisht/Competitive-Programming :: Codeforces/Codeforces Round #355 (Div. 2) (Vanya and Food Processor)

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

@n = external dso_local global i64, align 8
@h = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@s = external dso_local global i64, align 8
@i = external dso_local global i64, align 8
@temp = external dso_local global i64, align 8
@l = external dso_local global i64, align 8
@r = external dso_local global i64, align 8
@_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
  store i32 0, ptr %1, align 4
  %2 = 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)
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(8) @h)
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(8) @k)
  store i64 0, ptr @s, align 8, !tbaa !5
  store i64 0, ptr @l, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %36, %0
  %6 = load i64, ptr @i, align 8, !tbaa !5
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = icmp slt i64 %6, %7
  br i1 %8, label %9, label %39

9:                                                ; preds = %5
  %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) @temp)
  %11 = load i64, ptr @l, align 8, !tbaa !5
  %12 = load i64, ptr @temp, align 8, !tbaa !5
  %13 = add nsw i64 %11, %12
  %14 = load i64, ptr @h, align 8, !tbaa !5
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %9
  %17 = load i64, ptr @temp, align 8, !tbaa !5
  %18 = load i64, ptr @l, align 8, !tbaa !5
  %19 = add nsw i64 %18, %17
  store i64 %19, ptr @l, align 8, !tbaa !5
  br label %24

20:                                               ; preds = %9
  %21 = load i64, ptr @s, align 8, !tbaa !5
  %22 = add nsw i64 %21, 1
  store i64 %22, ptr @s, align 8, !tbaa !5
  %23 = load i64, ptr @temp, align 8, !tbaa !5
  store i64 %23, ptr @l, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %20, %16
  %25 = load i64, ptr @l, align 8, !tbaa !5
  %26 = load i64, ptr @k, align 8, !tbaa !5
  %27 = sdiv i64 %25, %26
  store i64 %27, ptr @r, align 8, !tbaa !5
  %28 = load i64, ptr @s, align 8, !tbaa !5
  %29 = load i64, ptr @r, align 8, !tbaa !5
  %30 = add nsw i64 %28, %29
  store i64 %30, ptr @s, align 8, !tbaa !5
  %31 = load i64, ptr @r, align 8, !tbaa !5
  %32 = load i64, ptr @k, align 8, !tbaa !5
  %33 = mul nsw i64 %31, %32
  %34 = load i64, ptr @l, align 8, !tbaa !5
  %35 = sub nsw i64 %34, %33
  store i64 %35, ptr @l, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %24
  %37 = load i64, ptr @i, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr @i, align 8, !tbaa !5
  br label %5, !llvm.loop !9

39:                                               ; preds = %5
  %40 = load i64, ptr @l, align 8, !tbaa !5
  %41 = icmp sgt i64 %40, 0
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load i64, ptr @s, align 8, !tbaa !5
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr @s, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42, %39
  %46 = load i64, ptr @s, align 8, !tbaa !5
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %46)
  %48 = load i32, ptr %1, align 4
  ret i32 %48
}

; 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: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@n = external dso_local global i64, align 8
@h = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@s = external dso_local local_unnamed_addr global i64, align 8
@i = external dso_local local_unnamed_addr global i64, align 8
@temp = external dso_local global i64, align 8
@l = external dso_local local_unnamed_addr global i64, align 8
@r = external dso_local local_unnamed_addr global i64, align 8
@_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 = 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) @h)
  %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)
  store i64 0, ptr @s, align 8, !tbaa !5
  store i64 0, ptr @l, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %0, %.lr.ph
  %6 = 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) @temp)
  %7 = load i64, ptr @l, align 8, !tbaa !5
  %8 = load i64, ptr @temp, align 8, !tbaa !5
  %9 = add nsw i64 %8, %7
  %10 = load i64, ptr @h, align 8, !tbaa !5
  %.not = icmp sgt i64 %9, %10
  %.pre = load i64, ptr @s, align 8, !tbaa !5
  %11 = zext i1 %.not to i64
  %spec.select = add nsw i64 %.pre, %11
  %spec.select3 = select i1 %.not, i64 %8, i64 %9
  %12 = load i64, ptr @k, align 8, !tbaa !5
  %13 = sdiv i64 %spec.select3, %12
  store i64 %13, ptr @r, align 8, !tbaa !5
  %14 = add nsw i64 %spec.select, %13
  store i64 %14, ptr @s, align 8, !tbaa !5
  %15 = mul nsw i64 %13, %12
  %.recomposed = srem i64 %spec.select3, %12
  store i64 %.recomposed, ptr @l, align 8, !tbaa !5
  %16 = load i64, ptr @i, align 8, !tbaa !5
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr @i, align 8, !tbaa !5
  %18 = load i64, ptr @n, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %20 = icmp sgt i64 %.recomposed, 0
  br i1 %20, label %21, label %._crit_edge.thread

21:                                               ; preds = %._crit_edge
  %22 = add nsw i64 %14, 1
  store i64 %22, ptr @s, align 8, !tbaa !5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0, %21, %._crit_edge
  %23 = phi i64 [ %22, %21 ], [ %14, %._crit_edge ], [ 0, %0 ]
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %23)
  ret i32 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)) local_unnamed_addr #1 align 2

; 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 #1 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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass