; LLVM IR from tangjz/acm-icpc :: 51nod (1399)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3fibx(i64 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z9count_fibxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calcxx(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %12

12:                                               ; preds = %120, %118, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %2, align 4, !tbaa !5
  %15 = icmp ne i32 %13, 0
  br i1 %15, label %16, label %121

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = icmp sle i64 %18, 2
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = call i32 @puts(ptr noundef @.str.2)
  store i32 2, ptr %7, align 4
  br label %118, !llvm.loop !11

22:                                               ; preds = %16
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = and i64 %23, 1
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %83

26:                                               ; preds = %22
  %27 = load i64, ptr %3, align 8, !tbaa !9
  %28 = load i64, ptr %4, align 8, !tbaa !9
  %29 = shl i64 %28, 2
  %30 = srem i64 %27, %29
  store i64 %30, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %31 = load i64, ptr %3, align 8, !tbaa !9
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = shl i64 %32, 2
  %34 = sdiv i64 %31, %33
  %35 = srem i64 %34, 1000000007
  %36 = load i64, ptr %4, align 8, !tbaa !9
  %37 = sub nsw i64 %36, 1
  %38 = shl i64 %37, 1
  %39 = srem i64 %38, 1000000007
  %40 = mul nsw i64 %35, %39
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = call noundef i64 @_Z9count_fibxx(i64 noundef %41, i64 noundef %42)
  %44 = add nsw i64 %40, %43
  %45 = srem i64 %44, 1000000007
  %46 = trunc i64 %45 to i32
  store i32 %46, ptr %8, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = load i64, ptr %4, align 8, !tbaa !9
  %50 = call noundef i32 @_Z3fibx(i64 noundef %49)
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %48, %51
  %53 = srem i64 %52, 1000000007
  %54 = trunc i64 %53 to i32
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %54)
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = load i64, ptr %4, align 8, !tbaa !9
  %57 = shl i64 %56, 1
  %58 = icmp sle i64 %55, %57
  br i1 %58, label %59, label %63

59:                                               ; preds = %26
  %60 = load i64, ptr %5, align 8, !tbaa !9
  %61 = load i64, ptr %4, align 8, !tbaa !9
  %62 = call noundef i32 @_Z4calcxx(i64 noundef %60, i64 noundef %61)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %62)
  br label %82

63:                                               ; preds = %26
  %64 = load i64, ptr %4, align 8, !tbaa !9
  %65 = shl i64 %64, 1
  %66 = load i64, ptr %4, align 8, !tbaa !9
  %67 = call noundef i32 @_Z4calcxx(i64 noundef %65, i64 noundef %66)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %67)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %68 = load i64, ptr %5, align 8, !tbaa !9
  %69 = load i64, ptr %4, align 8, !tbaa !9
  %70 = shl i64 %69, 1
  %71 = sub nsw i64 %68, %70
  %72 = load i64, ptr %4, align 8, !tbaa !9
  %73 = call noundef i32 @_Z4calcxx(i64 noundef %71, i64 noundef %72)
  %74 = sub nsw i32 0, %73
  store i32 %74, ptr %9, align 4, !tbaa !5
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = icmp slt i32 %75, 0
  br i1 %76, label %77, label %80

77:                                               ; preds = %63
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1000000007
  store i32 %79, ptr %9, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %77, %63
  %81 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %81)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %82

82:                                               ; preds = %80, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %115

83:                                               ; preds = %22
  %84 = load i64, ptr %3, align 8, !tbaa !9
  %85 = load i64, ptr %4, align 8, !tbaa !9
  %86 = shl i64 %85, 1
  %87 = srem i64 %84, %86
  store i64 %87, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %88 = load i64, ptr %3, align 8, !tbaa !9
  %89 = load i64, ptr %4, align 8, !tbaa !9
  %90 = shl i64 %89, 1
  %91 = sdiv i64 %88, %90
  %92 = srem i64 %91, 1000000007
  %93 = load i64, ptr %4, align 8, !tbaa !9
  %94 = add nsw i64 %93, 2
  %95 = ashr i64 %94, 1
  %96 = srem i64 %95, 1000000007
  %97 = mul nsw i64 %92, %96
  %98 = load i64, ptr %5, align 8, !tbaa !9
  %99 = load i64, ptr %4, align 8, !tbaa !9
  %100 = call noundef i64 @_Z9count_fibxx(i64 noundef %98, i64 noundef %99)
  %101 = add nsw i64 %97, %100
  %102 = srem i64 %101, 1000000007
  %103 = trunc i64 %102 to i32
  store i32 %103, ptr %10, align 4, !tbaa !5
  %104 = load i32, ptr %10, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = load i64, ptr %4, align 8, !tbaa !9
  %107 = call noundef i32 @_Z3fibx(i64 noundef %106)
  %108 = sext i32 %107 to i64
  %109 = mul nsw i64 %105, %108
  %110 = srem i64 %109, 1000000007
  %111 = trunc i64 %110 to i32
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %111)
  %112 = load i64, ptr %5, align 8, !tbaa !9
  %113 = load i64, ptr %4, align 8, !tbaa !9
  %114 = call noundef i32 @_Z4calcxx(i64 noundef %112, i64 noundef %113)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %114)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %115

115:                                              ; preds = %83, %82
  %116 = load i32, ptr %6, align 4, !tbaa !5
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %116)
  store i32 0, ptr %7, align 4
  br label %118

118:                                              ; preds = %115, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %119 = load i32, ptr %7, align 4
  switch i32 %119, label %123 [
    i32 0, label %120
    i32 2, label %12
  ]

120:                                              ; preds = %118
  br label %12, !llvm.loop !11

121:                                              ; preds = %12
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %122 = load i32, ptr %1, align 4
  ret i32 %122

123:                                              ; preds = %118
  unreachable
}

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

declare i32 @puts(ptr noundef) #4

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 #5 = { 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"}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3fibx(i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z9count_fibxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calcxx(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr %1, align 4, !tbaa !5
  %.not19 = icmp eq i32 %6, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %68
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %9 = load i64, ptr %3, align 8, !tbaa !9
  %10 = icmp slt i64 %9, 3
  br i1 %10, label %11, label %13

11:                                               ; preds = %.lr.ph
  %12 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %68, !llvm.loop !11

13:                                               ; preds = %.lr.ph
  %14 = and i64 %9, 1
  %.not17 = icmp eq i64 %14, 0
  %15 = load i64, ptr %2, align 8, !tbaa !9
  br i1 %.not17, label %45, label %16

16:                                               ; preds = %13
  %17 = shl i64 %9, 2
  %18 = srem i64 %15, %17
  %19 = sdiv i64 %15, %17
  %20 = srem i64 %19, 1000000007
  %21 = shl nuw i64 %9, 1
  %22 = add nsw i64 %21, -2
  %23 = srem i64 %22, 1000000007
  %24 = mul nsw i64 %20, %23
  %25 = call noundef i64 @_Z9count_fibxx(i64 noundef %18, i64 noundef %9)
  %26 = add nsw i64 %24, %25
  %27 = srem i64 %26, 1000000007
  %28 = load i64, ptr %3, align 8, !tbaa !9
  %29 = call noundef i32 @_Z3fibx(i64 noundef %28)
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %27, %30
  %32 = srem i64 %31, 1000000007
  %33 = trunc nsw i64 %32 to i32
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %33)
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = shl i64 %34, 1
  %.not18 = icmp sgt i64 %18, %35
  br i1 %.not18, label %38, label %36

36:                                               ; preds = %16
  %37 = call noundef i32 @_Z4calcxx(i64 noundef %18, i64 noundef %34)
  br label %65

38:                                               ; preds = %16
  %39 = call noundef i32 @_Z4calcxx(i64 noundef %35, i64 noundef %34)
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %39)
  %40 = load i64, ptr %3, align 8, !tbaa !9
  %41 = shl i64 %40, 1
  %42 = sub nsw i64 %18, %41
  %43 = call noundef i32 @_Z4calcxx(i64 noundef %42, i64 noundef %40)
  %44 = icmp sgt i32 %43, 0
  %spec.select = select i1 %44, i32 1000000007, i32 0
  %.0 = sub nsw i32 %spec.select, %43
  br label %65

45:                                               ; preds = %13
  %46 = shl nuw i64 %9, 1
  %47 = srem i64 %15, %46
  %48 = sdiv i64 %15, %46
  %49 = srem i64 %48, 1000000007
  %50 = add nuw nsw i64 %9, 2
  %51 = lshr exact i64 %50, 1
  %52 = urem i64 %51, 1000000007
  %53 = mul nsw i64 %49, %52
  %54 = call noundef i64 @_Z9count_fibxx(i64 noundef %47, i64 noundef %9)
  %55 = add nsw i64 %53, %54
  %56 = srem i64 %55, 1000000007
  %57 = load i64, ptr %3, align 8, !tbaa !9
  %58 = call noundef i32 @_Z3fibx(i64 noundef %57)
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %56, %59
  %61 = srem i64 %60, 1000000007
  %62 = trunc nsw i64 %61 to i32
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %62)
  %63 = load i64, ptr %3, align 8, !tbaa !9
  %64 = call noundef i32 @_Z4calcxx(i64 noundef %47, i64 noundef %63)
  br label %65

65:                                               ; preds = %36, %38, %45
  %.sink = phi i32 [ %37, %36 ], [ %.0, %38 ], [ %64, %45 ]
  call void @_Z7mod_incRii(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %.sink)
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %66)
  br label %68

68:                                               ; preds = %65, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = add nsw i32 %69, -1
  store i32 %70, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %69, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %68, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #4

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

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass