; LLVM IR from tangjz/acm-icpc :: lydsy/2832.ll (Z4calcx)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [201 x %"struct.std::pair"], align 16
@m = external dso_local global i64, align 8
@dt = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z4calcx(i64 noundef %0) #0 {
  %2 = alloca %"struct.std::pair", align 8
  %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 i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load i64, ptr @m, align 8, !tbaa !5
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = load i64, ptr @dt, align 8, !tbaa !5
  %14 = mul nsw i64 %12, %13
  %15 = sub nsw i64 %11, %14
  store i64 %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %82, %1
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr @n, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  br label %85

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %23
  %25 = getelementptr inbounds %"struct.std::pair", ptr %24, i32 0, i32 0
  %26 = load i64, ptr %25, align 16, !tbaa !11
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %36

29:                                               ; preds = %21
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %32
  %34 = getelementptr inbounds %"struct.std::pair", ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 16, !tbaa !11
  br label %37

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36, %29
  %38 = phi i64 [ %35, %29 ], [ -1, %36 ]
  %39 = sub nsw i64 %26, %38
  store i64 %39, ptr %8, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !5
  %41 = load i64, ptr @m, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = sdiv i64 %41, %42
  %44 = icmp sle i64 %40, %43
  br i1 %44, label %45, label %49

45:                                               ; preds = %37
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = mul nsw i64 %47, %46
  store i64 %48, ptr %8, align 8, !tbaa !5
  br label %52

49:                                               ; preds = %37
  %50 = load i64, ptr @m, align 8, !tbaa !5
  %51 = add nsw i64 %50, 1
  store i64 %51, ptr %8, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %49, %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %55
  %57 = getelementptr inbounds %"struct.std::pair", ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !13
  %59 = sdiv i64 %53, %58
  store i64 %59, ptr %10, align 8, !tbaa !5
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %61 = load i64, ptr %60, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  store i64 %61, ptr %9, align 8, !tbaa !5
  %62 = load i64, ptr %9, align 8, !tbaa !5
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr %4, align 8, !tbaa !5
  %65 = load i64, ptr %9, align 8, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %67
  %69 = getelementptr inbounds %"struct.std::pair", ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !13
  %71 = mul nsw i64 %65, %70
  %72 = load i64, ptr %5, align 8, !tbaa !5
  %73 = sub nsw i64 %72, %71
  store i64 %73, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %9, align 8, !tbaa !5
  %75 = load i64, ptr %8, align 8, !tbaa !5
  %76 = icmp slt i64 %74, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %52
  store i32 2, ptr %7, align 4
  br label %79

78:                                               ; preds = %52
  store i32 0, ptr %7, align 4
  br label %79

79:                                               ; preds = %78, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %80 = load i32, ptr %7, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %6, align 4, !tbaa !9
  br label %16, !llvm.loop !14

85:                                               ; preds = %79, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %86

86:                                               ; preds = %85
  %87 = call { i64, i64 } @_ZSt9make_pairIRxS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %88 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 0
  %89 = extractvalue { i64, i64 } %87, 0
  store i64 %89, ptr %88, align 8
  %90 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 1
  %91 = extractvalue { i64, i64 } %87, 1
  store i64 %91, ptr %90, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %92 = load { i64, i64 }, ptr %2, align 8
  ret { i64, i64 } %92
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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.end.p0(i64 immarg, ptr nocapture) #1

; 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)) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!12, !6, i64 0}
!12 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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.std::pair" = type { i64, i64 }

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [201 x %"struct.std::pair"], align 16
@m = external dso_local local_unnamed_addr global i64, align 8
@dt = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z4calcx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %6 = load i64, ptr @m, align 8, !tbaa !5
  %7 = load i64, ptr @dt, align 8, !tbaa !5
  %8 = mul nsw i64 %7, %0
  %9 = sub nsw i64 %6, %8
  store i64 %9, ptr %3, align 8, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %._crit_edge

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %13 = load i64, ptr @a, align 16, !tbaa !11
  %14 = add nsw i64 %13, 1
  %15 = sdiv i64 %6, %0
  %.not16.peel.not = icmp slt i64 %13, %15
  %16 = add nsw i64 %6, 1
  %17 = mul nsw i64 %14, %0
  %storemerge.peel = select i1 %.not16.peel.not, i64 %17, i64 %16
  store i64 %storemerge.peel, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %18 = load i64, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 8, !tbaa !13
  %19 = sdiv i64 %9, %18
  store i64 %19, ptr %5, align 8, !tbaa !5
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %21 = load i64, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  store i64 %21, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 8, !tbaa !13
  %23 = mul nsw i64 %22, %21
  %24 = sub nsw i64 %9, %23
  store i64 %24, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %.not17.peel = icmp sge i64 %21, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %26 = load i32, ptr @n, align 4
  %27 = icmp sgt i32 %26, 1
  %or.cond = select i1 %.not17.peel, i1 %27, i1 false
  br i1 %or.cond, label %.lr.ph.peel.next, label %._crit_edge

28:                                               ; preds = %.lr.ph.peel.next
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i32, ptr @n, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next, %30
  br i1 %31, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !14

.lr.ph.peel.next:                                 ; preds = %12, %28
  %32 = phi i64 [ %49, %28 ], [ %21, %12 ]
  %33 = phi i64 [ %52, %28 ], [ %24, %12 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 1, %12 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %34 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv
  %35 = load i64, ptr %34, align 16, !tbaa !11
  %36 = add nsw i64 %indvars.iv, -1
  %37 = getelementptr inbounds [201 x %"struct.std::pair"], ptr @a, i64 0, i64 %36
  %38 = load i64, ptr %37, align 16, !tbaa !11
  %39 = sub nsw i64 %35, %38
  %40 = load i64, ptr @m, align 8, !tbaa !5
  %41 = sdiv i64 %40, %0
  %.not16 = icmp sgt i64 %39, %41
  %42 = add nsw i64 %40, 1
  %43 = mul nsw i64 %39, %0
  %storemerge = select i1 %.not16, i64 %42, i64 %43
  store i64 %storemerge, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %44 = getelementptr inbounds i8, ptr %34, i64 8
  %45 = load i64, ptr %44, align 8, !tbaa !13
  %46 = sdiv i64 %33, %45
  store i64 %46, ptr %5, align 8, !tbaa !5
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %48 = load i64, ptr %47, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  %49 = add nsw i64 %32, %48
  store i64 %49, ptr %2, align 8, !tbaa !5
  %50 = load i64, ptr %44, align 8, !tbaa !13
  %51 = mul nsw i64 %50, %48
  %52 = sub nsw i64 %33, %51
  store i64 %52, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %.not17 = icmp slt i64 %48, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br i1 %.not17, label %._crit_edge, label %28

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %28, %12, %1
  %54 = 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)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret { i64, i64 } %54
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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.end.p0(i64 immarg, ptr nocapture) #1

; 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 #0

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!12, !6, i64 0}
!12 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass