; LLVM IR from manishbisht/Competitive-Programming :: Codechef/COOK75 (Sherlock Counts Ways)

; 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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"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" }
%"struct.std::pair" = type <{ %"struct.std::_Rb_tree_const_iterator", i8, [7 x i8] }>
%"struct.std::_Rb_tree_const_iterator" = type { ptr }

@n = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@i = external dso_local global i64, align 8
@temp = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@v = external dso_local global %"class.std::set", 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
  %2 = alloca %"struct.std::pair", align 8
  store i32 0, ptr %1, align 4
  %3 = 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)
  %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 1, ptr @ans, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %16, %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 %19

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 = call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) @v, ptr noundef nonnull align 8 dereferenceable(8) @temp)
  %12 = getelementptr inbounds { ptr, i8 }, ptr %2, i32 0, i32 0
  %13 = extractvalue { ptr, i8 } %11, 0
  store ptr %13, ptr %12, align 8
  %14 = getelementptr inbounds { ptr, i8 }, ptr %2, i32 0, i32 1
  %15 = extractvalue { ptr, i8 } %11, 1
  store i8 %15, ptr %14, align 8
  br label %16

16:                                               ; preds = %9
  %17 = load i64, ptr @i, align 8, !tbaa !5
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr @i, align 8, !tbaa !5
  br label %5, !llvm.loop !9

19:                                               ; preds = %5
  %20 = call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) @v) #4
  store i64 %20, ptr @temp, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %31, %19
  %22 = load i64, ptr @i, align 8, !tbaa !5
  %23 = load i64, ptr @k, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %25, label %34

25:                                               ; preds = %21
  %26 = load i64, ptr @ans, align 8, !tbaa !5
  %27 = load i64, ptr @temp, align 8, !tbaa !5
  %28 = mul nsw i64 %26, %27
  store i64 %28, ptr @ans, align 8, !tbaa !5
  %29 = load i64, ptr @temp, align 8, !tbaa !5
  %30 = add nsw i64 %29, -1
  store i64 %30, ptr @temp, align 8, !tbaa !5
  br label %31

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

34:                                               ; preds = %21
  %35 = load i64, ptr @ans, align 8, !tbaa !5
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %35)
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %36, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  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)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 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 = { 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 = { 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 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}


; 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::set" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long long, long long, std::_Identity<long long>, std::less<long long>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"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
@k = external dso_local global i64, align 8
@i = external dso_local local_unnamed_addr global i64, align 8
@temp = external dso_local global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@v = external dso_local global %"class.std::set", 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) @k)
  store i64 1, ptr @ans, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %5 = 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)
  %6 = tail call { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48) @v, ptr noundef nonnull align 8 dereferenceable(8) @temp)
  %7 = load i64, ptr @i, align 8, !tbaa !5
  %8 = add nsw i64 %7, 1
  store i64 %8, ptr @i, align 8, !tbaa !5
  %9 = load i64, ptr @n, align 8, !tbaa !5
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %11 = tail call noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48) @v) #4
  store i64 %11, ptr @temp, align 8, !tbaa !5
  %12 = load i64, ptr @k, align 8, !tbaa !5
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph4.preheader, label %38

.lr.ph4.preheader:                                ; preds = %._crit_edge
  %xtraiter = and i64 %12, 7
  %14 = icmp ult i64 %12, 8
  br i1 %14, label %._crit_edge5.unr-lcssa, label %.lr.ph4.preheader.new

.lr.ph4.preheader.new:                            ; preds = %.lr.ph4.preheader
  %unroll_iter = and i64 %12, 9223372036854775800
  br label %.lr.ph4

.lr.ph4:                                          ; preds = %.lr.ph4, %.lr.ph4.preheader.new
  %15 = phi i64 [ %ans.promoted, %.lr.ph4.preheader.new ], [ %31, %.lr.ph4 ]
  %16 = phi i64 [ %11, %.lr.ph4.preheader.new ], [ %32, %.lr.ph4 ]
  %niter = phi i64 [ 0, %.lr.ph4.preheader.new ], [ %niter.next.7, %.lr.ph4 ]
  %17 = mul nsw i64 %16, %15
  %18 = add nsw i64 %16, -1
  %19 = mul nsw i64 %18, %17
  %20 = add nsw i64 %16, -2
  %21 = mul nsw i64 %20, %19
  %22 = add nsw i64 %16, -3
  %23 = mul nsw i64 %22, %21
  %24 = add nsw i64 %16, -4
  %25 = mul nsw i64 %24, %23
  %26 = add nsw i64 %16, -5
  %27 = mul nsw i64 %26, %25
  %28 = add nsw i64 %16, -6
  %29 = mul nsw i64 %28, %27
  %30 = add nsw i64 %16, -7
  %31 = mul nsw i64 %30, %29
  %32 = add nsw i64 %16, -8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge5.unr-lcssa, label %.lr.ph4, !llvm.loop !11

._crit_edge5.unr-lcssa:                           ; preds = %.lr.ph4, %.lr.ph4.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph4.preheader ], [ %31, %.lr.ph4 ]
  %.unr = phi i64 [ %ans.promoted, %.lr.ph4.preheader ], [ %31, %.lr.ph4 ]
  %.unr9 = phi i64 [ %11, %.lr.ph4.preheader ], [ %32, %.lr.ph4 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge5, label %.lr.ph4.epil

.lr.ph4.epil:                                     ; preds = %._crit_edge5.unr-lcssa, %.lr.ph4.epil
  %33 = phi i64 [ %35, %.lr.ph4.epil ], [ %.unr, %._crit_edge5.unr-lcssa ]
  %34 = phi i64 [ %36, %.lr.ph4.epil ], [ %.unr9, %._crit_edge5.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph4.epil ], [ 0, %._crit_edge5.unr-lcssa ]
  %35 = mul nsw i64 %34, %33
  %36 = add nsw i64 %34, -1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge5, label %.lr.ph4.epil, !llvm.loop !12

._crit_edge5:                                     ; preds = %.lr.ph4.epil, %._crit_edge5.unr-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge5.unr-lcssa ], [ %35, %.lr.ph4.epil ]
  %37 = sub i64 %11, %12
  store i64 %.lcssa, ptr @ans, align 8, !tbaa !5
  store i64 %37, ptr @temp, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %._crit_edge5, %._crit_edge
  %39 = phi i64 [ %.lcssa, %._crit_edge5 ], [ %ans.promoted, %._crit_edge ]
  %storemerge1.lcssa = phi i64 [ %12, %._crit_edge5 ], [ 0, %._crit_edge ]
  store i64 %storemerge1.lcssa, ptr @i, align 8, !tbaa !5
  %40 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %39)
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %40, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  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 dso_local { ptr, i8 } @_ZNSt3setIxSt4lessIxESaIxEE6insertERKx(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt3setIxSt4lessIxESaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 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

; 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 #1 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 = { 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 = { 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 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, !13}
!13 = !{!"llvm.loop.unroll.disable"}


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