; LLVM IR from tangjz/acm-icpc :: lydsy/3738.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 { i32, i64 }
%"struct.std::pair.0" = type { i32, i32 }

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

; 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 uwtable
declare dso_local noundef i32 @_Z7mod_powix(i32 noundef, i64 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_mulii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4calci(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local { i32, i64 } @_Z8mod_factx(i64 noundef %0) #1 {
  %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) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  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 @_ZNSt4pairIixEC2IiiTnNSt9enable_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) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %56

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 { i32, i64 } @_Z8mod_factx(i64 noundef %15)
  %17 = getelementptr inbounds { i32, i64 }, ptr %2, i32 0, i32 0
  %18 = extractvalue { i32, i64 } %16, 0
  store i32 %18, ptr %17, align 8
  %19 = getelementptr inbounds { i32, i64 }, ptr %2, i32 0, i32 1
  %20 = extractvalue { i32, 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 i32, ptr @pp, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = icmp sge i64 %28, %30
  br i1 %31, label %32, label %47

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

47:                                               ; preds = %32, %11
  %48 = load i64, ptr %3, align 8, !tbaa !5
  %49 = add nsw i64 %48, 1
  %50 = trunc i64 %49 to i32
  call void @_Z4calci(i32 noundef %50)
  %51 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !13
  %53 = load i32, ptr @f, align 16, !tbaa !9
  %54 = call noundef i32 @_Z7mod_mulii(i32 noundef %52, i32 noundef %53)
  %55 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 0
  store i32 %54, ptr %55, align 8, !tbaa !13
  br label %56

56:                                               ; preds = %47, %9
  %57 = load { i32, i64 }, ptr %2, align 8
  ret { i32, i64 } %57
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIixEC2IiiTnNSt9enable_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 #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { 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 = !{!"_ZTSSt4pairIixE", !10, i64 0, !6, i64 8}
!13 = !{!12, !10, 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 { i32, 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 i32, align 4
@prod = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [20 x i32], align 16

; 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 uwtable
declare dso_local noundef i32 @_Z7mod_powix(i32 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_mulii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4calci(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local { i32, i64 } @_Z8mod_factx(i64 noundef %0) local_unnamed_addr #1 {
  %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) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  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 @_ZNSt4pairIixEC2IiiTnNSt9enable_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) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %.fca.0.load.pre = load i32, 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 %36

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 { i32, i64 } @_Z8mod_factx(i64 noundef %12)
  %14 = extractvalue { i32, i64 } %13, 0
  %15 = extractvalue { i32, 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 i32, ptr @pp, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %.not = icmp sgt i64 %21, %0
  br i1 %.not, label %30, label %22

22:                                               ; preds = %9
  %23 = load i32, ptr @prod, align 4, !tbaa !5
  %24 = sdiv i64 %0, %21
  %25 = tail call noundef i32 @_Z7mod_powix(i32 noundef %23, i64 noundef %24)
  %26 = tail call noundef i32 @_Z7mod_mulii(i32 noundef %14, i32 noundef %25)
  %27 = load i32, ptr @pp, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = srem i64 %0, %28
  br label %30

30:                                               ; preds = %22, %9
  %31 = phi i32 [ %26, %22 ], [ %14, %9 ]
  %.0 = phi i64 [ %29, %22 ], [ %0, %9 ]
  %32 = trunc i64 %.0 to i32
  %33 = add i32 %32, 1
  tail call void @_Z4calci(i32 noundef %33)
  %34 = load i32, ptr @f, align 16, !tbaa !5
  %35 = tail call noundef i32 @_Z7mod_mulii(i32 noundef %31, i32 noundef %34)
  br label %36

36:                                               ; preds = %30, %7
  %.fca.1.load = phi i64 [ %19, %30 ], [ %.fca.1.load.pre, %7 ]
  %.fca.0.load = phi i32 [ %35, %30 ], [ %.fca.0.load.pre, %7 ]
  %.fca.0.insert = insertvalue { i32, i64 } poison, i32 %.fca.0.load, 0
  %.fca.1.insert = insertvalue { i32, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { i32, 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 #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIixEC2IiiTnNSt9enable_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 #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { 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"}


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