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

; 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.std::pair.0" = type { i32, i32 }

@p = external dso_local global i32, align 4
@pp = external dso_local global i64, align 8
@prod = external dso_local global i64, align 8
@f = external dso_local global [20 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxx(i64 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 nounwind uwtable
declare dso_local noundef i64 @_Z7mod_powxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4calcx(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z8mod_factx(i64 noundef %0) #2 {
  %2 = alloca %"struct.std::pair", align 8
  %3 = alloca i64, align 8
  %4 = alloca %"struct.std::pair.0", align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  %10 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  store i64 %10, ptr %4, align 4
  call void @_ZNSt4pairIxxEC2IiiTnNSt9enable_ifIXaaclsr6_PCCFPIT_T0_EE22_MoveConstructiblePairIS3_S4_EEclsr6_PCCFPIS3_S4_EE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS_IS3_S4_E(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %52

11:                                               ; preds = %1
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr @p, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = sdiv i64 %12, %14
  %16 = call { i64, i64 } @_Z8mod_factx(i64 noundef %15)
  %17 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 0
  %18 = extractvalue { i64, i64 } %16, 0
  store i64 %18, ptr %17, align 8
  %19 = getelementptr inbounds { i64, i64 }, ptr %2, i32 0, i32 1
  %20 = extractvalue { i64, i64 } %16, 1
  store i64 %20, ptr %19, align 8
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr @p, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = sdiv i64 %21, %23
  %25 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = add nsw i64 %26, %24
  store i64 %27, ptr %25, align 8, !tbaa !11
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = load i64, ptr @pp, align 8, !tbaa !5
  %30 = icmp sge i64 %28, %29
  br i1 %30, label %31, label %44

31:                                               ; preds = %11
  %32 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !13
  %34 = load i64, ptr @prod, align 8, !tbaa !5
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr @pp, align 8, !tbaa !5
  %37 = sdiv i64 %35, %36
  %38 = call noundef i64 @_Z7mod_powxx(i64 noundef %34, i64 noundef %37)
  %39 = call noundef i64 @_Z7mod_mulxx(i64 noundef %33, i64 noundef %38)
  %40 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  store i64 %39, ptr %40, align 8, !tbaa !13
  %41 = load i64, ptr @pp, align 8, !tbaa !5
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = srem i64 %42, %41
  store i64 %43, ptr %3, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %31, %11
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = add nsw i64 %45, 1
  call void @_Z4calcx(i64 noundef %46)
  %47 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !13
  %49 = load i64, ptr @f, align 16, !tbaa !5
  %50 = call noundef i64 @_Z7mod_mulxx(i64 noundef %48, i64 noundef %49)
  %51 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  store i64 %50, ptr %51, align 8, !tbaa !13
  br label %52

52:                                               ; preds = %44, %9
  %53 = load { i64, i64 }, ptr %2, align 8
  ret { i64, i64 } %53
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IiiTnNSt9enable_ifIXaaclsr6_PCCFPIT_T0_EE22_MoveConstructiblePairIS3_S4_EEclsr6_PCCFPIS3_S4_EE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS_IS3_S4_E(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #0 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 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 8}
!12 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 0}


; 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 }
%"struct.std::pair.0" = type { i32, i32 }

@p = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local local_unnamed_addr global i64, align 8
@prod = external dso_local local_unnamed_addr global i64, align 8
@f = external dso_local local_unnamed_addr global [20 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxx(i64 noundef, 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 nounwind uwtable
declare dso_local noundef i64 @_Z7mod_powxx(i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z8mod_factx(i64 noundef %0) local_unnamed_addr #2 {
  %2 = alloca %"struct.std::pair", align 8
  %3 = alloca %"struct.std::pair.0", align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = icmp eq i64 %0, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  %8 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  store i64 %8, ptr %3, align 8
  call void @_ZNSt4pairIxxEC2IiiTnNSt9enable_ifIXaaclsr6_PCCFPIT_T0_EE22_MoveConstructiblePairIS3_S4_EEclsr6_PCCFPIS3_S4_EE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS_IS3_S4_E(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %.fca.0.load.pre = load i64, ptr %2, align 8
  %.fca.1.gep.phi.trans.insert = getelementptr inbounds i8, ptr %2, i64 8
  %.fca.1.load.pre = load i64, ptr %.fca.1.gep.phi.trans.insert, align 8
  br label %33

9:                                                ; preds = %1
  %10 = load i32, ptr @p, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = sdiv i64 %0, %11
  %13 = tail call { i64, i64 } @_Z8mod_factx(i64 noundef %12)
  %14 = extractvalue { i64, i64 } %13, 0
  %15 = extractvalue { i64, i64 } %13, 1
  %16 = load i32, ptr @p, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = sdiv i64 %0, %17
  %19 = add nsw i64 %18, %15
  %20 = load i64, ptr @pp, align 8, !tbaa !9
  %.not = icmp sgt i64 %20, %0
  br i1 %.not, label %28, label %21

21:                                               ; preds = %9
  %22 = load i64, ptr @prod, align 8, !tbaa !9
  %23 = sdiv i64 %0, %20
  %24 = tail call noundef i64 @_Z7mod_powxx(i64 noundef %22, i64 noundef %23)
  %25 = tail call noundef i64 @_Z7mod_mulxx(i64 noundef %14, i64 noundef %24)
  %26 = load i64, ptr @pp, align 8, !tbaa !9
  %27 = srem i64 %0, %26
  br label %28

28:                                               ; preds = %21, %9
  %29 = phi i64 [ %25, %21 ], [ %14, %9 ]
  %.0 = phi i64 [ %27, %21 ], [ %0, %9 ]
  %30 = add nsw i64 %.0, 1
  tail call void @_Z4calcx(i64 noundef %30)
  %31 = load i64, ptr @f, align 16, !tbaa !9
  %32 = tail call noundef i64 @_Z7mod_mulxx(i64 noundef %29, i64 noundef %31)
  br label %33

33:                                               ; preds = %28, %7
  %.fca.1.load = phi i64 [ %19, %28 ], [ %.fca.1.load.pre, %7 ]
  %.fca.0.load = phi i64 [ %32, %28 ], [ %.fca.0.load.pre, %7 ]
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.fca.0.load, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { i64, i64 } %.fca.1.insert
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IiiTnNSt9enable_ifIXaaclsr6_PCCFPIT_T0_EE22_MoveConstructiblePairIS3_S4_EEclsr6_PCCFPIS3_S4_EE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS_IS3_S4_E(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #0 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 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 = !{!"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}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass