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

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

%struct.Fib = type { i32, i32 }

@len = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@sum = external dso_local global [2 x i32], align 4
@ans = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@A = external dso_local global %struct.Fib, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.Fib, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @len, ptr noundef @mod)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = add nsw i64 %5, 2
  %7 = call i64 @_ZN3Fib3powEx(ptr noundef nonnull align 4 dereferenceable(8) @A, i64 noundef %6)
  store i64 %7, ptr %2, align 4
  %8 = getelementptr inbounds %struct.Fib, ptr %2, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %9, ptr @sum, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %10 = load i64, ptr @n, align 8, !tbaa !5
  %11 = call noundef i32 @_Z7mod_powix(i32 noundef 2, i64 noundef %10)
  %12 = load i32, ptr @sum, align 4, !tbaa !12
  %13 = sub nsw i32 %11, %12
  store i32 %13, ptr getelementptr inbounds ([2 x i32], ptr @sum, i64 0, i64 1), align 4, !tbaa !12
  %14 = load i32, ptr @len, align 4, !tbaa !12
  %15 = icmp sge i32 %14, 62
  br i1 %15, label %22, label %16

16:                                               ; preds = %0
  %17 = load i64, ptr @m, align 8, !tbaa !5
  %18 = load i32, ptr @len, align 4, !tbaa !12
  %19 = zext i32 %18 to i64
  %20 = shl i64 1, %19
  %21 = icmp slt i64 %17, %20
  br label %22

22:                                               ; preds = %16, %0
  %23 = phi i1 [ true, %0 ], [ %21, %16 ]
  %24 = zext i1 %23 to i32
  store i32 %24, ptr @ans, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %46, %22
  %26 = load i32, ptr %3, align 4, !tbaa !12
  %27 = load i32, ptr @len, align 4, !tbaa !12
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %49

30:                                               ; preds = %25
  %31 = load i32, ptr @ans, align 4, !tbaa !12
  %32 = sext i32 %31 to i64
  %33 = load i64, ptr @m, align 8, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !12
  %35 = zext i32 %34 to i64
  %36 = ashr i64 %33, %35
  %37 = and i64 %36, 1
  %38 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %32, %40
  %42 = load i32, ptr @mod, align 4, !tbaa !12
  %43 = sext i32 %42 to i64
  %44 = srem i64 %41, %43
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr @ans, align 4, !tbaa !12
  br label %46

46:                                               ; preds = %30
  %47 = load i32, ptr %3, align 4, !tbaa !12
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !12
  br label %25, !llvm.loop !13

49:                                               ; preds = %29
  %50 = load i32, ptr @ans, align 4, !tbaa !12
  %51 = load i32, ptr @mod, align 4, !tbaa !12
  %52 = srem i32 %50, %51
  %53 = load i32, ptr @mod, align 4, !tbaa !12
  %54 = add nsw i32 %52, %53
  %55 = load i32, ptr @mod, align 4, !tbaa !12
  %56 = srem i32 %54, %55
  store i32 %56, ptr @ans, align 4, !tbaa !12
  %57 = load i32, ptr @ans, align 4, !tbaa !12
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %57)
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN3Fib3powEx(ptr noundef nonnull align 4 dereferenceable(8), i64 noundef) #4 align 2

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

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

%struct.Fib = type { i32, i32 }

@len = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@sum = external dso_local local_unnamed_addr global [2 x i32], align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@A = external dso_local global %struct.Fib, align 4
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @len, ptr noundef nonnull @mod)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = add nsw i64 %2, 2
  %4 = tail call i64 @_ZN3Fib3powEx(ptr noundef nonnull align 4 dereferenceable(8) @A, i64 noundef %3)
  %.sroa.3.0.extract.shift = lshr i64 %4, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  store i32 %.sroa.3.0.extract.trunc, ptr @sum, align 4, !tbaa !9
  %5 = load i64, ptr @n, align 8, !tbaa !5
  %6 = tail call noundef i32 @_Z7mod_powix(i32 noundef 2, i64 noundef %5)
  %7 = load i32, ptr @sum, align 4, !tbaa !9
  %8 = sub nsw i32 %6, %7
  store i32 %8, ptr getelementptr inbounds (i8, ptr @sum, i64 4), align 4, !tbaa !9
  %9 = load i32, ptr @len, align 4
  %10 = icmp sgt i32 %9, 61
  %11 = load i64, ptr @m, align 8
  %12 = zext i32 %9 to i64
  %13 = shl nuw i64 1, %12
  %14 = icmp slt i64 %11, %13
  %15 = select i1 %10, i1 true, i1 %14
  %16 = zext i1 %15 to i32
  %17 = icmp sgt i32 %9, 0
  %.pre = load i32, ptr @mod, align 4, !tbaa !9
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %18 = sext i32 %.pre to i64
  %xtraiter = and i64 %12, 1
  %19 = icmp eq i32 %9, 1
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %12, 2147483646
  br label %34

._crit_edge.loopexit.unr-lcssa:                   ; preds = %34, %.lr.ph
  %.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %52, %34 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %34 ]
  %.unr = phi i32 [ %16, %.lr.ph ], [ %52, %34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %20 = sext i32 %.unr to i64
  %21 = lshr i64 %11, %indvars.iv.unr
  %22 = and i64 %21, 1
  %23 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = mul nsw i64 %25, %20
  %27 = srem i64 %26, %18
  %28 = trunc nsw i64 %27 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %0
  %29 = phi i32 [ %16, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %28, %._crit_edge.loopexit.epilog-lcssa ]
  %30 = srem i32 %29, %.pre
  %31 = add nsw i32 %30, %.pre
  %32 = srem i32 %31, %.pre
  store i32 %32, ptr @ans, align 4, !tbaa !9
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %32)
  ret i32 0

34:                                               ; preds = %34, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %34 ]
  %35 = phi i32 [ %16, %.lr.ph.new ], [ %52, %34 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %34 ]
  %36 = sext i32 %35 to i64
  %37 = lshr i64 %11, %indvars.iv
  %38 = and i64 %37, 1
  %39 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = mul nsw i64 %41, %36
  %43 = srem i64 %42, %18
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %sext = shl i64 %43, 32
  %44 = ashr exact i64 %sext, 32
  %45 = lshr i64 %11, %indvars.iv.next
  %46 = and i64 %45, 1
  %47 = getelementptr inbounds [2 x i32], ptr @sum, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %44, %49
  %51 = srem i64 %50, %18
  %52 = trunc nsw i64 %51 to i32
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %34, !llvm.loop !11
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN3Fib3powEx(ptr noundef nonnull align 4 dereferenceable(8), i64 noundef) local_unnamed_addr #3 align 2

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

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 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 #2 = { 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 #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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