; LLVM IR from DionysiosB/CodeForces :: 0200-0299 (205B-LittleElephantAndSorting)

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

@.str = external hidden unnamed_addr constant [4 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 i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  store i64 0, ptr %2, align 8, !tbaa !5
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %8, i64 8)
  %10 = extractvalue { i64, i1 } %9, 1
  %11 = extractvalue { i64, i1 } %9, 0
  %12 = select i1 %10, i64 -1, i64 %11
  %13 = call noalias noundef nonnull ptr @_Znam(i64 noundef %12) #7
  store ptr %13, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %26, %0
  %15 = load i32, ptr %4, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = icmp slt i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %29

20:                                               ; preds = %14
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i64, ptr %21, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %4, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !11
  br label %14, !llvm.loop !13

29:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store i64 0, ptr %5, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = sub nsw i64 %30, 1
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %6, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %66, %29
  %34 = load i32, ptr %6, align 4, !tbaa !11
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %69

37:                                               ; preds = %33
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %38, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = icmp sgt i64 %43, %48
  br i1 %49, label %50, label %65

50:                                               ; preds = %37
  %51 = load ptr, ptr %3, align 8, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !11
  %53 = sub nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i64, ptr %51, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !5
  %62 = sub nsw i64 %56, %61
  %63 = load i64, ptr %5, align 8, !tbaa !15
  %64 = add nsw i64 %63, %62
  store i64 %64, ptr %5, align 8, !tbaa !15
  br label %65

65:                                               ; preds = %50, %37
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %6, align 4, !tbaa !11
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %6, align 4, !tbaa !11
  br label %33, !llvm.loop !17

69:                                               ; preds = %36
  %70 = load i64, ptr %5, align 8, !tbaa !15
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %70)
  %72 = load ptr, ptr %3, align 8, !tbaa !9
  %73 = icmp eq ptr %72, null
  br i1 %73, label %75, label %74

74:                                               ; preds = %69
  call void @_ZdaPv(ptr noundef %72) #8
  br label %75

75:                                               ; preds = %74, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #5

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { nobuiltin 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !14}


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

@.str = external hidden unnamed_addr constant [4 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 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  store i64 0, ptr %1, align 8, !tbaa !5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = icmp ugt i64 %3, 2305843009213693951
  %5 = shl i64 %3, 3
  %6 = select i1 %4, i64 -1, i64 %5
  %7 = call noalias noundef nonnull ptr @_Znam(i64 noundef %6) #7
  %8 = icmp sgt i64 %3, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %3, %0 ], [ %39, %.lr.ph ]
  %9 = trunc i64 %.lcssa to i32
  %.023 = add i32 %9, -1
  %10 = icmp sgt i32 %.023, 0
  br i1 %10, label %.lr.ph28.preheader, label %._crit_edge29

.lr.ph28.preheader:                               ; preds = %._crit_edge
  %11 = zext nneg i32 %.023 to i64
  %12 = and i64 %.lcssa, 4294967295
  %min.iters.check = icmp ult i32 %.023, 10
  br i1 %min.iters.check, label %.lr.ph28.preheader52, label %vector.scevcheck

.lr.ph28.preheader52:                             ; preds = %middle.block, %vector.scevcheck, %.lr.ph28.preheader
  %indvars.iv35.ph = phi i64 [ %12, %vector.scevcheck ], [ %12, %.lr.ph28.preheader ], [ %ind.end, %middle.block ]
  %indvars.iv33.ph = phi i64 [ %11, %vector.scevcheck ], [ %11, %.lr.ph28.preheader ], [ %ind.end42, %middle.block ]
  %.01624.ph = phi i64 [ 0, %vector.scevcheck ], [ 0, %.lr.ph28.preheader ], [ %36, %middle.block ]
  br label %.lr.ph28

vector.scevcheck:                                 ; preds = %.lr.ph28.preheader
  %13 = add nsw i64 %11, -1
  %14 = add i32 %9, -2
  %15 = trunc nsw i64 %13 to i32
  %16 = icmp ult i32 %14, %15
  %17 = icmp ugt i64 %13, 4294967295
  %18 = or i1 %16, %17
  br i1 %18, label %.lr.ph28.preheader52, label %vector.ph

