; LLVM IR from tangjz/acm-icpc :: 51nod/1080.ll (Z3gaox)

; 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.std::pair" = type { i64, i64 }
%struct.Matrix = type { i32, i32, i64, [2 x [2 x i64]] }

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

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

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

; Function Attrs: nounwind
declare i32 @rand() #2

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z3gaox(i64 noundef %0) #3 {
  %2 = alloca %"struct.std::pair", align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.Matrix, align 8
  %10 = alloca %struct.Matrix, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %12)
  %14 = fptosi double %13 to i64
  store i64 %14, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %24, %1
  %16 = call i32 @rand() #5
  %17 = sext i32 %16 to i64
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = srem i64 %17, %18
  store i64 %19, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = mul nsw i64 %20, %21
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %15
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = sub nsw i64 %26, 1
  %28 = ashr i64 %27, 1
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = call noundef i64 @_Z7mod_powxxx(i64 noundef %25, i64 noundef %28, i64 noundef %29)
  %31 = icmp eq i64 %30, 1
  br i1 %31, label %15, label %32, !llvm.loop !9

32:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %33, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr %10) #5
  %34 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 0
  store i32 2, ptr %34, align 8, !tbaa !11
  %35 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 1
  store i32 2, ptr %35, align 4, !tbaa !14
  %36 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 2
  %37 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %37, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds %struct.Matrix, ptr %10, i32 0, i32 3
  %39 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %39, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds i64, ptr %38, i64 1
  store i64 1, ptr %40, align 8, !tbaa !5
  %41 = getelementptr inbounds [2 x i64], ptr %38, i64 1
  %42 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %42, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i64, ptr %41, i64 1
  %44 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %44, ptr %43, align 8, !tbaa !5
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = add nsw i64 %45, 1
  %47 = ashr i64 %46, 1
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind writable sret(%struct.Matrix) align 8 %9, ptr noundef nonnull align 8 dereferenceable(48) %10, i64 noundef %47)
  %48 = getelementptr inbounds %struct.Matrix, ptr %9, i32 0, i32 3
  %49 = getelementptr inbounds [2 x [2 x i64]], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds [2 x i64], ptr %49, i64 0, i64 0
  %51 = load i64, ptr %50, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 48, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %9) #5
  store i64 %51, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !5
  %54 = srem i64 %52, %53
  store i64 %54, ptr %11, align 8, !tbaa !5
  %55 = load i64, ptr %7, align 8, !tbaa !5
  %56 = load i64, ptr %8, align 8, !tbaa !5
  %57 = srem i64 %55, %56
  store i64 %57, ptr %11, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %63, %32
  %59 = load i64, ptr %11, align 8, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !5
  %61 = icmp sge i64 %59, %60
  br i1 %61, label %62, label %69

62:                                               ; preds = %58
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %64, ptr %7, align 8, !tbaa !5
  %65 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %65, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %7, align 8, !tbaa !5
  %67 = load i64, ptr %8, align 8, !tbaa !5
  %68 = srem i64 %66, %67
  store i64 %68, ptr %11, align 8, !tbaa !5
  br label %58, !llvm.loop !16

69:                                               ; preds = %58
  %70 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %70, ptr %7, align 8, !tbaa !5
  %71 = load i64, ptr %3, align 8, !tbaa !5
  %72 = load i64, ptr %11, align 8, !tbaa !5
  %73 = load i64, ptr %11, align 8, !tbaa !5
  %74 = mul nsw i64 %72, %73
  %75 = sub nsw i64 %71, %74
  %76 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %75)
  %77 = fptosi double %76 to i64
  store i64 %77, ptr %8, align 8, !tbaa !5
  %78 = load i64, ptr %7, align 8, !tbaa !5
  %79 = load i64, ptr %8, align 8, !tbaa !5
  %80 = icmp sle i64 %78, %79
  br i1 %80, label %81, label %87

81:                                               ; preds = %69
  %82 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %83 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 0
  %84 = extractvalue { i64, i64 } %82, 0
  store i64 %84, ptr %83, align 8
  %85 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 1
  %86 = extractvalue { i64, i64 } %82, 1
  store i64 %86, ptr %85, align 8
  br label %93

87:                                               ; preds = %69
  %88 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %89 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 0
  %90 = extractvalue { i64, i64 } %88, 0
  store i64 %90, ptr %89, align 8
  %91 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 1
  %92 = extractvalue { i64, i64 } %88, 1
  store i64 %92, ptr %91, align 8
  br label %93

93:                                               ; preds = %87, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %94 = load { i64, i64 }, ptr %2, align 8
  ret { i64, i64 } %94
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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


; 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, i64, [2 x [2 x i64]] }

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

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

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z3gaox(i64 noundef %0) local_unnamed_addr #3 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca %struct.Matrix, align 8
  %5 = alloca %struct.Matrix, align 8
  %6 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %7 = fptosi double %6 to i64
  %8 = add nsw i64 %0, -1
  %9 = ashr i64 %8, 1
  br label %10

10:                                               ; preds = %10, %1
  %11 = tail call i32 @rand() #5
  %12 = sext i32 %11 to i64
  %13 = srem i64 %12, %7
  %14 = mul nsw i64 %13, %13
  %15 = add nuw nsw i64 %14, 1
  %16 = tail call noundef i64 @_Z7mod_powxxx(i64 noundef %15, i64 noundef %9, i64 noundef %0)
  %17 = icmp eq i64 %16, 1
  br i1 %17, label %10, label %18, !llvm.loop !5

18:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %5) #5
  store i32 2, ptr %5, align 8, !tbaa !7
  %19 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 2, ptr %19, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %0, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 %13, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %5, i64 24
  store i64 1, ptr %22, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %5, i64 32
  store i64 %15, ptr %23, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %5, i64 40
  store i64 %13, ptr %24, align 8, !tbaa !15
  %25 = add nsw i64 %0, 1
  %26 = ashr i64 %25, 1
  call void @_ZN6Matrix3powEx(ptr dead_on_unwind nonnull writable sret(%struct.Matrix) align 8 %4, ptr noundef nonnull align 8 dereferenceable(48) %5, i64 noundef %26)
  %27 = getelementptr inbounds i8, ptr %4, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #5
  %29 = srem i64 %0, %28
  %.not26 = icmp slt i64 %29, %7
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.028 = phi i64 [ %30, %.lr.ph ], [ %29, %18 ]
  %.02327 = phi i64 [ %.028, %.lr.ph ], [ %28, %18 ]
  %30 = srem i64 %.02327, %.028
  %.not = icmp slt i64 %30, %7
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %18
  %.0.lcssa = phi i64 [ %29, %18 ], [ %30, %.lr.ph ]
  store i64 %.0.lcssa, ptr %2, align 8, !tbaa !15
  %31 = mul nsw i64 %.0.lcssa, %.0.lcssa
  %32 = sub nsw i64 %0, %31
  %33 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %32)
  %34 = fptosi double %33 to i64
  store i64 %34, ptr %3, align 8, !tbaa !15
  %.not20 = icmp sgt i64 %.0.lcssa, %34
  br i1 %.not20, label %37, label %35

35:                                               ; preds = %._crit_edge
  %36 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %39

37:                                               ; preds = %._crit_edge
  %38 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %2)
  br label %39

39:                                               ; preds = %37, %35
  %.pn = phi { i64, i64 } [ %36, %35 ], [ %38, %37 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret { i64, i64 } %.pn
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Matrix3powEx(ptr dead_on_unwind noalias writable sret(%struct.Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(48), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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


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