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

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

@t = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@pos = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@fib = external dso_local global [85 x i64], align 16
@x = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

5:                                                ; preds = %84, %0
  %6 = load i32, ptr @t, align 4, !tbaa !9
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr @t, align 4, !tbaa !9
  %8 = icmp ne i32 %6, 0
  br i1 %8, label %9, label %87

9:                                                ; preds = %5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  br label %11

11:                                               ; preds = %33, %9
  %12 = load i32, ptr @mx, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = load i64, ptr @x, align 8, !tbaa !5
  %17 = icmp sle i64 %15, %16
  br i1 %17, label %18, label %36

18:                                               ; preds = %11
  %19 = load i32, ptr @mx, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = load i32, ptr @mx, align 4, !tbaa !9
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i64 %22, %27
  %29 = load i32, ptr @mx, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %31
  store i64 %28, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %18
  %34 = load i32, ptr @mx, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @mx, align 4, !tbaa !9
  br label %11, !llvm.loop !11

36:                                               ; preds = %11
  store i32 0, ptr @pos, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %46, %36
  %38 = load i32, ptr @pos, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = load i64, ptr @x, align 8, !tbaa !5
  %44 = icmp sle i64 %42, %43
  br i1 %44, label %45, label %49

45:                                               ; preds = %37
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr @pos, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @pos, align 4, !tbaa !9
  br label %37, !llvm.loop !13

49:                                               ; preds = %37
  store i32 0, ptr @cnt, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %81, %49
  %51 = load i64, ptr @x, align 8, !tbaa !5
  %52 = icmp sgt i64 %51, 0
  br i1 %52, label %53, label %84

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %62, %53
  %55 = load i32, ptr @pos, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !5
  %59 = load i64, ptr @x, align 8, !tbaa !5
  %60 = icmp sgt i64 %58, %59
  br i1 %60, label %61, label %65

61:                                               ; preds = %54
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr @pos, align 4, !tbaa !9
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr @pos, align 4, !tbaa !9
  br label %54, !llvm.loop !14

65:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %66 = load i64, ptr @x, align 8, !tbaa !5
  %67 = load i32, ptr @pos, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = sub nsw i64 %66, %70
  store i64 %71, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %72 = load i32, ptr @pos, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !5
  %77 = load i64, ptr @x, align 8, !tbaa !5
  %78 = sub nsw i64 %76, %77
  store i64 %78, ptr %3, align 8, !tbaa !5
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %80 = load i64, ptr %79, align 8, !tbaa !5
  store i64 %80, ptr @x, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %81

81:                                               ; preds = %65
  %82 = load i32, ptr @cnt, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr @cnt, align 4, !tbaa !9
  br label %50, !llvm.loop !15

84:                                               ; preds = %50
  %85 = load i32, ptr @cnt, align 4, !tbaa !9
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %85)
  br label %5, !llvm.loop !16

87:                                               ; preds = %5
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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"

@t = external dso_local global i32, align 4
@mx = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@fib = external dso_local local_unnamed_addr global [85 x i64], align 16
@x = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  store i64 1, ptr @fib, align 16, !tbaa !5
  store i64 2, ptr getelementptr inbounds (i8, ptr @fib, i64 8), align 8, !tbaa !5
  store i32 1, ptr @mx, align 4, !tbaa !9
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %4 = load i32, ptr @t, align 4, !tbaa !9
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !9
  %.not15 = icmp eq i32 %4, 0
  br i1 %.not15, label %._crit_edge18, label %.lr.ph17

.lr.ph17:                                         ; preds = %0, %._crit_edge13
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %7 = load i64, ptr @x, align 8, !tbaa !5
  %mx.promoted = load i32, ptr @mx, align 4, !tbaa !9
  %8 = sext i32 %mx.promoted to i64
  %9 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not17 = icmp sgt i64 %10, %7
  br i1 %.not17, label %.preheader4.preheader, label %.lr.ph

.preheader4.preheader:                            ; preds = %..preheader4_crit_edge, %.lr.ph17
  br label %.preheader4

..preheader4_crit_edge:                           ; preds = %.lr.ph
  %11 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %11, ptr @mx, align 4, !tbaa !9
  br label %.preheader4.preheader

.lr.ph:                                           ; preds = %.lr.ph17, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %8, %.lr.ph17 ]
  %12 = phi i64 [ %16, %.lr.ph ], [ %10, %.lr.ph17 ]
  %13 = add nsw i64 %indvars.iv, -1
  %14 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, %12
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %17 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %indvars.iv.next
  store i64 %16, ptr %17, align 8, !tbaa !5
  %.not1 = icmp sgt i64 %16, %7
  br i1 %.not1, label %..preheader4_crit_edge, label %.lr.ph, !llvm.loop !11

.preheader4:                                      ; preds = %.preheader4.preheader, %.preheader4
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %.preheader4 ], [ 0, %.preheader4.preheader ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %18 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %indvars.iv.next24
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %.not2 = icmp sgt i64 %19, %7
  br i1 %.not2, label %thread-pre-split, label %.preheader4, !llvm.loop !13

thread-pre-split:                                 ; preds = %.preheader4
  %20 = trunc nuw nsw i64 %indvars.iv23 to i32
  store i32 %20, ptr @pos, align 4, !tbaa !9
  store i32 0, ptr @cnt, align 4, !tbaa !9
  %21 = icmp sgt i64 %7, 0
  br i1 %21, label %.preheader, label %._crit_edge13

.preheader:                                       ; preds = %thread-pre-split, %31
  %22 = phi i64 [ %39, %31 ], [ %7, %thread-pre-split ]
  %pos.promoted = load i32, ptr @pos, align 4, !tbaa !9
  %23 = sext i32 %pos.promoted to i64
  %24 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = icmp sgt i64 %25, %22
  br i1 %26, label %.lr.ph9, label %31

.lr.ph9:                                          ; preds = %.preheader, %.lr.ph9
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %.lr.ph9 ], [ %23, %.preheader ]
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, -1
  %27 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %indvars.iv.next27
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = icmp sgt i64 %28, %22
  br i1 %29, label %.lr.ph9, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph9
  %30 = trunc nsw i64 %indvars.iv.next27 to i32
  store i32 %30, ptr @pos, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %._crit_edge, %.preheader
  %.lcssa6 = phi i32 [ %30, %._crit_edge ], [ %pos.promoted, %.preheader ]
  %.lcssa5 = phi i64 [ %28, %._crit_edge ], [ %25, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %32 = sub nsw i64 %22, %.lcssa5
  store i64 %32, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %33 = add nsw i32 %.lcssa6, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [85 x i64], ptr @fib, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = sub nsw i64 %36, %22
  store i64 %37, ptr %2, align 8, !tbaa !5
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %39 = load i64, ptr %38, align 8, !tbaa !5
  store i64 %39, ptr @x, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  %40 = load i32, ptr @cnt, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @cnt, align 4, !tbaa !9
  %42 = icmp sgt i64 %39, 0
  br i1 %42, label %.preheader, label %._crit_edge13, !llvm.loop !15

._crit_edge13:                                    ; preds = %31, %thread-pre-split
  %storemerge3.lcssa = phi i32 [ 0, %thread-pre-split ], [ %41, %31 ]
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %storemerge3.lcssa)
  %44 = load i32, ptr @t, align 4, !tbaa !9
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr @t, align 4, !tbaa !9
  %.not = icmp eq i32 %44, 0
  br i1 %.not, label %._crit_edge18, label %.lr.ph17, !llvm.loop !16

._crit_edge18:                                    ; preds = %._crit_edge13, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

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

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

attributes #0 = { mustprogress 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" }
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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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