; LLVM IR from tangjz/acm-icpc :: lydsy (2489)

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

@f = external dso_local global [1501 x x86_fp80], align 16
@x = external dso_local global x86_fp80, align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 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 i32, align 4
  store i32 0, ptr %1, align 4
  store x86_fp80 0xK3FFF8000000000000000, ptr @x, align 16, !tbaa !5
  store x86_fp80 0xK3FFF8000000000000000, ptr getelementptr inbounds ([1501 x x86_fp80], ptr @f, i64 0, i64 1), align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %35, %0
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 1501
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %38

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = xor i32 %11, -1
  %13 = and i32 %12, 1
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %24

15:                                               ; preds = %10
  %16 = load x86_fp80, ptr @x, align 16, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  %19 = sitofp i32 %18 to x86_fp80
  %20 = fmul x86_fp80 %16, %19
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sitofp i32 %21 to x86_fp80
  %23 = fdiv x86_fp80 %20, %22
  store x86_fp80 %23, ptr @x, align 16, !tbaa !5
  br label %24

24:                                               ; preds = %15, %10
  %25 = load i32, ptr %2, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1501 x x86_fp80], ptr @f, i64 0, i64 %27
  %29 = load x86_fp80, ptr %28, align 16, !tbaa !5
  %30 = load x86_fp80, ptr @x, align 16, !tbaa !5
  %31 = fadd x86_fp80 %29, %30
  %32 = load i32, ptr %2, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1501 x x86_fp80], ptr @f, i64 0, i64 %33
  store x86_fp80 %31, ptr %34, align 16, !tbaa !5
  br label %35

35:                                               ; preds = %24
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %2, align 4, !tbaa !9
  br label %6, !llvm.loop !11

38:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %55, %38
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = icmp sle i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %58

45:                                               ; preds = %40
  %46 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1501 x x86_fp80], ptr @f, i64 0, i64 %49
  %51 = load x86_fp80, ptr %50, align 16, !tbaa !5
  %52 = fptrunc x86_fp80 %51 to double
  %53 = fadd double %52, 1.000000e-10
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %47, double noundef %53)
  br label %55

55:                                               ; preds = %45
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !9
  br label %40, !llvm.loop !13

58:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 0
}

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

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

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

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 = { 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 = !{!"long double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@f = external dso_local local_unnamed_addr global [1501 x x86_fp80], align 16
@x = external dso_local local_unnamed_addr global x86_fp80, align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store x86_fp80 0xK3FFF8000000000000000, ptr @x, align 16, !tbaa !5
  store x86_fp80 0xK3FFF8000000000000000, ptr getelementptr inbounds (i8, ptr @f, i64 16), align 16, !tbaa !5
  br label %6

3:                                                ; preds = %._crit_edge16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = load i32, ptr %1, align 4, !tbaa !9
  %.not13 = icmp slt i32 %5, 1
  br i1 %.not13, label %._crit_edge, label %.lr.ph

6:                                                ; preds = %0, %._crit_edge16
  %7 = phi x86_fp80 [ 0xK3FFF8000000000000000, %0 ], [ %19, %._crit_edge16 ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %._crit_edge16 ]
  %8 = phi x86_fp80 [ 0xK3FFF8000000000000000, %0 ], [ %18, %._crit_edge16 ]
  %9 = trunc nuw nsw i64 %indvars.iv to i32
  %10 = and i32 %9, 1
  %.not11.not = icmp eq i32 %10, 0
  br i1 %.not11.not, label %11, label %._crit_edge16

11:                                               ; preds = %6
  %12 = trunc i64 %indvars.iv to i32
  %13 = add i32 %12, -1
  %14 = sitofp i32 %13 to x86_fp80
  %15 = fmul x86_fp80 %8, %14
  %16 = uitofp nneg i32 %9 to x86_fp80
  %17 = fdiv x86_fp80 %15, %16
  store x86_fp80 %17, ptr @x, align 16, !tbaa !5
  br label %._crit_edge16

._crit_edge16:                                    ; preds = %6, %11
  %18 = phi x86_fp80 [ %17, %11 ], [ %8, %6 ]
  %19 = fadd x86_fp80 %7, %18
  %20 = getelementptr inbounds [1501 x x86_fp80], ptr @f, i64 0, i64 %indvars.iv
  store x86_fp80 %19, ptr %20, align 16, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1501
  br i1 %exitcond.not, label %3, label %6, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.014 = phi i32 [ %29, %.lr.ph ], [ 1, %3 ]
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1501 x x86_fp80], ptr @f, i64 0, i64 %23
  %25 = load x86_fp80, ptr %24, align 16, !tbaa !5
  %26 = fptrunc x86_fp80 %25 to double
  %27 = fadd double %26, 1.000000e-10
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.014, double noundef %27)
  %29 = add nuw nsw i32 %.014, 1
  %30 = load i32, ptr %1, align 4, !tbaa !9
  %.not.not = icmp slt i32 %.014, %30
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass