; LLVM IR from manishbisht/Competitive-Programming :: Codechef/COOK74 (The Lost Arithmetic Sequences)

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

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

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

7:                                                ; preds = %3
  %8 = 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 @j, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %17, %7
  %10 = load i64, ptr @j, align 8, !tbaa !5
  %11 = load i64, ptr @n, align 8, !tbaa !5
  %12 = icmp slt i64 %10, %11
  br i1 %12, label %13, label %20

13:                                               ; preds = %9
  %14 = load i64, ptr @i, align 8, !tbaa !5
  %15 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %14
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %15)
  br label %17

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

20:                                               ; preds = %9
  %21 = load i64, ptr @n, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr @a, i64 %21
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @a, ptr noundef %22)
  %23 = load i64, ptr @n, align 8, !tbaa !5
  %24 = icmp eq i64 %23, 2
  br i1 %24, label %25, label %29

25:                                               ; preds = %20
  %26 = load i64, ptr @a, align 16, !tbaa !5
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %26)
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %86

29:                                               ; preds = %20
  %30 = load i64, ptr getelementptr inbounds ([100005 x i64], ptr @a, i64 0, i64 1), align 8, !tbaa !5
  %31 = load i64, ptr @a, align 16, !tbaa !5
  %32 = sub nsw i64 %30, %31
  store i64 %32, ptr @b, align 8, !tbaa !5
  %33 = load i64, ptr getelementptr inbounds ([100005 x i64], ptr @a, i64 0, i64 2), align 16, !tbaa !5
  %34 = load i64, ptr getelementptr inbounds ([100005 x i64], ptr @a, i64 0, i64 1), align 8, !tbaa !5
  %35 = sub nsw i64 %33, %34
  store i64 %35, ptr @c, align 8, !tbaa !5
  store i64 0, ptr @temp1, align 8, !tbaa !5
  store i64 0, ptr @temp2, align 8, !tbaa !5
  store i64 0, ptr @j, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %71, %29
  %37 = load i64, ptr @j, align 8, !tbaa !5
  %38 = load i64, ptr @n, align 8, !tbaa !5
  %39 = sub nsw i64 %38, 1
  %40 = icmp slt i64 %37, %39
  br i1 %40, label %41, label %74

41:                                               ; preds = %36
  %42 = load i64, ptr @i, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  %44 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = load i64, ptr @i, align 8, !tbaa !5
  %47 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = sub nsw i64 %45, %48
  %50 = load i64, ptr @b, align 8, !tbaa !5
  %51 = icmp eq i64 %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %41
  %53 = load i64, ptr @temp1, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr @temp1, align 8, !tbaa !5
  br label %70

55:                                               ; preds = %41
  %56 = load i64, ptr @i, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  %58 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !5
  %60 = load i64, ptr @i, align 8, !tbaa !5
  %61 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = sub nsw i64 %59, %62
  %64 = load i64, ptr @c, align 8, !tbaa !5
  %65 = icmp eq i64 %63, %64
  br i1 %65, label %66, label %69

66:                                               ; preds = %55
  %67 = load i64, ptr @temp2, align 8, !tbaa !5
  %68 = add nsw i64 %67, 1
  store i64 %68, ptr @temp2, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %66, %55
  br label %70

70:                                               ; preds = %69, %52
  br label %71

71:                                               ; preds = %70
  %72 = load i64, ptr @j, align 8, !tbaa !5
  %73 = add nsw i64 %72, 1
  store i64 %73, ptr @j, align 8, !tbaa !5
  br label %36, !llvm.loop !11

74:                                               ; preds = %36
  %75 = load i64, ptr @temp1, align 8, !tbaa !5
  %76 = load i64, ptr @temp2, align 8, !tbaa !5
  %77 = add nsw i64 %75, %76
  %78 = load i64, ptr @n, align 8, !tbaa !5
  %79 = icmp eq i64 %77, %78
  br i1 %79, label %80, label %85

80:                                               ; preds = %74
  %81 = load i64, ptr @temp1, align 8, !tbaa !5
  %82 = icmp eq i64 %81, 1
  br i1 %82, label %83, label %84

83:                                               ; preds = %80
  br label %84

84:                                               ; preds = %83, %80
  br label %85

85:                                               ; preds = %84, %74
  br label %86

86:                                               ; preds = %85, %25
  br label %87

87:                                               ; preds = %86
  %88 = load i64, ptr @i, align 8, !tbaa !5
  %89 = add nsw i64 %88, 1
  store i64 %89, ptr @i, align 8, !tbaa !5
  br label %3, !llvm.loop !12

90:                                               ; preds = %3
  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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #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)) #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 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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::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" }

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

.lr.ph14:                                         ; preds = %0, %38
  %4 = 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 @j, align 8, !tbaa !5
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph14
  %.lcssa = phi i64 [ %5, %.lr.ph14 ], [ %12, %.lr.ph ]
  %14 = getelementptr inbounds i64, ptr @a, i64 %.lcssa
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %14)
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 2
  br i1 %16, label %17, label %21

17:                                               ; preds = %._crit_edge
  %18 = load i64, ptr @a, align 16, !tbaa !5
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %18)
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %38

21:                                               ; preds = %._crit_edge
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 8, !tbaa !5
  %23 = load i64, ptr @a, align 16, !tbaa !5
  %24 = sub nsw i64 %22, %23
  store i64 %24, ptr @b, align 8, !tbaa !5
  %25 = load i64, ptr getelementptr inbounds (i8, ptr @a, i64 16), align 16, !tbaa !5
  %26 = sub nsw i64 %25, %22
  store i64 %26, ptr @c, align 8, !tbaa !5
  store i64 0, ptr @temp1, align 8, !tbaa !5
  store i64 0, ptr @temp2, align 8, !tbaa !5
  %27 = add i64 %15, -1
  %28 = icmp sgt i64 %15, 1
  br i1 %28, label %.lr.ph6, label %.loopexit

.lr.ph6:                                          ; preds = %21
  %29 = load i64, ptr @i, align 8, !tbaa !5
  %30 = add nsw i64 %29, 1
  %31 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %29
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = sub nsw i64 %32, %34
  %36 = icmp eq i64 %35, %24
  br i1 %36, label %.loopexit.sink.split, label %.lr.ph6.split

.lr.ph6.split:                                    ; preds = %.lr.ph6
  %37 = icmp eq i64 %35, %26
  br i1 %37, label %.loopexit.sink.split, label %.loopexit

.loopexit.sink.split:                             ; preds = %.lr.ph6.split, %.lr.ph6
  %temp1.sink = phi ptr [ @temp1, %.lr.ph6 ], [ @temp2, %.lr.ph6.split ]
  store i64 %27, ptr %temp1.sink, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.sink.split, %.lr.ph6.split, %21
  %storemerge3.lcssa = phi i64 [ 0, %21 ], [ %27, %.lr.ph6.split ], [ %27, %.loopexit.sink.split ]
  store i64 %storemerge3.lcssa, ptr @j, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %.loopexit, %17
  %39 = load i64, ptr @i, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr @i, align 8, !tbaa !5
  %41 = load i64, ptr @t, align 8, !tbaa !5
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %.lr.ph14, label %._crit_edge15, !llvm.loop !11

._crit_edge15:                                    ; preds = %38, %0
  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 uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #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)) #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 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"}
!11 = distinct !{!11, !10}


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