; LLVM IR from tangjz/acm-icpc :: lydsy/5225.ll (Z4facti)

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

@_ZL1C = external hidden global double, align 8
@_ZZ4factiE2mx = external hidden global i32, align 4
@_ZZ4factiE1f = external hidden global [1001 x double], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z4facti(i32 noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sge i32 %4, 1001
  br i1 %5, label %6, label %18

6:                                                ; preds = %1
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sitofp i32 %7 to double
  %9 = fadd double %8, 5.000000e-01
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = call noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %10)
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sitofp i32 %12 to double
  %14 = fneg double %13
  %15 = call double @llvm.fmuladd.f64(double %9, double %11, double %14)
  %16 = load double, ptr @_ZL1C, align 8, !tbaa !9
  %17 = fadd double %15, %16
  store double %17, ptr %2, align 8
  br label %43

18:                                               ; preds = %1
  br label %19

19:                                               ; preds = %35, %18
  %20 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %23, label %38

23:                                               ; preds = %19
  %24 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %30 = call noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %29)
  %31 = fadd double %28, %30
  %32 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %33
  store double %31, ptr %34, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %23
  %36 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  br label %19, !llvm.loop !11

38:                                               ; preds = %19
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  store double %42, ptr %2, align 8
  br label %43

43:                                               ; preds = %38, %6
  %44 = load double, ptr %2, align 8
  ret double %44
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@_ZL1C = external hidden local_unnamed_addr global double, align 8
@_ZZ4factiE2mx = external hidden local_unnamed_addr global i32, align 4
@_ZZ4factiE1f = external hidden local_unnamed_addr global [1001 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z4facti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, 1000
  br i1 %2, label %4, label %.preheader

.preheader:                                       ; preds = %1
  %3 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %.not8 = icmp sgt i32 %3, %0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

4:                                                ; preds = %1
  %5 = uitofp nneg i32 %0 to double
  %6 = fadd double %5, 5.000000e-01
  %7 = tail call noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %8 = fneg double %5
  %9 = tail call double @llvm.fmuladd.f64(double %6, double %7, double %8)
  %10 = load double, ptr @_ZL1C, align 8, !tbaa !9
  %11 = fadd double %9, %10
  br label %26

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %12 = phi i32 [ %22, %.lr.ph ], [ %3, %.preheader ]
  %13 = add nsw i32 %12, -1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = tail call noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %12)
  %18 = fadd double %16, %17
  %19 = load i32, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %20
  store double %18, ptr %21, align 8, !tbaa !9
  %22 = add nsw i32 %19, 1
  store i32 %22, ptr @_ZZ4factiE2mx, align 4, !tbaa !5
  %.not.not = icmp slt i32 %19, %0
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %23 = sext i32 %0 to i64
  %24 = getelementptr inbounds [1001 x double], ptr @_ZZ4factiE1f, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %._crit_edge, %4
  %.0 = phi double [ %11, %4 ], [ %25, %._crit_edge ]
  ret double %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3logIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass