; LLVM IR from tangjz/acm-icpc :: hdu (4653)

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

@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@ans = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %37, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %41

8:                                                ; preds = %4
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !9
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p, ptr noundef @n, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %34, %8
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @k, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %37

15:                                               ; preds = %10
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sub nsw i32 %16, %17
  %19 = load i32, ptr @p, align 4, !tbaa !5
  %20 = mul nsw i32 %18, %19
  %21 = sitofp i32 %20 to double
  %22 = call double @log(double noundef %21) #4
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  %26 = load i32, ptr @p, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = add nsw i32 %27, 1
  %29 = sitofp i32 %28 to double
  %30 = call double @log(double noundef %29) #4
  %31 = fsub double %22, %30
  %32 = load double, ptr @ans, align 8, !tbaa !9
  %33 = fadd double %32, %31
  store double %33, ptr @ans, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %15
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

37:                                               ; preds = %14
  %38 = load double, ptr @ans, align 8, !tbaa !9
  %39 = call double @exp(double noundef %38) #4
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %39)
  br label %4, !llvm.loop !13

41:                                               ; preds = %4
  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: nounwind
declare double @log(double noundef) #3

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

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

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

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 = !{!"int", !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, !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"

@t = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not7 = icmp eq i32 %2, 0
  br i1 %.not7, label %._crit_edge10, label %.lr.ph9

.lr.ph9:                                          ; preds = %0, %._crit_edge
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !9
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %.not45 = icmp slt i32 %5, 0
  br i1 %.not45, label %.lr.ph9.._crit_edge_crit_edge, label %.lr.ph

.lr.ph9.._crit_edge_crit_edge:                    ; preds = %.lr.ph9
  %.pre = load double, ptr @ans, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph9.._crit_edge_crit_edge
  %6 = phi double [ %.pre, %.lr.ph9.._crit_edge_crit_edge ], [ %26, %.lr.ph ]
  %7 = tail call double @exp(double noundef %6) #3
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %7)
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge10, label %.lr.ph9, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph9, %.lr.ph
  %.06 = phi i32 [ %27, %.lr.ph ], [ 0, %.lr.ph9 ]
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sub nsw i32 %11, %.06
  %13 = load i32, ptr @p, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = sitofp i32 %14 to double
  %16 = tail call double @log(double noundef %15) #3
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sub nsw i32 %17, %.06
  %19 = load i32, ptr @p, align 4, !tbaa !5
  %20 = mul nsw i32 %18, %19
  %21 = add nsw i32 %20, 1
  %22 = sitofp i32 %21 to double
  %23 = tail call double @log(double noundef %22) #3
  %24 = fsub double %16, %23
  %25 = load double, ptr @ans, align 8, !tbaa !9
  %26 = fadd double %25, %24
  store double %26, ptr @ans, align 8, !tbaa !9
  %27 = add nuw nsw i32 %.06, 1
  %28 = load i32, ptr @k, align 4, !tbaa !5
  %.not4.not = icmp slt i32 %.06, %28
  br i1 %.not4.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge10:                                    ; preds = %._crit_edge, %0
  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

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

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 = !{!"int", !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, !12}


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