; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codesprints 2017/Codesprint 9/Problem F/usaxena.ll (Z8process2i)

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

%"struct.std::pair" = type { i32, i32 }

@P = external dso_local global [200005 x %"struct.std::pair"], align 16
@M = external dso_local global [200005 x [19 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8process2i(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %16, %1
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %19

9:                                                ; preds = %5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %13
  %15 = getelementptr inbounds [19 x i32], ptr %14, i64 0, i64 0
  store i32 %11, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %9
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !9

19:                                               ; preds = %5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %99, %19
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = shl i32 1, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = icmp sle i32 %22, %23
  br i1 %24, label %25, label %102

25:                                               ; preds = %20
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %95, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = shl i32 1, %28
  %30 = add nsw i32 %27, %29
  %31 = sub nsw i32 %30, 1
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %98

34:                                               ; preds = %26
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [19 x i32], ptr %37, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200005 x %"struct.std::pair"], ptr @P, i64 0, i64 %43
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = shl i32 1, %47
  %49 = add nsw i32 %45, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [19 x i32], ptr %51, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200005 x %"struct.std::pair"], ptr @P, i64 0, i64 %57
  %59 = call noundef zeroext i1 @_ZStltIiiEbRKSt4pairIT_T0_ES5_(ptr noundef nonnull align 4 dereferenceable(8) %44, ptr noundef nonnull align 4 dereferenceable(8) %58)
  br i1 %59, label %60, label %75

60:                                               ; preds = %34
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %62
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [19 x i32], ptr %63, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %70
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [19 x i32], ptr %71, i64 0, i64 %73
  store i32 %68, ptr %74, align 4, !tbaa !5
  br label %94

75:                                               ; preds = %34
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sub nsw i32 %77, 1
  %79 = shl i32 1, %78
  %80 = add nsw i32 %76, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %81
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [19 x i32], ptr %82, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %89
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [19 x i32], ptr %90, i64 0, i64 %92
  store i32 %87, ptr %93, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %75, %60
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !11

98:                                               ; preds = %26
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !12

102:                                              ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStltIiiEbRKSt4pairIT_T0_ES5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2

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

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 = { inlinehint mustprogress 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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"

%"struct.std::pair" = type { i32, i32 }

@P = external dso_local global [200005 x %"struct.std::pair"], align 16
@M = external dso_local local_unnamed_addr global [200005 x [19 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8process2i(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %3 = icmp ult i32 %0, 4
  br i1 %3, label %.preheader30.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader30.unr-lcssa:                           ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader30, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader30.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader30.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader30.unr-lcssa ]
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %4 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv.epil
  %5 = trunc nuw nsw i64 %indvars.iv.next.epil to i32
  store i32 %5, ptr %4, align 4, !tbaa !5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader30, label %.lr.ph.epil, !llvm.loop !9

.preheader30:                                     ; preds = %.lr.ph.epil, %.preheader30.unr-lcssa
  %.not33 = icmp eq i32 %0, 1
  br i1 %.not33, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader30
  %6 = zext nneg i32 %0 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %7 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv
  %8 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %8, ptr %7, align 16, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %9 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv.next
  %10 = trunc nuw nsw i64 %indvars.iv.next.1 to i32
  store i32 %10, ptr %9, align 4, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %11 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv.next.1
  %12 = trunc nuw nsw i64 %indvars.iv.next.2 to i32
  store i32 %12, ptr %11, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %13 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv.next.2
  %14 = trunc nuw nsw i64 %indvars.iv.next.3 to i32
  store i32 %14, ptr %13, align 4, !tbaa !5
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader30.unr-lcssa, label %.lr.ph, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.preheader, %33
  %indvars.iv39 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next40, %33 ]
  %15 = phi i32 [ 2, %.preheader.preheader ], [ %35, %33 ]
  %16 = add nsw i64 %indvars.iv39, -1
  %17 = trunc nuw nsw i64 %16 to i32
  %18 = shl nuw i32 1, %17
  %19 = sext i32 %15 to i64
  %20 = sext i32 %18 to i64
  %invariant.op = sub nsw i64 %6, %19
  br label %21

21:                                               ; preds = %.preheader, %21
  %indvars.iv36 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next37, %21 ]
  %22 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv36, i64 %16
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200005 x %"struct.std::pair"], ptr @P, i64 0, i64 %24
  %26 = add nuw nsw i64 %indvars.iv36, %20
  %27 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %26, i64 %16
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200005 x %"struct.std::pair"], ptr @P, i64 0, i64 %29
  %31 = tail call noundef zeroext i1 @_ZStltIiiEbRKSt4pairIT_T0_ES5_(ptr noundef nonnull align 4 dereferenceable(8) %25, ptr noundef nonnull align 4 dereferenceable(8) %30)
  %spec.select = select i1 %31, ptr %22, ptr %27
  %.sink = load i32, ptr %spec.select, align 4, !tbaa !5
  %32 = getelementptr inbounds [200005 x [19 x i32]], ptr @M, i64 0, i64 %indvars.iv36, i64 %indvars.iv39
  store i32 %.sink, ptr %32, align 4
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %.not29.not = icmp slt i64 %indvars.iv36, %invariant.op
  br i1 %.not29.not, label %21, label %33, !llvm.loop !13

33:                                               ; preds = %21
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %34 = trunc nuw nsw i64 %indvars.iv39 to i32
  %35 = shl nuw i32 2, %34
  %.not = icmp sgt i32 %35, %0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %33, %1, %.preheader30
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStltIiiEbRKSt4pairIT_T0_ES5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

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

!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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass