; LLVM IR from manishbisht/Competitive-Programming :: Codeforces/Codeforces Round #354 (Div. 2) (Nicholas and Permutation)

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

@a = external dso_local global [100 x i64], align 16
@n = external dso_local global i64, align 8
@i = external dso_local global i64, align 8
@b = external dso_local global i64, align 8
@c = 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)
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %11, %0
  %4 = load i64, ptr @i, align 8, !tbaa !5
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp slt i64 %4, %5
  br i1 %6, label %7, label %14

7:                                                ; preds = %3
  %8 = load i64, ptr @i, align 8, !tbaa !5
  %9 = getelementptr inbounds [100 x i64], ptr @a, i64 0, i64 %8
  %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) %9)
  br label %11

11:                                               ; preds = %7
  %12 = load i64, ptr @i, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr @i, align 8, !tbaa !5
  br label %3, !llvm.loop !9

14:                                               ; preds = %3
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = getelementptr inbounds i64, ptr @a, i64 %15
  %17 = call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %16)
  %18 = load i64, ptr @n, align 8, !tbaa !5
  %19 = getelementptr inbounds i64, ptr @a, i64 %18
  %20 = call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %19)
  %21 = ptrtoint ptr %17 to i64
  %22 = ptrtoint ptr %20 to i64
  %23 = sub i64 %21, %22
  %24 = sdiv exact i64 %23, 8
  %25 = call noundef i64 @_ZSt3absl(i64 noundef %24)
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = sub nsw i64 %26, 1
  %28 = icmp eq i64 %25, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %14
  %30 = load i64, ptr @n, align 8, !tbaa !5
  %31 = sub nsw i64 %30, 1
  %32 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %31)
  store i32 0, ptr %1, align 4
  br label %91

33:                                               ; preds = %14
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = getelementptr inbounds i64, ptr @a, i64 %34
  %36 = call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %35)
  %37 = load i64, ptr @n, align 8, !tbaa !5
  %38 = getelementptr inbounds i64, ptr @a, i64 %37
  %39 = call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %38)
  %40 = ptrtoint ptr %36 to i64
  %41 = ptrtoint ptr %39 to i64
  %42 = sub i64 %40, %41
  %43 = sdiv exact i64 %42, 8
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %62

45:                                               ; preds = %33
  %46 = load i64, ptr @n, align 8, !tbaa !5
  %47 = sub nsw i64 %46, 1
  %48 = getelementptr inbounds [100 x i64], ptr @a, i64 0, i64 %47
  %49 = load i64, ptr @n, align 8, !tbaa !5
  %50 = getelementptr inbounds i64, ptr @a, i64 %49
  %51 = call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %50)
  %52 = ptrtoint ptr %48 to i64
  %53 = ptrtoint ptr %51 to i64
  %54 = sub i64 %52, %53
  %55 = sdiv exact i64 %54, 8
  store i64 %55, ptr @b, align 8, !tbaa !5
  %56 = load i64, ptr @n, align 8, !tbaa !5
  %57 = getelementptr inbounds i64, ptr @a, i64 %56
  %58 = call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %57)
  %59 = ptrtoint ptr %58 to i64
  %60 = sub i64 %59, ptrtoint (ptr @a to i64)
  %61 = sdiv exact i64 %60, 8
  store i64 %61, ptr @c, align 8, !tbaa !5
  br label %79

62:                                               ; preds = %33
  %63 = load i64, ptr @n, align 8, !tbaa !5
  %64 = sub nsw i64 %63, 1
  %65 = getelementptr inbounds [100 x i64], ptr @a, i64 0, i64 %64
  %66 = load i64, ptr @n, align 8, !tbaa !5
  %67 = getelementptr inbounds i64, ptr @a, i64 %66
  %68 = call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %67)
  %69 = ptrtoint ptr %65 to i64
  %70 = ptrtoint ptr %68 to i64
  %71 = sub i64 %69, %70
  %72 = sdiv exact i64 %71, 8
  store i64 %72, ptr @b, align 8, !tbaa !5
  %73 = load i64, ptr @n, align 8, !tbaa !5
  %74 = getelementptr inbounds i64, ptr @a, i64 %73
  %75 = call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef @a, ptr noundef %74)
  %76 = ptrtoint ptr %75 to i64
  %77 = sub i64 %76, ptrtoint (ptr @a to i64)
  %78 = sdiv exact i64 %77, 8
  store i64 %78, ptr @c, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %62, %45
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr @b, align 8, !tbaa !5
  %82 = load i64, ptr @c, align 8, !tbaa !5
  %83 = icmp sge i64 %81, %82
  br i1 %83, label %84, label %87

84:                                               ; preds = %80
  %85 = load i64, ptr @b, align 8, !tbaa !5
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %85)
  br label %90

87:                                               ; preds = %80
  %88 = load i64, ptr @c, align 8, !tbaa !5
  %89 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %88)
  br label %90

90:                                               ; preds = %87, %84
  store i32 0, ptr %1, align 4
  br label %91

91:                                               ; preds = %90, %29
  %92 = load i32, ptr %1, align 4
  ret i32 %92
}

; 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 nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef, ptr noundef) #3

; 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" }
attributes #2 = { inlinehint 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" }

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

@a = external dso_local global [100 x i64], align 16
@n = external dso_local global i64, align 8
@i = external dso_local local_unnamed_addr global i64, align 8
@b = external dso_local local_unnamed_addr global i64, align 8
@c = 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)
  store i64 0, ptr @i, align 8, !tbaa !5
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = icmp sgt i64 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge6 = phi i64 [ %7, %.lr.ph ], [ 0, %0 ]
  %4 = getelementptr inbounds [100 x i64], ptr @a, i64 0, i64 %storemerge6
  %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) %4)
  %6 = load i64, ptr @i, align 8, !tbaa !5
  %7 = add nsw i64 %6, 1
  store i64 %7, ptr @i, align 8, !tbaa !5
  %8 = load i64, ptr @n, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %2, %0 ], [ %8, %.lr.ph ]
  %10 = getelementptr inbounds i64, ptr @a, i64 %.lcssa
  %11 = tail call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %10)
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %13 = getelementptr inbounds i64, ptr @a, i64 %12
  %14 = tail call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %13)
  %15 = ptrtoint ptr %11 to i64
  %16 = ptrtoint ptr %14 to i64
  %17 = sub i64 %15, %16
  %18 = ashr exact i64 %17, 3
  %19 = tail call noundef i64 @_ZSt3absl(i64 noundef %18)
  %20 = load i64, ptr @n, align 8, !tbaa !5
  %21 = add nsw i64 %20, -1
  %22 = icmp eq i64 %19, %21
  br i1 %22, label %56, label %23

23:                                               ; preds = %._crit_edge
  %24 = getelementptr inbounds i64, ptr @a, i64 %20
  %25 = tail call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %24)
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = getelementptr inbounds i64, ptr @a, i64 %26
  %28 = tail call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %27)
  %29 = ptrtoint ptr %25 to i64
  %30 = ptrtoint ptr %28 to i64
  %31 = sub i64 %29, %30
  %32 = icmp slt i64 %31, 0
  %33 = load i64, ptr @n, align 8, !tbaa !5
  %34 = add nsw i64 %33, -1
  %35 = getelementptr inbounds [100 x i64], ptr @a, i64 0, i64 %34
  %36 = getelementptr inbounds i64, ptr @a, i64 %33
  %37 = ptrtoint ptr %35 to i64
  br i1 %32, label %38, label %46

38:                                               ; preds = %23
  %39 = tail call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %36)
  %40 = ptrtoint ptr %39 to i64
  %41 = sub i64 %37, %40
  %42 = ashr exact i64 %41, 3
  store i64 %42, ptr @b, align 8, !tbaa !5
  %43 = load i64, ptr @n, align 8, !tbaa !5
  %44 = getelementptr inbounds i64, ptr @a, i64 %43
  %45 = tail call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %44)
  br label %54

46:                                               ; preds = %23
  %47 = tail call noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %36)
  %48 = ptrtoint ptr %47 to i64
  %49 = sub i64 %37, %48
  %50 = ashr exact i64 %49, 3
  store i64 %50, ptr @b, align 8, !tbaa !5
  %51 = load i64, ptr @n, align 8, !tbaa !5
  %52 = getelementptr inbounds i64, ptr @a, i64 %51
  %53 = tail call noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %52)
  br label %54

54:                                               ; preds = %38, %46
  %storemerge5.in.in.in = phi ptr [ %53, %46 ], [ %45, %38 ]
  %storemerge5.in.in = ptrtoint ptr %storemerge5.in.in.in to i64
  %storemerge5.in = sub i64 %storemerge5.in.in, ptrtoint (ptr @a to i64)
  %storemerge5 = ashr exact i64 %storemerge5.in, 3
  store i64 %storemerge5, ptr @c, align 8, !tbaa !5
  %55 = load i64, ptr @b, align 8, !tbaa !5
  %storemerge5. = tail call i64 @llvm.smax.i64(i64 %55, i64 %storemerge5)
  br label %56

56:                                               ; preds = %54, %._crit_edge
  %.sink = phi i64 [ %19, %._crit_edge ], [ %storemerge5., %54 ]
  %57 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.sink)
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11max_elementIPxET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11min_elementIPxET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #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 = { 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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass