; LLVM IR from manishbisht/Competitive-Programming :: Skillenza/Code Golf Challenge 1 (Fibonacci numbers)

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

@f = external dso_local global i64, align 8
@s = external dso_local global i64, align 8
@i = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@a = external dso_local global [115 x i64], align 16
@_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
  store i64 0, ptr @f, align 8, !tbaa !5
  store i64 1, ptr @s, align 8, !tbaa !5
  store i64 0, ptr @i, align 8, !tbaa !5
  br label %2

2:                                                ; preds = %16, %0
  %3 = load i64, ptr @i, align 8, !tbaa !5
  %4 = icmp slt i64 %3, 115
  br i1 %4, label %5, label %19

5:                                                ; preds = %2
  %6 = load i64, ptr @f, align 8, !tbaa !5
  %7 = srem i64 %6, 1000000007
  store i64 %7, ptr @f, align 8, !tbaa !5
  %8 = load i64, ptr @f, align 8, !tbaa !5
  %9 = load i64, ptr @i, align 8, !tbaa !5
  %10 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %9
  store i64 %8, ptr %10, align 8, !tbaa !5
  %11 = load i64, ptr @f, align 8, !tbaa !5
  %12 = load i64, ptr @s, align 8, !tbaa !5
  %13 = add nsw i64 %11, %12
  store i64 %13, ptr @n, align 8, !tbaa !5
  %14 = load i64, ptr @s, align 8, !tbaa !5
  store i64 %14, ptr @f, align 8, !tbaa !5
  %15 = load i64, ptr @n, align 8, !tbaa !5
  store i64 %15, ptr @s, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %5
  %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 %2, !llvm.loop !9

19:                                               ; preds = %2
  %20 = 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 %21

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

25:                                               ; preds = %21
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @f)
  %27 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %26, ptr noundef nonnull align 8 dereferenceable(8) @s)
  %28 = load i64, ptr @s, align 8, !tbaa !5
  %29 = add nsw i64 %28, 2
  %30 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = load i64, ptr @f, align 8, !tbaa !5
  %33 = add nsw i64 %32, 1
  %34 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = sub nsw i64 %31, %35
  %37 = srem i64 %36, 1000000007
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %37)
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %40

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

43:                                               ; preds = %21
  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 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}


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

@f = external dso_local global i64, align 8
@s = external dso_local global i64, align 8
@i = external dso_local local_unnamed_addr global i64, align 8
@n = external dso_local global i64, align 8
@a = external dso_local local_unnamed_addr global [115 x i64], align 16
@_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 {
  br label %1

1:                                                ; preds = %7, %0
  %storemerge4 = phi i64 [ 0, %0 ], [ %12, %7 ]
  %2 = phi i64 [ 0, %0 ], [ %6, %7 ]
  %3 = phi i64 [ 1, %0 ], [ %11, %7 ]
  %4 = srem i64 %2, 1000000007
  %5 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %storemerge4
  store i64 %4, ptr %5, align 16, !tbaa !5
  %6 = add nsw i64 %3, %4
  %exitcond.not = icmp eq i64 %storemerge4, 114
  br i1 %exitcond.not, label %13, label %7, !llvm.loop !9

7:                                                ; preds = %1
  %8 = or disjoint i64 %storemerge4, 1
  %9 = srem i64 %3, 1000000007
  %10 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %8
  store i64 %9, ptr %10, align 8, !tbaa !5
  %11 = add nsw i64 %6, %9
  %12 = add nuw nsw i64 %storemerge4, 2
  br label %1

13:                                               ; preds = %1
  store i64 115, ptr @i, align 8, !tbaa !5
  store i64 %3, ptr @f, align 8, !tbaa !5
  store i64 %6, ptr @s, align 8, !tbaa !5
  store i64 %6, ptr @n, align 8, !tbaa !5
  %14 = 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
  %15 = load i64, ptr @n, align 8, !tbaa !5
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13, %.lr.ph
  %17 = 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) @f)
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(8) @s)
  %19 = load i64, ptr @s, align 8, !tbaa !5
  %20 = add nsw i64 %19, 2
  %21 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = load i64, ptr @f, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  %25 = getelementptr inbounds [115 x i64], ptr @a, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = sub nsw i64 %22, %26
  %28 = srem i64 %27, 1000000007
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %28)
  %30 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %31 = load i64, ptr @i, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr @i, align 8, !tbaa !5
  %33 = load i64, ptr @n, align 8, !tbaa !5
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %13
  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

; 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass