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

; 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
@x = external dso_local global [100001 x i32], align 16
@y = external dso_local global [100001 x i32], align 16
@a = external dso_local global [100001 x double], align 16
@b = external dso_local global [100001 x double], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5checkii(i32 noundef, i32 noundef) #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

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

8:                                                ; preds = %48, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %51

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %15
  call void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %16)
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100001 x i32], ptr @y, i64 0, i64 %18
  call void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %19)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100001 x i32], ptr @y, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %23, %27
  %29 = sitofp i32 %28 to double
  %30 = fdiv double %29, 2.000000e+00
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x double], ptr @a, i64 0, i64 %32
  store double %30, ptr %33, align 8, !tbaa !9
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i32], ptr @y, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sub nsw i32 %37, %41
  %43 = sitofp i32 %42 to double
  %44 = fdiv double %43, 2.000000e+00
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x double], ptr @b, i64 0, i64 %46
  store double %44, ptr %47, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %13
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

51:                                               ; preds = %12
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr @a, i64 %53
  call void @_ZSt4sortIPdEvT_S1_(ptr noundef @a, ptr noundef %54)
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr @b, i64 %56
  call void @_ZSt4sortIPdEvT_S1_(ptr noundef @b, ptr noundef %57)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = ashr i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100001 x double], ptr @a, i64 0, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = load i32, ptr @n, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = ashr i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x double], ptr @b, i64 0, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !9
  %70 = fadd double %63, %69
  store double %70, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %71 = load i32, ptr @n, align 4, !tbaa !5
  %72 = sub nsw i32 %71, 1
  %73 = ashr i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100001 x double], ptr @a, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !9
  %77 = load i32, ptr @n, align 4, !tbaa !5
  %78 = sub nsw i32 %77, 1
  %79 = ashr i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100001 x double], ptr @b, i64 0, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !9
  %83 = fsub double %76, %82
  store double %83, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 -1, ptr %5, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %108, %51
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = icmp sle i32 %85, 1
  br i1 %86, label %88, label %87

87:                                               ; preds = %84
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %111

88:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 -1, ptr %7, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %104, %88
  %90 = load i32, ptr %7, align 4, !tbaa !5
  %91 = icmp sle i32 %90, 1
  br i1 %91, label %93, label %92

92:                                               ; preds = %89
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %107

93:                                               ; preds = %89
  %94 = load double, ptr %3, align 8, !tbaa !9
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = sitofp i32 %95 to double
  %97 = fadd double %94, %96
  %98 = fptosi double %97 to i32
  %99 = load double, ptr %4, align 8, !tbaa !9
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = sitofp i32 %100 to double
  %102 = fadd double %99, %101
  %103 = fptosi double %102 to i32
  call void @_Z5checkii(i32 noundef %98, i32 noundef %103)
  br label %104

104:                                              ; preds = %93
  %105 = load i32, ptr %7, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %7, align 4, !tbaa !5
  br label %89, !llvm.loop !13

107:                                              ; preds = %92
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %5, align 4, !tbaa !5
  br label %84, !llvm.loop !14

111:                                              ; preds = %87
  %112 = load i64, ptr @ans, align 8, !tbaa !15
  %113 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %112)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  %114 = load i32, ptr %1, align 4
  ret i32 %114
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { "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 #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 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}


; 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
@x = external dso_local global [100001 x i32], align 16
@y = external dso_local global [100001 x i32], align 16
@a = external dso_local global [100001 x double], align 16
@b = external dso_local global [100001 x double], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5checkii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) @n)
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %1 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %44, %.lr.ph ]
  %3 = getelementptr inbounds double, ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPdEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %3)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds double, ptr @b, i64 %5
  tail call void @_ZSt4sortIPdEvT_S1_(ptr noundef nonnull @b, ptr noundef nonnull %6)
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  %9 = ashr i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100001 x double], ptr @a, i64 0, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds [100001 x double], ptr @b, i64 0, i64 %10
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = fadd double %12, %14
  %16 = fsub double %12, %14
  %17 = fadd double %16, -1.000000e+00
  %18 = fptosi double %17 to i32
  %19 = fadd double %15, -1.000000e+00
  %20 = fptosi double %19 to i32
  tail call void @_Z5checkii(i32 noundef %20, i32 noundef %18)
  %21 = fadd double %16, 0.000000e+00
  %22 = fptosi double %21 to i32
  tail call void @_Z5checkii(i32 noundef %20, i32 noundef %22)
  %23 = fadd double %16, 1.000000e+00
  %24 = fptosi double %23 to i32
  tail call void @_Z5checkii(i32 noundef %20, i32 noundef %24)
  %25 = fadd double %15, 0.000000e+00
  %26 = fptosi double %25 to i32
  tail call void @_Z5checkii(i32 noundef %26, i32 noundef %18)
  tail call void @_Z5checkii(i32 noundef %26, i32 noundef %22)
  tail call void @_Z5checkii(i32 noundef %26, i32 noundef %24)
  %27 = fadd double %15, 1.000000e+00
  %28 = fptosi double %27 to i32
  tail call void @_Z5checkii(i32 noundef %28, i32 noundef %18)
  tail call void @_Z5checkii(i32 noundef %28, i32 noundef %22)
  tail call void @_Z5checkii(i32 noundef %28, i32 noundef %24)
  %29 = load i64, ptr @ans, align 8, !tbaa !11
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %29)
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %31 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %indvars.iv
  tail call void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %31)
  %32 = getelementptr inbounds [100001 x i32], ptr @y, i64 0, i64 %indvars.iv
  tail call void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %32)
  %33 = load i32, ptr %31, align 4, !tbaa !5
  %34 = load i32, ptr %32, align 4, !tbaa !5
  %35 = add nsw i32 %34, %33
  %36 = sitofp i32 %35 to double
  %37 = fmul double %36, 5.000000e-01
  %38 = getelementptr inbounds [100001 x double], ptr @a, i64 0, i64 %indvars.iv
  store double %37, ptr %38, align 8, !tbaa !9
  %39 = sub nsw i32 %33, %34
  %40 = sitofp i32 %39 to double
  %41 = fmul double %40, 5.000000e-01
  %42 = getelementptr inbounds [100001 x double], ptr @b, i64 0, i64 %indvars.iv
  store double %41, ptr %42, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6getintIiEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; 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 #3

attributes #0 = { 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 #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 = { 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 #3 = { 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" }

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


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