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

; 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.Matrix = type { i32, i32, [2 x [2 x i32]] }

@A = external dso_local global %struct.Matrix, align 4
@t = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@fib = external dso_local global [61 x i64], align 16
@.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 [9 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z4calcx(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 i32, align 4
  %3 = alloca %struct.Matrix, align 4
  store i32 0, ptr %1, align 4
  store i64 1, ptr getelementptr inbounds ([61 x i64], ptr @fib, i64 0, i64 1), align 8, !tbaa !5
  store i64 1, ptr @fib, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %23, %0
  %5 = load i32, ptr %2, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 61
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %26

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

23:                                               ; preds = %8
  %24 = load i32, ptr %2, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !9
  br label %4, !llvm.loop !11

26:                                               ; preds = %7
  store i32 2, ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 1), align 4, !tbaa !13
  store i32 2, ptr @A, align 4, !tbaa !15
  store i32 1, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), i64 0, i64 1), align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds ([2 x [2 x i32]], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds ([2 x i32], ptr getelementptr inbounds (%struct.Matrix, ptr @A, i32 0, i32 2), i64 0, i64 1), align 4, !tbaa !9
  %27 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %28

28:                                               ; preds = %32, %26
  %29 = load i32, ptr @t, align 4, !tbaa !9
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr @t, align 4, !tbaa !9
  %31 = icmp ne i32 %29, 0
  br i1 %31, label %32, label %43

32:                                               ; preds = %28
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n)
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = call noundef i64 @_Z4calcx(i64 noundef %34)
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #5
  %36 = load i64, ptr @n, align 8, !tbaa !5
  %37 = add nsw i64 %36, 2
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 4 %3, ptr noundef nonnull align 4 dereferenceable(24) @A, i64 noundef %37)
  %38 = getelementptr inbounds %struct.Matrix, ptr %3, i32 0, i32 2
  %39 = getelementptr inbounds [2 x [2 x i32]], ptr %38, i64 0, i64 0
  %40 = getelementptr inbounds [2 x i32], ptr %39, i64 0, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %35, i32 noundef %41)
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #5
  br label %28, !llvm.loop !16

43:                                               ; preds = %28
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), i64 noundef) #4 align 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 4}
!14 = !{!"_ZTS6Matrix", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = !{!14, !10, i64 0}
!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"

%struct.Matrix = type { i32, i32, [2 x [2 x i32]] }

@A = external dso_local global %struct.Matrix, align 4
@t = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@fib = external dso_local local_unnamed_addr global [61 x i64], align 16
@.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 [9 x i8], align 1

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

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

; Function Attrs: mustprogress 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() local_unnamed_addr #2 {
  %1 = alloca %struct.Matrix, align 4
  store i64 1, ptr getelementptr inbounds (i8, ptr @fib, i64 8), align 8, !tbaa !5
  store i64 1, ptr @fib, align 16, !tbaa !5
  br label %7

2:                                                ; preds = %7
  store i32 2, ptr getelementptr inbounds (i8, ptr @A, i64 4), align 4, !tbaa !9
  store i32 2, ptr @A, align 4, !tbaa !12
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 20), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 16), align 4, !tbaa !13
  store i32 1, ptr getelementptr inbounds (i8, ptr @A, i64 12), align 4, !tbaa !13
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %4 = load i32, ptr @t, align 4, !tbaa !13
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @t, align 4, !tbaa !13
  %.not6 = icmp eq i32 %4, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  br label %29

7:                                                ; preds = %23, %0
  %8 = phi i64 [ 1, %0 ], [ %27, %23 ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.3, %23 ]
  %9 = add nsw i64 %indvars.iv, -2
  %10 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %9
  %11 = load i64, ptr %10, align 16, !tbaa !5
  %12 = add nsw i64 %11, %8
  %13 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %indvars.iv
  store i64 %12, ptr %13, align 16, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = add nsw i64 %indvars.iv, -1
  %15 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %16, %12
  %18 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %indvars.iv.next
  store i64 %17, ptr %18, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %19 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %indvars.iv
  %20 = load i64, ptr %19, align 16, !tbaa !5
  %21 = add nsw i64 %20, %17
  %22 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %indvars.iv.next.1
  store i64 %21, ptr %22, align 16, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 61
  br i1 %exitcond.not.2, label %2, label %23, !llvm.loop !14

23:                                               ; preds = %7
  %24 = or disjoint i64 %indvars.iv, 1
  %25 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = add nsw i64 %26, %21
  %28 = getelementptr inbounds [61 x i64], ptr @fib, i64 0, i64 %indvars.iv.next.2
  store i64 %27, ptr %28, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %7

29:                                               ; preds = %.lr.ph, %29
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n)
  %31 = load i64, ptr @n, align 8, !tbaa !5
  %32 = call noundef i64 @_Z4calcx(i64 noundef %31)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #5
  %33 = load i64, ptr @n, align 8, !tbaa !5
  %34 = add nsw i64 %33, 2
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 4 %1, ptr noundef nonnull align 4 dereferenceable(24) @A, i64 noundef %34)
  %35 = load i32, ptr %6, align 4, !tbaa !13
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %32, i32 noundef %35)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #5
  %37 = load i32, ptr @t, align 4, !tbaa !13
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @t, align 4, !tbaa !13
  %.not = icmp eq i32 %37, 0
  br i1 %.not, label %._crit_edge, label %29, !llvm.loop !16

._crit_edge:                                      ; preds = %29, %2
  ret i32 0
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 4, ptr noundef nonnull align 4 dereferenceable(24), i64 noundef) local_unnamed_addr #4 align 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 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 = { 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 #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 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass