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

; 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
@n = 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 [17 x i8], align 1
@_ZL3dig = external hidden constant [17 x i8], align 16

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %69, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @t, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %72

12:                                               ; preds = %7
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  store i32 %15, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %49, %12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %54

21:                                               ; preds = %16
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = shl i32 %23, 3
  %25 = or i32 %24, 1
  %26 = call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %22, i32 noundef %25)
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = shl i32 %28, 3
  %30 = or i32 %29, 4
  %31 = call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %27, i32 noundef %30)
  %32 = fmul double 2.000000e+00, %31
  %33 = fneg double %32
  %34 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %26, double %33)
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = shl i32 %36, 3
  %38 = or i32 %37, 5
  %39 = call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %35, i32 noundef %38)
  %40 = fsub double %34, %39
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = shl i32 %42, 3
  %44 = or i32 %43, 6
  %45 = call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %41, i32 noundef %44)
  %46 = fsub double %40, %45
  %47 = load double, ptr @ans, align 8, !tbaa !9
  %48 = fadd double %47, %46
  store double %48, ptr @ans, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %21
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %16, !llvm.loop !11

54:                                               ; preds = %20
  %55 = load double, ptr @ans, align 8, !tbaa !9
  %56 = call double @llvm.floor.f64(double %55)
  %57 = load double, ptr @ans, align 8, !tbaa !9
  %58 = fsub double %57, %56
  store double %58, ptr @ans, align 8, !tbaa !9
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = load i32, ptr @n, align 4, !tbaa !5
  %61 = load double, ptr @ans, align 8, !tbaa !9
  %62 = fmul double %61, 1.600000e+01
  %63 = fptosi double %62 to i32
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [17 x i8], ptr @_ZL3dig, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = sext i8 %66 to i32
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %59, i32 noundef %60, i32 noundef %67)
  br label %69

69:                                               ; preds = %54
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !14

72:                                               ; preds = %11
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z4calciii(i32 noundef, i32 noundef, i32 noundef) #3

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { inlinehint mustprogress 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 #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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !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
@n = 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 [17 x i8], align 1
@_ZL3dig = external hidden local_unnamed_addr constant [17 x i8], align 16

; Function Attrs: mustprogress 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
  %.not18 = icmp slt i32 %2, 1
  br i1 %.not18, label %._crit_edge22, label %.lr.ph21

._crit_edge22:                                    ; preds = %._crit_edge, %0
  ret i32 0

.lr.ph21:                                         ; preds = %0, %._crit_edge
  %.01519 = phi i32 [ %16, %._crit_edge ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !9
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph21
  %6 = phi double [ 0.000000e+00, %.lr.ph21 ], [ %32, %.lr.ph ]
  %.lcssa = phi i32 [ %4, %.lr.ph21 ], [ %34, %.lr.ph ]
  %7 = tail call double @llvm.floor.f64(double %6)
  %8 = fsub double %6, %7
  store double %8, ptr @ans, align 8, !tbaa !9
  %9 = fmul double %8, 1.600000e+01
  %10 = fptosi double %9 to i32
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [17 x i8], ptr @_ZL3dig, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.01519, i32 noundef %.lcssa, i32 noundef %14)
  %16 = add nuw nsw i32 %.01519, 1
  %17 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01519, %17
  br i1 %.not.not, label %.lr.ph21, label %._crit_edge22, !llvm.loop !12

.lr.ph:                                           ; preds = %.lr.ph21, %.lr.ph
  %.0.in17 = phi i32 [ %.0, %.lr.ph ], [ %4, %.lr.ph21 ]
  %.01416 = phi i32 [ %33, %.lr.ph ], [ 0, %.lr.ph21 ]
  %.0 = add nsw i32 %.0.in17, -1
  %18 = shl i32 %.01416, 3
  %19 = or disjoint i32 %18, 1
  %20 = tail call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %.0, i32 noundef %19)
  %21 = or disjoint i32 %18, 4
  %22 = tail call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %.0, i32 noundef %21)
  %23 = fmul double %22, -2.000000e+00
  %24 = tail call double @llvm.fmuladd.f64(double %20, double 4.000000e+00, double %23)
  %25 = or disjoint i32 %18, 5
  %26 = tail call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %.0, i32 noundef %25)
  %27 = fsub double %24, %26
  %28 = or disjoint i32 %18, 6
  %29 = tail call noundef double @_Z4calciii(i32 noundef 16, i32 noundef %.0, i32 noundef %28)
  %30 = fsub double %27, %29
  %31 = load double, ptr @ans, align 8, !tbaa !9
  %32 = fadd double %31, %30
  store double %32, ptr @ans, align 8, !tbaa !9
  %33 = add nuw nsw i32 %.01416, 1
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z4calciii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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

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

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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