vector.ph:                                        ; preds = %vector.scevcheck
  %n.vec = and i64 %11, 2147483644
  %ind.end = sub nsw i64 %12, %n.vec
  %ind.end42 = and i64 %11, 3
  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> [ zeroinitializer, %vector.ph ], [ %33, %vector.body ]
  %vec.phi44 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %34, %vector.body ]
  %offset.idx = sub i64 %.lcssa, %index
  %offset.idx45 = sub i64 %11, %index
  %19 = add i64 %offset.idx, 4294967294
  %20 = and i64 %19, 4294967295
  %21 = getelementptr inbounds i64, ptr %7, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 -8
  %23 = getelementptr inbounds i8, ptr %21, i64 -24
  %wide.load = load <2 x i64>, ptr %22, align 8, !tbaa !5
  %reverse = shufflevector <2 x i64> %wide.load, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %wide.load46 = load <2 x i64>, ptr %23, align 8, !tbaa !5
  %reverse47 = shufflevector <2 x i64> %wide.load46, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %24 = getelementptr inbounds i64, ptr %7, i64 %offset.idx45
  %25 = getelementptr inbounds i8, ptr %24, i64 -8
  %26 = getelementptr inbounds i8, ptr %24, i64 -24
  %wide.load48 = load <2 x i64>, ptr %25, align 8, !tbaa !5
  %reverse49 = shufflevector <2 x i64> %wide.load48, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %wide.load50 = load <2 x i64>, ptr %26, align 8, !tbaa !5
  %reverse51 = shufflevector <2 x i64> %wide.load50, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %27 = icmp sgt <2 x i64> %reverse, %reverse49
  %28 = icmp sgt <2 x i64> %reverse47, %reverse51
  %29 = sub nsw <2 x i64> %reverse, %reverse49
  %30 = sub nsw <2 x i64> %reverse47, %reverse51
  %31 = select <2 x i1> %27, <2 x i64> %29, <2 x i64> zeroinitializer
  %32 = select <2 x i1> %28, <2 x i64> %30, <2 x i64> zeroinitializer
  %33 = add <2 x i64> %31, %vec.phi
  %34 = add <2 x i64> %32, %vec.phi44
  %index.next = add nuw i64 %index, 4
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %34, %33
  %36 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %11
  br i1 %cmp.n, label %._crit_edge29, label %.lr.ph28.preheader52

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %37 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv
  %38 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %37)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i64, ptr %1, align 8, !tbaa !5
  %40 = icmp sgt i64 %39, %indvars.iv.next
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge29:                                    ; preds = %.lr.ph28, %middle.block, %._crit_edge
  %.016.lcssa = phi i64 [ 0, %._crit_edge ], [ %36, %middle.block ], [ %.1, %.lr.ph28 ]
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.016.lcssa)
  call void @_ZdaPv(ptr noundef nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret i32 0

.lr.ph28:                                         ; preds = %.lr.ph28.preheader52, %.lr.ph28
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph28 ], [ %indvars.iv35.ph, %.lr.ph28.preheader52 ]
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.lr.ph28 ], [ %indvars.iv33.ph, %.lr.ph28.preheader52 ]
  %.01624 = phi i64 [ %.1, %.lr.ph28 ], [ %.01624.ph, %.lr.ph28.preheader52 ]
  %42 = add i64 %indvars.iv35, 4294967294
  %43 = and i64 %42, 4294967295
  %44 = getelementptr inbounds i64, ptr %7, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv33
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = icmp sgt i64 %45, %47
  %49 = sub nsw i64 %45, %47
  %50 = select i1 %48, i64 %49, i64 0
  %.1 = add nsw i64 %50, %.01624
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %51 = icmp ugt i64 %indvars.iv33, 1
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, -1
  br i1 %51, label %.lr.ph28, label %._crit_edge29, !llvm.loop !14
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) 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) #1

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #4

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

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 = { 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 = { nobuiltin allocsize(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 = { nobuiltin 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass