; LLVM IR from tangjz/acm-icpc :: poj (1877)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [1000 x double], align 16
@x = external dso_local global double, align 8
@sum = external dso_local global double, align 8
@ans = external dso_local global double, align 8
@cnt = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [45 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 i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %121, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %10 = icmp eq i32 %9, 2
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %3, align 4
  br label %124

12:                                               ; preds = %8
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %3, align 4
  br label %124

19:                                               ; preds = %15, %12
  %20 = load i32, ptr @m, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %20
  store i32 %22, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %33, %19
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %30
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %31)
  br label %33

33:                                               ; preds = %28
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !9

36:                                               ; preds = %27
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr @a, i64 %38
  call void @_ZSt4sortIPdEvT_S1_(ptr noundef @a, ptr noundef %39)
  %40 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x)
  %41 = load double, ptr @x, align 8, !tbaa !11
  %42 = fdiv double %41, 1.000000e+02
  store double %42, ptr @x, align 8, !tbaa !11
  store double 0.000000e+00, ptr @cnt, align 8, !tbaa !11
  store double 0.000000e+00, ptr @ans, align 8, !tbaa !11
  store double 0.000000e+00, ptr @sum, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %94, %36
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr @n, align 4, !tbaa !5
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 8, ptr %3, align 4
  br label %97

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fsub double %52, %57
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sitofp i32 %59 to double
  %61 = fmul double %58, %60
  store double %61, ptr %7, align 8, !tbaa !11
  %62 = load double, ptr %7, align 8, !tbaa !11
  %63 = load double, ptr @sum, align 8, !tbaa !11
  %64 = fadd double %62, %63
  %65 = load double, ptr @x, align 8, !tbaa !11
  %66 = fcmp ogt double %64, %65
  br i1 %66, label %67, label %86

67:                                               ; preds = %48
  %68 = load double, ptr @x, align 8, !tbaa !11
  %69 = load double, ptr @sum, align 8, !tbaa !11
  %70 = fsub double %68, %69
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = sitofp i32 %71 to double
  %73 = fdiv double %70, %72
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = sub nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = fadd double %73, %78
  store double %79, ptr @ans, align 8, !tbaa !11
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = sitofp i32 %80 to double
  %82 = fmul double %81, 1.000000e+02
  %83 = load i32, ptr @n, align 4, !tbaa !5
  %84 = sitofp i32 %83 to double
  %85 = fdiv double %82, %84
  store double %85, ptr @cnt, align 8, !tbaa !11
  store i32 8, ptr %3, align 4
  br label %91

86:                                               ; preds = %48
  %87 = load double, ptr %7, align 8, !tbaa !11
  %88 = load double, ptr @sum, align 8, !tbaa !11
  %89 = fadd double %88, %87
  store double %89, ptr @sum, align 8, !tbaa !11
  br label %90

90:                                               ; preds = %86
  store i32 0, ptr %3, align 4
  br label %91

91:                                               ; preds = %90, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %92 = load i32, ptr %3, align 4
  switch i32 %92, label %97 [
    i32 0, label %93
  ]

93:                                               ; preds = %91
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %6, align 4, !tbaa !5
  br label %43, !llvm.loop !15

97:                                               ; preds = %91, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %98

98:                                               ; preds = %97
  %99 = load double, ptr @cnt, align 8, !tbaa !11
  %100 = fcmp une double %99, 0.000000e+00
  br i1 %100, label %114, label %101

101:                                              ; preds = %98
  %102 = load double, ptr @x, align 8, !tbaa !11
  %103 = load double, ptr @sum, align 8, !tbaa !11
  %104 = fsub double %102, %103
  %105 = load i32, ptr @n, align 4, !tbaa !5
  %106 = sitofp i32 %105 to double
  %107 = fdiv double %104, %106
  %108 = load i32, ptr @n, align 4, !tbaa !5
  %109 = sub nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %110
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = fadd double %107, %112
  store double %113, ptr @ans, align 8, !tbaa !11
  store double 1.000000e+02, ptr @cnt, align 8, !tbaa !11
  br label %114

114:                                              ; preds = %101, %98
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %115)
  %117 = load double, ptr @ans, align 8, !tbaa !11
  %118 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, double noundef %117)
  %119 = load double, ptr @cnt, align 8, !tbaa !11
  %120 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, double noundef %119)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  br label %121

121:                                              ; preds = %114
  %122 = load i32, ptr %2, align 4, !tbaa !5
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !16

124:                                              ; preds = %18, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %125

125:                                              ; preds = %124
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPdEvT_S1_(ptr noundef, ptr noundef) #3

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

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


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [1000 x double], align 16
@x = external dso_local global double, align 8
@sum = external dso_local local_unnamed_addr global double, align 8
@ans = external dso_local local_unnamed_addr global double, align 8
@cnt = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: mustprogress norecurse 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 @n, ptr noundef nonnull @m)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph34, label %._crit_edge35

.lr.ph34:                                         ; preds = %0, %48
  %.032 = phi i32 [ %54, %48 ], [ 1, %0 ]
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp ne i32 %3, 0
  %5 = load i32, ptr @m, align 4
  %6 = icmp ne i32 %5, 0
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %7, label %._crit_edge35

7:                                                ; preds = %.lr.ph34
  %8 = mul nsw i32 %5, %3
  store i32 %8, ptr @n, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %7
  %.pre48 = sext i32 %8 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre48, %.._crit_edge_crit_edge ], [ %19, %.lr.ph ]
  %10 = getelementptr inbounds double, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPdEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %10)
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x)
  %12 = load double, ptr @x, align 8, !tbaa !9
  %13 = fdiv double %12, 1.000000e+02
  store double %13, ptr @x, align 8, !tbaa !9
  store double 0.000000e+00, ptr @sum, align 8, !tbaa !9
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 1
  br i1 %15, label %.lr.ph30.preheader, label %thread-pre-split.thread

.lr.ph30.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %14 to i64
  %.pre = load double, ptr @a, align 16, !tbaa !9
  br label %.lr.ph30

.lr.ph:                                           ; preds = %7, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %7 ]
  %16 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %indvars.iv
  %17 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %31
  %21 = phi double [ %.pre, %.lr.ph30.preheader ], [ %24, %31 ]
  %indvars.iv45 = phi i64 [ 1, %.lr.ph30.preheader ], [ %indvars.iv.next46, %31 ]
  %22 = phi double [ 0.000000e+00, %.lr.ph30.preheader ], [ %29, %31 ]
  %23 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %indvars.iv45
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fsub double %24, %21
  %26 = trunc nuw nsw i64 %indvars.iv45 to i32
  %27 = uitofp nneg i32 %26 to double
  %28 = fmul double %25, %27
  %29 = fadd double %22, %28
  %30 = fcmp ule double %29, %13
  br i1 %30, label %31, label %thread-pre-split

31:                                               ; preds = %.lr.ph30
  store double %29, ptr @sum, align 8, !tbaa !9
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count
  br i1 %exitcond.not, label %thread-pre-split.thread, label %.lr.ph30, !llvm.loop !13

thread-pre-split:                                 ; preds = %.lr.ph30
  %32 = fsub double %13, %22
  %33 = fdiv double %32, %27
  %34 = fadd double %21, %33
  store double %34, ptr @ans, align 8, !tbaa !9
  %35 = fmul double %27, 1.000000e+02
  %36 = sitofp i32 %14 to double
  %37 = fdiv double %35, %36
  store double %37, ptr @cnt, align 8, !tbaa !9
  %38 = fcmp une double %37, 0.000000e+00
  br i1 %38, label %48, label %thread-pre-split.thread

thread-pre-split.thread:                          ; preds = %31, %._crit_edge, %thread-pre-split
  %39 = phi double [ %22, %thread-pre-split ], [ 0.000000e+00, %._crit_edge ], [ %29, %31 ]
  %40 = fsub double %13, %39
  %41 = sitofp i32 %14 to double
  %42 = fdiv double %40, %41
  %43 = add nsw i32 %14, -1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000 x double], ptr @a, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = fadd double %46, %42
  store double %47, ptr @ans, align 8, !tbaa !9
  store double 1.000000e+02, ptr @cnt, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %thread-pre-split.thread, %thread-pre-split
  %49 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.032)
  %50 = load double, ptr @ans, align 8, !tbaa !9
  %51 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, double noundef %50)
  %52 = load double, ptr @cnt, align 8, !tbaa !9
  %53 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, double noundef %52)
  %54 = add nuw nsw i32 %.032, 1
  %55 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %56 = icmp eq i32 %55, 2
  br i1 %56, label %.lr.ph34, label %._crit_edge35, !llvm.loop !14

._crit_edge35:                                    ; preds = %48, %.lr.ph34, %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 uwtable
declare dso_local void @_ZSt4sortIPdEvT_S1_(ptr noundef, ptr 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 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 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: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass