; LLVM IR from tangjz/acm-icpc :: self_training/2014-12-07 (F)

; 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
@m = external dso_local global i32, align 4
@x = external dso_local global double, align 8
@sum = 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 [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
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %77, %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 %82

8:                                                ; preds = %4
  store i32 0, ptr @m, align 4, !tbaa !5
  store double 0.000000e+00, ptr @sum, align 8, !tbaa !9
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  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 = %33, %8
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = shl i32 %12, 1
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %10
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  %18 = load double, ptr @x, align 8, !tbaa !9
  %19 = fptosi double %18 to i32
  %20 = sitofp i32 %19 to double
  %21 = load double, ptr @x, align 8, !tbaa !9
  %22 = fsub double %21, %20
  store double %22, ptr @x, align 8, !tbaa !9
  %23 = load double, ptr @x, align 8, !tbaa !9
  %24 = fcmp ogt double %23, 1.000000e-08
  br i1 %24, label %25, label %29

25:                                               ; preds = %16
  %26 = load double, ptr @x, align 8, !tbaa !9
  %27 = load double, ptr @sum, align 8, !tbaa !9
  %28 = fadd double %27, %26
  store double %28, ptr @sum, align 8, !tbaa !9
  br label %32

29:                                               ; preds = %16
  %30 = load i32, ptr @m, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @m, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %29, %25
  br label %33

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

36:                                               ; preds = %15
  %37 = load i32, ptr @m, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = sub nsw i32 %41, %42
  %44 = sitofp i32 %43 to double
  %45 = load double, ptr @sum, align 8, !tbaa !9
  %46 = fsub double %45, %44
  store double %46, ptr @sum, align 8, !tbaa !9
  br label %49

47:                                               ; preds = %36
  %48 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %48, ptr @m, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %47, %40
  br label %50

50:                                               ; preds = %59, %49
  %51 = load double, ptr @sum, align 8, !tbaa !9
  %52 = fsub double %51, 1.000000e+00
  %53 = fcmp ogt double %52, 1.000000e-08
  br i1 %53, label %54, label %57

54:                                               ; preds = %50
  %55 = load i32, ptr @m, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br label %57

57:                                               ; preds = %54, %50
  %58 = phi i1 [ false, %50 ], [ %56, %54 ]
  br i1 %58, label %59, label %64

59:                                               ; preds = %57
  %60 = load double, ptr @sum, align 8, !tbaa !9
  %61 = fsub double %60, 1.000000e+00
  store double %61, ptr @sum, align 8, !tbaa !9
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = add nsw i32 %62, -1
  store i32 %63, ptr @m, align 4, !tbaa !5
  br label %50, !llvm.loop !13

64:                                               ; preds = %57
  %65 = load i32, ptr @m, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %77

67:                                               ; preds = %64
  %68 = load double, ptr @sum, align 8, !tbaa !9
  %69 = fsub double %68, 1.000000e+00
  %70 = call noundef double @_ZSt3absd(double noundef %69)
  %71 = load double, ptr @sum, align 8, !tbaa !9
  %72 = fcmp olt double %70, %71
  br i1 %72, label %73, label %77

73:                                               ; preds = %67
  %74 = load double, ptr @sum, align 8, !tbaa !9
  %75 = fsub double %74, 1.000000e+00
  %76 = call noundef double @_ZSt3absd(double noundef %75)
  store double %76, ptr @sum, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %73, %67, %64
  %78 = load double, ptr @sum, align 8, !tbaa !9
  %79 = call noundef double @_ZSt3absd(double noundef %78)
  %80 = fadd double %79, 1.000000e-08
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %80)
  br label %4, !llvm.loop !14

82:                                               ; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

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

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 = { 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 = { 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}
!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
@m = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local global double, align 8
@sum = 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 [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; 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
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %._crit_edge20, label %.lr.ph19

.lr.ph19:                                         ; preds = %0, %53
  store i32 0, ptr @m, align 4, !tbaa !5
  store double 0.000000e+00, ptr @sum, align 8, !tbaa !9
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = shl i32 %5, 1
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %22, %.lr.ph19
  %.lcssa = phi i32 [ %5, %.lr.ph19 ], [ %24, %22 ]
  %8 = load i32, ptr @m, align 4
  %9 = icmp slt i32 %8, %.lcssa
  br i1 %9, label %27, label %32

.lr.ph:                                           ; preds = %.lr.ph19, %22
  %.09 = phi i32 [ %23, %22 ], [ 0, %.lr.ph19 ]
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %11 = load double, ptr @x, align 8, !tbaa !9
  %12 = fptosi double %11 to i32
  %13 = sitofp i32 %12 to double
  %14 = fsub double %11, %13
  store double %14, ptr @x, align 8, !tbaa !9
  %15 = fcmp ogt double %14, 1.000000e-08
  br i1 %15, label %16, label %19

16:                                               ; preds = %.lr.ph
  %17 = load double, ptr @sum, align 8, !tbaa !9
  %18 = fadd double %14, %17
  store double %18, ptr @sum, align 8, !tbaa !9
  br label %22

19:                                               ; preds = %.lr.ph
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @m, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %16, %19
  %23 = add nuw nsw i32 %.09, 1
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = shl i32 %24, 1
  %26 = icmp slt i32 %23, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !11

27:                                               ; preds = %._crit_edge
  %28 = sub nsw i32 %.lcssa, %8
  %29 = sitofp i32 %28 to double
  %30 = load double, ptr @sum, align 8, !tbaa !9
  %31 = fsub double %30, %29
  store double %31, ptr @sum, align 8, !tbaa !9
  br label %33

32:                                               ; preds = %._crit_edge
  store i32 %.lcssa, ptr @m, align 4, !tbaa !5
  %sum.promoted.pre = load double, ptr @sum, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %32, %27
  %sum.promoted = phi double [ %sum.promoted.pre, %32 ], [ %31, %27 ]
  %.pr = phi i32 [ %.lcssa, %32 ], [ %8, %27 ]
  %34 = fadd double %sum.promoted, -1.000000e+00
  %35 = fcmp ogt double %34, 1.000000e-08
  %36 = icmp ne i32 %.pr, 0
  %37 = and i1 %35, %36
  br i1 %37, label %.lr.ph11, label %45

.lr.ph11:                                         ; preds = %33, %.lr.ph11
  %38 = phi double [ %41, %.lr.ph11 ], [ %34, %33 ]
  %39 = phi i32 [ %40, %.lr.ph11 ], [ %.pr, %33 ]
  %40 = add nsw i32 %39, -1
  %41 = fadd double %38, -1.000000e+00
  %42 = fcmp ogt double %41, 1.000000e-08
  %43 = icmp ne i32 %40, 0
  %44 = select i1 %42, i1 %43, i1 false
  br i1 %44, label %.lr.ph11, label %._crit_edge12, !llvm.loop !13

._crit_edge12:                                    ; preds = %.lr.ph11
  store double %38, ptr @sum, align 8, !tbaa !9
  store i32 %40, ptr @m, align 4, !tbaa !5
  br i1 %43, label %46, label %53

45:                                               ; preds = %33
  br i1 %36, label %46, label %53

46:                                               ; preds = %._crit_edge12, %45
  %.lcssa828 = phi double [ %41, %._crit_edge12 ], [ %34, %45 ]
  %47 = tail call noundef double @_ZSt3absd(double noundef %.lcssa828)
  %48 = load double, ptr @sum, align 8, !tbaa !9
  %49 = fcmp olt double %47, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %46
  %51 = fadd double %48, -1.000000e+00
  %52 = tail call noundef double @_ZSt3absd(double noundef %51)
  store double %52, ptr @sum, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %._crit_edge12, %50, %46, %45
  %54 = phi double [ %52, %50 ], [ %48, %46 ], [ %sum.promoted, %45 ], [ %38, %._crit_edge12 ]
  %55 = tail call noundef double @_ZSt3absd(double noundef %54)
  %56 = fadd double %55, 1.000000e-08
  %57 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %56)
  %58 = load i32, ptr @t, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %58, 0
  br i1 %.not, label %._crit_edge20, label %.lr.ph19, !llvm.loop !14

._crit_edge20:                                    ; preds = %53, %0
  ret i32 0
}

; 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 @_ZSt3absd(double noundef) local_unnamed_addr #2

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

!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}
!14 = distinct !{!14, !12}


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