; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2020/第一场/H.ll (Z9get_valuex)

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

; 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
define dso_local noundef i64 @_Z9get_valuex(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  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 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %30, %1
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = sitofp i32 %9 to double
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %11)
  %13 = fcmp ole double %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %33

15:                                               ; preds = %8
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = sdiv i64 %16, %18
  store i64 %19, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = sdiv i64 %21, %23
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %24, %26
  %28 = add nsw i64 %20, %27
  %29 = srem i64 %28, 1000000007
  store i64 %29, ptr %3, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %15
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !11

33:                                               ; preds = %14
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = mul nsw i64 2, %34
  %36 = srem i64 %35, 1000000007
  store i64 %36, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %37 = load i64, ptr %2, align 8, !tbaa !5
  %38 = call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %37)
  %39 = fadd double %38, 1.000000e+00
  %40 = fptosi double %39 to i64
  store i64 %40, ptr %7, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %70, %33
  %42 = load i64, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = icmp sle i64 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %73

46:                                               ; preds = %41
  %47 = load i64, ptr %2, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = sdiv i64 %47, %48
  store i64 %49, ptr %4, align 8, !tbaa !5
  %50 = load i64, ptr %2, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = sdiv i64 %50, %51
  store i64 %52, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = srem i64 %54, 1000000007
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = sub nsw i64 %56, %57
  %59 = add nsw i64 %58, 1
  %60 = srem i64 %59, 1000000007
  %61 = mul nsw i64 %55, %60
  %62 = srem i64 %61, 1000000007
  %63 = load i64, ptr %7, align 8, !tbaa !5
  %64 = load i64, ptr %6, align 8, !tbaa !5
  %65 = add nsw i64 %63, %64
  %66 = srem i64 %65, 1000000007
  %67 = mul nsw i64 %62, %66
  %68 = add nsw i64 %53, %67
  %69 = srem i64 %68, 1000000007
  store i64 %69, ptr %3, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %46
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %7, align 8, !tbaa !5
  br label %41, !llvm.loop !13

73:                                               ; preds = %45
  %74 = load i64, ptr %3, align 8, !tbaa !5
  %75 = mul nsw i64 %74, 500000004
  %76 = srem i64 %75, 1000000007
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %76
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef) #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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -1000000006, 1000000007) i64 @_Z9get_valuex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %3 = fcmp ult double %2, 1.000000e+00
  br i1 %3, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %4 = shl nsw i64 %12, 1
  %5 = srem i64 %4, 1000000007
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.026.lcssa = phi i64 [ 0, %1 ], [ %5, %._crit_edge.loopexit ]
  %6 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %7 = fadd double %6, 1.000000e+00
  %8 = fptosi double %7 to i64
  %.not31 = icmp sgt i64 %8, %0
  br i1 %.not31, label %._crit_edge36, label %.lr.ph35

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.02628 = phi i64 [ %12, %.lr.ph ], [ 0, %1 ]
  %9 = srem i64 %0, %indvars.iv
  %10 = add i64 %.02628, %0
  %11 = sub i64 %10, %9
  %12 = srem i64 %11, 1000000007
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = trunc nuw i64 %indvars.iv.next to i32
  %14 = uitofp nneg i32 %13 to double
  %15 = tail call noundef double @_ZSt4sqrtIxEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i64 noundef %0)
  %16 = fcmp ult double %15, %14
  br i1 %16, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !5

._crit_edge36:                                    ; preds = %.lr.ph35, %._crit_edge
  %.1.lcssa = phi i64 [ %.026.lcssa, %._crit_edge ], [ %.1, %.lr.ph35 ]
  %17 = mul nsw i64 %.1.lcssa, 500000004
  %18 = srem i64 %17, 1000000007
  ret i64 %18

.lr.ph35:                                         ; preds = %._crit_edge, %.lr.ph35
  %.133 = phi i64 [ %.1, %.lr.ph35 ], [ %.026.lcssa, %._crit_edge ]
  %.032 = phi i64 [ %30, %.lr.ph35 ], [ %8, %._crit_edge ]
  %19 = sdiv i64 %0, %.032
  %20 = sdiv i64 %0, %19
  %21 = srem i64 %19, 1000000007
  %reass.sub = sub i64 %20, %.032
  %22 = add i64 %reass.sub, 1
  %23 = srem i64 %22, 1000000007
  %24 = mul nsw i64 %23, %21
  %25 = srem i64 %24, 1000000007
  %26 = add nsw i64 %20, %.032
  %27 = srem i64 %26, 1000000007
  %28 = mul nsw i64 %25, %27
  %29 = add nsw i64 %28, %.133
  %30 = add nsw i64 %20, 1
  %.1 = srem i64 %29, 1000000007
  %.not.not = icmp slt i64 %20, %0
  br i1 %.not.not, label %.lr.ph35, label %._crit_edge36, !llvm.loop !7
}

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

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

!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 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass