; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (994)

; 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
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %71, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %6 = icmp ne i32 %5, -1
  br i1 %6, label %7, label %75

7:                                                ; preds = %4
  store i64 0, ptr @ans, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %18, %7
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %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) #4
  br label %21

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr @x, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !9
  br label %8, !llvm.loop !11

21:                                               ; preds = %12
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr @x, i64 %23
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @x, ptr noundef %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %68, %21
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = load i32, ptr @n, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %71

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load i32, ptr @n, align 4, !tbaa !9
  %36 = ashr i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp slt i32 %34, %39
  br i1 %40, label %41, label %52

41:                                               ; preds = %30
  %42 = load i32, ptr @n, align 4, !tbaa !9
  %43 = ashr i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = sub nsw i32 %46, %50
  br label %63

52:                                               ; preds = %30
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = load i32, ptr @n, align 4, !tbaa !9
  %58 = ashr i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = sub nsw i32 %56, %61
  br label %63

63:                                               ; preds = %52, %41
  %64 = phi i32 [ %51, %41 ], [ %62, %52 ]
  %65 = sext i32 %64 to i64
  %66 = load i64, ptr @ans, align 8, !tbaa !5
  %67 = add nsw i64 %66, %65
  store i64 %67, ptr @ans, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %63
  %69 = load i32, ptr %3, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %3, align 4, !tbaa !9
  br label %25, !llvm.loop !13

71:                                               ; preds = %29
  %72 = load i64, ptr @ans, align 8, !tbaa !5
  %73 = shl i64 %72, 1
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %73)
  br label %4, !llvm.loop !14

75:                                               ; 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 uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr 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 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 = !{!"long long", !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}
!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"

@n = external dso_local global i32, align 4
@x = external dso_local global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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)
  %.not20 = icmp eq i32 %1, -1
  br i1 %.not20, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %0, %._crit_edge._crit_edge
  store i64 0, ptr @ans, align 8, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !9
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.lr.ph22.._crit_edge_crit_edge

.lr.ph22.._crit_edge_crit_edge:                   ; preds = %.lr.ph22
  %.pre30 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph22.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre30, %.lr.ph22.._crit_edge_crit_edge ], [ %27, %.lr.ph ]
  %4 = getelementptr inbounds i32, ptr @x, i64 %.pre-phi
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @x, ptr noundef nonnull %4)
  %5 = load i32, ptr @n, align 4, !tbaa !9
  %6 = icmp sgt i32 %5, 0
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !5
  br i1 %6, label %.lr.ph17, label %._crit_edge._crit_edge

.lr.ph17:                                         ; preds = %._crit_edge
  %7 = lshr i32 %5, 1
  %8 = zext nneg i32 %7 to i64
  %9 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph17
  %indvars.iv27.ph = phi i64 [ 0, %.lr.ph17 ], [ %n.vec, %middle.block ]
  %.ph = phi i64 [ %ans.promoted, %.lr.ph17 ], [ %23, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph17
  %n.vec = and i64 %wide.trip.count, 2147483644
  %11 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %ans.promoted, i64 0
  %broadcast.splatinsert = insertelement <2 x i32> poison, i32 %10, i64 0
  %broadcast.splat = shufflevector <2 x i32> %broadcast.splatinsert, <2 x i32> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %11, %vector.ph ], [ %20, %vector.body ]
  %vec.phi33 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %21, %vector.body ]
  %12 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %wide.load = load <2 x i32>, ptr %12, align 16, !tbaa !9
  %wide.load34 = load <2 x i32>, ptr %13, align 8, !tbaa !9
  %14 = sub nsw <2 x i32> %wide.load, %broadcast.splat
  %15 = sub nsw <2 x i32> %wide.load34, %broadcast.splat
  %16 = tail call <2 x i32> @llvm.abs.v2i32(<2 x i32> %14, i1 true)
  %17 = tail call <2 x i32> @llvm.abs.v2i32(<2 x i32> %15, i1 true)
  %18 = zext nneg <2 x i32> %16 to <2 x i64>
  %19 = zext nneg <2 x i32> %17 to <2 x i64>
  %20 = add <2 x i64> %vec.phi, %18
  %21 = add <2 x i64> %vec.phi33, %19
  %index.next = add nuw i64 %index, 4
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %21, %20
  %23 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge18, label %scalar.ph.preheader

.lr.ph:                                           ; preds = %.lr.ph22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph22 ]
  %24 = getelementptr inbounds i32, ptr @x, i64 %indvars.iv
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %24)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @n, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge18:                                    ; preds = %scalar.ph, %middle.block
  %.lcssa32 = phi i64 [ %23, %middle.block ], [ %39, %scalar.ph ]
  store i64 %.lcssa32, ptr @ans, align 8, !tbaa !5
  br label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge, %._crit_edge18
  %29 = phi i64 [ %.lcssa32, %._crit_edge18 ], [ %ans.promoted, %._crit_edge ]
  %30 = shl i64 %29, 1
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %30)
  %32 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %.not = icmp eq i32 %32, -1
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !16

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %scalar.ph ], [ %indvars.iv27.ph, %scalar.ph.preheader ]
  %33 = phi i64 [ %39, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %34 = getelementptr inbounds [100001 x i32], ptr @x, i64 0, i64 %indvars.iv27
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = sub nsw i32 %35, %10
  %37 = tail call i32 @llvm.abs.i32(i32 %36, i1 true)
  %38 = zext nneg i32 %37 to i64
  %39 = add nsw i64 %33, %38
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next28, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge18, label %scalar.ph, !llvm.loop !17

._crit_edge23:                                    ; preds = %._crit_edge._crit_edge, %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 @_ZSt4sortIPiEvT_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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i32> @llvm.abs.v2i32(<2 x i32>, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

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" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 long", !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, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12, !14, !13}


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