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

; 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
@t = external dso_local global i32, align 4
@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 @t)
  br label %26

26:                                               ; preds = %74, %24
  %27 = load i32, ptr @t, align 4, !tbaa !5
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @t, align 4, !tbaa !5
  %29 = icmp ne i32 %27, 0
  br i1 %29, label %30, label %75

30:                                               ; preds = %26
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 10, ptr @k, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 10001
  br i1 %33, label %34, label %49

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

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

74:                                               ; preds = %49, %34
  br label %26, !llvm.loop !13

75:                                               ; preds = %26
  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
@t = external dso_local global i32, align 4
@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 @t)
  %3 = load i32, ptr @t, align 4, !tbaa !9
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !9
  %.not7 = icmp eq i32 %3, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

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

.lr.ph:                                           ; preds = %1, %48
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 10, ptr @k, align 4, !tbaa !9
  %14 = load i32, ptr @n, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 10001
  br i1 %15, label %16, label %26

16:                                               ; preds = %.lr.ph
  %17 = sext i32 %14 to i64
  %18 = getelementptr inbounds [10001 x x86_fp80], ptr @f, i64 0, i64 %17
  %19 = load x86_fp80, ptr %18, align 16, !tbaa !5
  %20 = fdiv x86_fp80 %19, 0xK4000935D8DDDAAA8B000
  %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.2, 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 %14 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 !9
  %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 !9
  %39 = sitofp i32 %38 to double
  %40 = fsub double %37, %39
  %41 = load i32, ptr @k, align 4, !tbaa !9
  %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.3, i64 noundef %46)
  br label %48

48:                                               ; preds = %26, %16
  %49 = load i32, ptr @t, align 4, !tbaa !9
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr @t, align 4, !tbaa !9
  %.not = icmp eq i32 %49, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %48, %1
  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"}
!13 = distinct !{!13, !12}


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