; LLVM IR from tangjz/acm-icpc :: lydsy (2048)

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

@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = sitofp i64 %4 to double
  %6 = fcmp ole double %5, 1.000000e+04
  br i1 %6, label %7, label %24

7:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %20, %7
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = load i64, ptr @n, align 8, !tbaa !5
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %23

14:                                               ; preds = %8
  %15 = load i32, ptr %2, align 4, !tbaa !9
  %16 = sitofp i32 %15 to double
  %17 = fdiv double 5.000000e-01, %16
  %18 = load double, ptr @ans, align 8, !tbaa !11
  %19 = fadd double %18, %17
  store double %19, ptr @ans, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %14
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !9
  br label %8, !llvm.loop !13

23:                                               ; preds = %13
  br label %31

24:                                               ; preds = %0
  %25 = load i64, ptr @n, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  %27 = sitofp i64 %26 to double
  %28 = call double @log(double noundef %27) #4
  %29 = fadd double %28, 0x3FE2788CFC6F802A
  %30 = fmul double 5.000000e-01, %29
  store double %30, ptr @ans, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %24, %23
  %32 = load i64, ptr @m, align 8, !tbaa !5
  %33 = sitofp i64 %32 to double
  %34 = load double, ptr @ans, align 8, !tbaa !11
  %35 = fmul double %34, %33
  store double %35, ptr @ans, align 8, !tbaa !11
  %36 = load double, ptr @ans, align 8, !tbaa !11
  %37 = fsub double %36, 1.000000e-08
  %38 = fptosi double %37 to i32
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %38)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind
declare double @log(double noundef) #3

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse 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 = { "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 willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@ans = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i64, ptr @n, align 8, !tbaa !5
  %3 = icmp slt i64 %2, 10001
  br i1 %3, label %.preheader, label %25

.preheader:                                       ; preds = %0
  %ans.promoted = load double, ptr @ans, align 8, !tbaa !9
  %.not3 = icmp slt i64 %2, 1
  br i1 %.not3, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %xtraiter = and i64 %2, 3
  %4 = icmp ult i64 %2, 4
  br i1 %4, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, 9223372036854775804
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %5 = phi double [ %ans.promoted, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  %7 = uitofp nneg i32 %6 to double
  %8 = fdiv double 5.000000e-01, %7
  %9 = fadd double %8, %5
  %10 = trunc i64 %indvars.iv to i32
  %11 = add i32 %10, 1
  %12 = uitofp nneg i32 %11 to double
  %13 = fdiv double 5.000000e-01, %12
  %14 = fadd double %13, %9
  %15 = trunc i64 %indvars.iv to i32
  %16 = add i32 %15, 2
  %17 = uitofp nneg i32 %16 to double
  %18 = fdiv double 5.000000e-01, %17
  %19 = fadd double %18, %14
  %20 = trunc i64 %indvars.iv to i32
  %21 = add i32 %20, 3
  %22 = uitofp nneg i32 %21 to double
  %23 = fdiv double 5.000000e-01, %22
  %24 = fadd double %23, %19
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

25:                                               ; preds = %0
  %26 = add nuw nsw i64 %2, 1
  %27 = uitofp nneg i64 %26 to double
  %28 = tail call double @log(double noundef %27) #3
  %29 = fadd double %28, 0x3FE2788CFC6F802A
  %30 = fmul double %29, 5.000000e-01
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.unr = phi double [ %ans.promoted, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %31 = phi double [ %35, %.lr.ph.epil ], [ %.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %32 = trunc nuw nsw i64 %indvars.iv.epil to i32
  %33 = uitofp nneg i32 %32 to double
  %34 = fdiv double 5.000000e-01, %33
  %35 = fadd double %34, %31
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !13

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader, %25
  %36 = phi double [ %ans.promoted, %.preheader ], [ %30, %25 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %35, %.lr.ph.epil ]
  %37 = load i64, ptr @m, align 8, !tbaa !5
  %38 = sitofp i64 %37 to double
  %39 = fmul double %36, %38
  store double %39, ptr @ans, align 8, !tbaa !9
  %40 = fadd double %39, -1.000000e-08
  %41 = fptosi double %40 to i32
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %41)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree norecurse 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 = { nofree nounwind "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 nofree nounwind willreturn memory(write) "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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass