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

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

@_ZL2pi = external hidden global x86_fp80, align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@f = external dso_local global [10001 x x86_fp80], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %21, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 10001
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %10
  %12 = load x86_fp80, ptr %11, align 16, !tbaa !9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sitofp i32 %13 to double
  %15 = call double @log(double noundef %14) #5
  %16 = fpext double %15 to x86_fp80
  %17 = fadd x86_fp80 %12, %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %19
  store x86_fp80 %17, ptr %20, align 16, !tbaa !9
  br label %21

21:                                               ; preds = %7
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !11

24:                                               ; preds = %6
  br label %25

25:                                               ; preds = %71, %24
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  %27 = icmp ne i32 %26, -1
  br i1 %27, label %28, label %72

28:                                               ; preds = %25
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp slt i32 %29, 10001
  br i1 %30, label %31, label %46

31:                                               ; preds = %28
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %33
  %35 = load x86_fp80, ptr %34, align 16, !tbaa !9
  %36 = load i32, ptr @k, align 4, !tbaa !5
  %37 = sitofp i32 %36 to double
  %38 = call double @log(double noundef %37) #5
  %39 = fpext double %38 to x86_fp80
  %40 = fdiv x86_fp80 %35, %39
  %41 = fadd x86_fp80 %40, 0xK3FE4ABCC77118461D000
  %42 = fptrunc x86_fp80 %41 to double
  %43 = call double @llvm.ceil.f64(double %42)
  %44 = fptosi double %43 to i32
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %44)
  br label %71

46:                                               ; preds = %28
  %47 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !9
  %48 = fmul x86_fp80 0xK40008000000000000000, %47
  %49 = load i32, ptr @n, align 4, !tbaa !5
  %50 = sitofp i32 %49 to x86_fp80
  %51 = fmul x86_fp80 %48, %50
  %52 = fptrunc x86_fp80 %51 to double
  %53 = call double @log(double noundef %52) #5
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = sitofp i32 %54 to double
  %56 = load i32, ptr @n, align 4, !tbaa !5
  %57 = sitofp i32 %56 to double
  %58 = call double @log(double noundef %57) #5
  %59 = fmul double %55, %58
  %60 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %53, double %59)
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = sitofp i32 %61 to double
  %63 = fsub double %60, %62
  %64 = load i32, ptr @k, align 4, !tbaa !5
  %65 = sitofp i32 %64 to double
  %66 = call double @log(double noundef %65) #5
  %67 = fdiv double %63, %66
  %68 = fptosi double %67 to i64
  %69 = add nsw i64 %68, 1
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %69)
  br label %71

71:                                               ; preds = %46, %31
  br label %25, !llvm.loop !13

72:                                               ; preds = %25
  ret i32 0
}

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

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

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

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 double", !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"

@_ZL2pi = external hidden local_unnamed_addr global x86_fp80, align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@f = external dso_local local_unnamed_addr global [10001 x x86_fp80], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %.pre = load x86_fp80, ptr @f, align 16, !tbaa !5
  br label %2

.preheader:                                       ; preds = %2
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %.not7 = icmp eq i32 %1, -1
  br i1 %.not7, label %._crit_edge, label %.lr.ph

2:                                                ; preds = %0, %2
  %3 = phi x86_fp80 [ %.pre, %0 ], [ %8, %2 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %2 ]
  %4 = trunc nuw nsw i64 %indvars.iv to i32
  %5 = uitofp nneg i32 %4 to double
  %6 = tail call double @log(double noundef %5) #4
  %7 = fpext double %6 to x86_fp80
  %8 = fadd x86_fp80 %3, %7
  %9 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %indvars.iv
  store x86_fp80 %8, ptr %9, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10001
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %48
  %10 = load i32, ptr @n, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 10001
  br i1 %11, label %12, label %26

12:                                               ; preds = %.lr.ph
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %13
  %15 = load x86_fp80, ptr %14, align 16, !tbaa !5
  %16 = load i32, ptr @k, align 4, !tbaa !11
  %17 = sitofp i32 %16 to double
  %18 = tail call double @log(double noundef %17) #4
  %19 = fpext double %18 to x86_fp80
  %20 = fdiv x86_fp80 %15, %19
  %21 = fadd x86_fp80 %20, 0xK3FE4ABCC77118461D000
  %22 = fptrunc x86_fp80 %21 to double
  %23 = tail call double @llvm.ceil.f64(double %22)
  %24 = fptosi double %23 to i32
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %24)
  br label %48

26:                                               ; preds = %.lr.ph
  %27 = load x86_fp80, ptr @_ZL2pi, align 16, !tbaa !5
  %28 = fmul x86_fp80 %27, 0xK40008000000000000000
  %29 = uitofp nneg i32 %10 to x86_fp80
  %30 = fmul x86_fp80 %28, %29
  %31 = fptrunc x86_fp80 %30 to double
  %32 = tail call double @log(double noundef %31) #4
  %33 = load i32, ptr @n, align 4, !tbaa !11
  %34 = sitofp i32 %33 to double
  %35 = tail call double @log(double noundef %34) #4
  %36 = fmul double %35, %34
  %37 = tail call double @llvm.fmuladd.f64(double %32, double 5.000000e-01, double %36)
  %38 = load i32, ptr @n, align 4, !tbaa !11
  %39 = sitofp i32 %38 to double
  %40 = fsub double %37, %39
  %41 = load i32, ptr @k, align 4, !tbaa !11
  %42 = sitofp i32 %41 to double
  %43 = tail call double @log(double noundef %42) #4
  %44 = fdiv double %40, %43
  %45 = fptosi double %44 to i64
  %46 = add nsw i64 %45, 1
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %46)
  br label %48

48:                                               ; preds = %26, %12
  %49 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %.not = icmp eq i32 %49, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %48, %.preheader
  ret i32 0
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.ceil.f64(double) #3

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

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 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}


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