; LLVM IR from tangjz/acm-icpc :: lydsy (2275)

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

@tot = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@fib = external dso_local global [101 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 2, ptr @tot, align 4, !tbaa !5
  store i64 1, ptr @fib, align 16, !tbaa !9
  store i64 2, ptr getelementptr inbounds ([101 x i64], ptr @fib, i64 0, i64 1), align 8, !tbaa !9
  br label %4

4:                                                ; preds = %27, %0
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = sub nsw i32 %5, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = load i64, ptr @n, align 8, !tbaa !9
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %12, label %30

12:                                               ; preds = %4
  %13 = load i32, ptr @tot, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load i32, ptr @tot, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 2
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add nsw i64 %17, %22
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %25
  store i64 %23, ptr %26, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %12
  %28 = load i32, ptr @tot, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @tot, align 4, !tbaa !5
  br label %4, !llvm.loop !11

30:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %31 = load i32, ptr @tot, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %53, %30
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = icmp sge i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %56

37:                                               ; preds = %33
  %38 = load i64, ptr @n, align 8, !tbaa !9
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = icmp sge i64 %38, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %37
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = load i64, ptr @n, align 8, !tbaa !9
  %50 = sub nsw i64 %49, %48
  store i64 %50, ptr @n, align 8, !tbaa !9
  %51 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %51, ptr @last, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %44, %37
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %2, align 4, !tbaa !5
  br label %33, !llvm.loop !13

56:                                               ; preds = %36
  %57 = load i32, ptr @last, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %60)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare i32 @printf(ptr noundef, ...) #1

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@last = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@fib = external dso_local local_unnamed_addr global [101 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 2, ptr @tot, align 4, !tbaa !5
  store i64 1, ptr @fib, align 16, !tbaa !9
  store i64 2, ptr getelementptr inbounds (i8, ptr @fib, i64 8), align 8, !tbaa !9
  %2 = load i64, ptr @n, align 8, !tbaa !9
  %3 = icmp sgt i64 %2, 2
  br i1 %3, label %.lr.ph, label %.lr.ph10.preheader

..preheader_crit_edge:                            ; preds = %.lr.ph
  %4 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %4, ptr @tot, align 4, !tbaa !5
  %5 = and i64 %indvars.iv, 4294967295
  br label %.lr.ph10.preheader

.lr.ph10.preheader:                               ; preds = %0, %..preheader_crit_edge
  %indvars.iv14.ph = phi i64 [ 1, %0 ], [ %5, %..preheader_crit_edge ]
  %6 = and i64 %indvars.iv14.ph, 1
  %lcmp.mod.not.not = icmp eq i64 %6, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph10.prol, label %.lr.ph10.prol.loopexit

.lr.ph10.prol:                                    ; preds = %.lr.ph10.preheader
  %7 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %indvars.iv14.ph
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %.not.prol = icmp slt i64 %2, %8
  br i1 %.not.prol, label %.lr.ph10.prol.loopexit.unr-lcssa, label %9

9:                                                ; preds = %.lr.ph10.prol
  %10 = sub nsw i64 %2, %8
  store i64 %10, ptr @n, align 8, !tbaa !9
  %11 = trunc nuw nsw i64 %indvars.iv14.ph to i32
  store i32 %11, ptr @last, align 4, !tbaa !5
  br label %.lr.ph10.prol.loopexit.unr-lcssa

.lr.ph10.prol.loopexit.unr-lcssa:                 ; preds = %9, %.lr.ph10.prol
  %12 = phi i64 [ %2, %.lr.ph10.prol ], [ %10, %9 ]
  %indvars.iv.next15.prol = add nsw i64 %indvars.iv14.ph, -1
  br label %.lr.ph10.prol.loopexit

.lr.ph10.prol.loopexit:                           ; preds = %.lr.ph10.prol.loopexit.unr-lcssa, %.lr.ph10.preheader
  %indvars.iv14.unr = phi i64 [ %indvars.iv14.ph, %.lr.ph10.preheader ], [ %indvars.iv.next15.prol, %.lr.ph10.prol.loopexit.unr-lcssa ]
  %.unr = phi i64 [ %2, %.lr.ph10.preheader ], [ %12, %.lr.ph10.prol.loopexit.unr-lcssa ]
  %13 = icmp eq i64 %indvars.iv14.ph, 0
  br i1 %13, label %._crit_edge, label %.lr.ph10

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %0 ]
  %14 = phi i64 [ %18, %.lr.ph ], [ 2, %0 ]
  %15 = add nsw i64 %indvars.iv, -2
  %16 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = add nsw i64 %17, %14
  %19 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %indvars.iv
  store i64 %18, ptr %19, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = icmp slt i64 %18, %2
  br i1 %20, label %.lr.ph, label %..preheader_crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %38, %.lr.ph10.prol.loopexit
  %21 = load i32, ptr @last, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %24)
  ret i32 0

.lr.ph10:                                         ; preds = %.lr.ph10.prol.loopexit, %38
  %indvars.iv14 = phi i64 [ %indvars.iv.next15.1, %38 ], [ %indvars.iv14.unr, %.lr.ph10.prol.loopexit ]
  %26 = phi i64 [ %39, %38 ], [ %.unr, %.lr.ph10.prol.loopexit ]
  %27 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %indvars.iv14
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %.not = icmp slt i64 %26, %28
  br i1 %.not, label %.lr.ph10.1, label %29

29:                                               ; preds = %.lr.ph10
  %30 = sub nsw i64 %26, %28
  store i64 %30, ptr @n, align 8, !tbaa !9
  %31 = trunc nuw nsw i64 %indvars.iv14 to i32
  store i32 %31, ptr @last, align 4, !tbaa !5
  br label %.lr.ph10.1

.lr.ph10.1:                                       ; preds = %.lr.ph10, %29
  %32 = phi i64 [ %26, %.lr.ph10 ], [ %30, %29 ]
  %indvars.iv.next15 = add nsw i64 %indvars.iv14, -1
  %33 = getelementptr inbounds [101 x i64], ptr @fib, i64 0, i64 %indvars.iv.next15
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %.not.1 = icmp slt i64 %32, %34
  br i1 %.not.1, label %38, label %35

35:                                               ; preds = %.lr.ph10.1
  %36 = sub nsw i64 %32, %34
  store i64 %36, ptr @n, align 8, !tbaa !9
  %37 = trunc nuw nsw i64 %indvars.iv.next15 to i32
  store i32 %37, ptr @last, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %35, %.lr.ph10.1
  %39 = phi i64 [ %32, %.lr.ph10.1 ], [ %36, %35 ]
  %indvars.iv.next15.1 = add nsw i64 %indvars.iv14, -2
  %40 = icmp sgt i64 %indvars.iv14, 1
  br i1 %40, label %.lr.ph10, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 #1 = { nofree nounwind "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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