; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1237)

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

@s = external dso_local global [200 x double], align 16
@num = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 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
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %8

8:                                                ; preds = %87, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @num)
  %10 = icmp ne i32 %9, -1
  br i1 %10, label %11, label %88

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  %12 = load double, ptr @num, align 8, !tbaa !9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %15
  store double %12, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  %17 = call i32 @getchar()
  %18 = trunc i32 %17 to i8
  store i8 %18, ptr %3, align 1, !tbaa !11
  %19 = load double, ptr @num, align 8, !tbaa !9
  %20 = fcmp oeq double %19, 0.000000e+00
  br i1 %20, label %21, label %26

21:                                               ; preds = %11
  %22 = load i8, ptr %3, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 10
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 3, ptr %4, align 4
  br label %85

26:                                               ; preds = %21, %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  br label %27

27:                                               ; preds = %65, %26
  br label %28

28:                                               ; preds = %27
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5, ptr noundef @num)
  %30 = load i8, ptr %5, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  switch i32 %31, label %61 [
    i32 43, label %32
    i32 45, label %38
    i32 42, label %45
    i32 47, label %53
  ]

32:                                               ; preds = %28
  %33 = load double, ptr @num, align 8, !tbaa !9
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %36
  store double %33, ptr %37, align 8, !tbaa !9
  br label %61

38:                                               ; preds = %28
  %39 = load double, ptr @num, align 8, !tbaa !9
  %40 = fneg double %39
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %43
  store double %40, ptr %44, align 8, !tbaa !9
  br label %61

45:                                               ; preds = %28
  %46 = load double, ptr @num, align 8, !tbaa !9
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fmul double %51, %46
  store double %52, ptr %50, align 8, !tbaa !9
  br label %61

53:                                               ; preds = %28
  %54 = load double, ptr @num, align 8, !tbaa !9
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = fdiv double %59, %54
  store double %60, ptr %58, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %53, %45, %38, %32, %28
  %62 = call i32 @getchar()
  %63 = icmp eq i32 %62, 10
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  br label %66

65:                                               ; preds = %61
  br label %27, !llvm.loop !12

66:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %79, %66
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  store i32 7, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %82

72:                                               ; preds = %67
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !9
  %77 = load double, ptr %6, align 8, !tbaa !9
  %78 = fadd double %77, %76
  store double %78, ptr %6, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %72
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %7, align 4, !tbaa !5
  br label %67, !llvm.loop !14

82:                                               ; preds = %71
  %83 = load double, ptr %6, align 8, !tbaa !9
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %83)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  store i32 0, ptr %4, align 4
  br label %85

85:                                               ; preds = %82, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %86 = load i32, ptr %4, align 4
  switch i32 %86, label %89 [
    i32 0, label %87
    i32 3, label %88
  ]

87:                                               ; preds = %85
  br label %8, !llvm.loop !15

88:                                               ; preds = %85, %8
  ret i32 0

89:                                               ; preds = %85
  unreachable
}

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: inlinehint mustprogress uwtable
declare i32 @getchar() #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

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


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

@s = external dso_local local_unnamed_addr global [200 x double], align 16
@num = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i8, align 1
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @num)
  %.not21 = icmp eq i32 %2, -1
  br i1 %.not21, label %.thread, label %.lr.ph23

.lr.ph23:                                         ; preds = %0, %._crit_edge
  %3 = load double, ptr @num, align 8, !tbaa !5
  store double %3, ptr @s, align 16, !tbaa !5
  %4 = call i32 @getchar()
  %5 = load double, ptr @num, align 8, !tbaa !5
  %6 = fcmp oeq double %5, 0.000000e+00
  %sext.mask = and i32 %4, 255
  %7 = icmp eq i32 %sext.mask, 10
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %.thread, label %8

8:                                                ; preds = %.lr.ph23
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #4
  br label %9

9:                                                ; preds = %37, %8
  %.016 = phi i32 [ 1, %8 ], [ %.1, %37 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull @num)
  %11 = load i8, ptr %1, align 1, !tbaa !9
  switch i8 %11, label %37 [
    i8 43, label %12
    i8 45, label %17
    i8 42, label %23
    i8 47, label %30
  ]

12:                                               ; preds = %9
  %13 = load double, ptr @num, align 8, !tbaa !5
  %14 = add nsw i32 %.016, 1
  %15 = sext i32 %.016 to i64
  %16 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %15
  store double %13, ptr %16, align 8, !tbaa !5
  br label %37

17:                                               ; preds = %9
  %18 = load double, ptr @num, align 8, !tbaa !5
  %19 = fneg double %18
  %20 = add nsw i32 %.016, 1
  %21 = sext i32 %.016 to i64
  %22 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %21
  store double %19, ptr %22, align 8, !tbaa !5
  br label %37

23:                                               ; preds = %9
  %24 = load double, ptr @num, align 8, !tbaa !5
  %25 = add nsw i32 %.016, -1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fmul double %24, %28
  store double %29, ptr %27, align 8, !tbaa !5
  br label %37

30:                                               ; preds = %9
  %31 = load double, ptr @num, align 8, !tbaa !5
  %32 = add nsw i32 %.016, -1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = fdiv double %35, %31
  store double %36, ptr %34, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %30, %23, %17, %12, %9
  %.1 = phi i32 [ %.016, %9 ], [ %.016, %30 ], [ %.016, %23 ], [ %20, %17 ], [ %14, %12 ]
  %38 = call i32 @getchar()
  %39 = icmp eq i32 %38, 10
  br i1 %39, label %.preheader, label %9, !llvm.loop !10

.preheader:                                       ; preds = %37
  %40 = icmp sgt i32 %.1, 0
  br i1 %40, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %.1 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %41 = icmp ult i32 %.1, 8
  br i1 %41, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.7, %.lr.ph ]
  %.01419 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %65, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %42 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv
  %43 = load double, ptr %42, align 16, !tbaa !5
  %44 = fadd double %.01419, %43
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %45 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = fadd double %44, %46
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %48 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.1
  %49 = load double, ptr %48, align 16, !tbaa !5
  %50 = fadd double %47, %49
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %51 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.2
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = fadd double %50, %52
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %54 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.3
  %55 = load double, ptr %54, align 16, !tbaa !5
  %56 = fadd double %53, %55
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %57 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.4
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = fadd double %56, %58
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %60 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.5
  %61 = load double, ptr %60, align 16, !tbaa !5
  %62 = fadd double %59, %61
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %63 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.next.6
  %64 = load double, ptr %63, align 8, !tbaa !5
  %65 = fadd double %62, %64
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %65, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.7, %.lr.ph ]
  %.01419.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %65, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01419.epil = phi double [ %68, %.lr.ph.epil ], [ %.01419.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %66 = getelementptr inbounds [200 x double], ptr @s, i64 0, i64 %indvars.iv.epil
  %67 = load double, ptr %66, align 8, !tbaa !5
  %68 = fadd double %.01419.epil, %67
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader
  %.014.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %68, %.lr.ph.epil ]
  %69 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %.014.lcssa)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #4
  %70 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @num)
  %.not = icmp eq i32 %70, -1
  br i1 %.not, label %.thread, label %.lr.ph23

.thread:                                          ; preds = %._crit_edge, %.lr.ph23, %0
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #3

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint mustprogress nofree 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


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