; LLVM IR from tangjz/acm-icpc :: 51nod (1058)

; 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 [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 10, ptr @k, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 10001
  br i1 %27, label %28, label %43

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

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

68:                                               ; preds = %43, %28
  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"}


; 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 local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [10001 x x86_fp80], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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 %5

1:                                                ; preds = %5
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 10, ptr @k, align 4, !tbaa !9
  %3 = load i32, ptr @n, align 4, !tbaa !9
  %4 = icmp slt i32 %3, 10001
  br i1 %4, label %13, label %23

5:                                                ; preds = %0, %5
  %6 = phi x86_fp80 [ %.pre, %0 ], [ %11, %5 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %5 ]
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  %8 = uitofp nneg i32 %7 to double
  %9 = tail call double @log(double noundef %8) #4
  %10 = fpext double %9 to x86_fp80
  %11 = fadd x86_fp80 %6, %10
  %12 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %indvars.iv
  store x86_fp80 %11, ptr %12, 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 %1, label %5, !llvm.loop !11

13:                                               ; preds = %1
  %14 = sext i32 %3 to i64
  %15 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %14
  %16 = load x86_fp80, ptr %15, align 16, !tbaa !5
  %17 = fdiv x86_fp80 %16, 0xK4000935D8DDDAAA8B000
  %18 = fadd x86_fp80 %17, 0xK3FE4ABCC77118461D000
  %19 = fptrunc x86_fp80 %18 to double
  %20 = tail call double @llvm.ceil.f64(double %19)
  %21 = fptosi double %20 to i32
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %21)
  br label %45

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

45:                                               ; preds = %23, %13
  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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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