; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/cp/Maximum_In_Array.ll (Z19max_height_in_arraySt6vectorIiSaIiEEi)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z19max_height_in_arraySt6vectorIiSaIiEEi(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = and i32 %8, 1
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %48

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

12:                                               ; preds = %44, %11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = mul nsw i32 %21, 12
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %25) #2
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = add nsw i32 %22, %27
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %31, label %43

31:                                               ; preds = %17
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %33) #2
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = mul nsw i32 %35, 12
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %39) #2
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = add nsw i32 %36, %41
  store i32 %42, ptr %5, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %31, %17
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !11

47:                                               ; preds = %16
  br label %102

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

49:                                               ; preds = %82, %48
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = sub nsw i32 %51, 1
  %53 = icmp slt i32 %50, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %85

55:                                               ; preds = %49
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %57) #2
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = mul nsw i32 %59, 12
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %63) #2
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = add nsw i32 %60, %65
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %81

69:                                               ; preds = %55
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %71) #2
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = mul nsw i32 %73, 12
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %77) #2
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = add nsw i32 %74, %79
  store i32 %80, ptr %5, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %69, %55
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = add nsw i32 %83, 2
  store i32 %84, ptr %7, align 4, !tbaa !9
  br label %49, !llvm.loop !13

85:                                               ; preds = %54
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = sub nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %88) #2
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = mul nsw i32 %90, 12
  %92 = load i32, ptr %5, align 4, !tbaa !9
  %93 = icmp sgt i32 %91, %92
  br i1 %93, label %94, label %101

94:                                               ; preds = %85
  %95 = load i32, ptr %4, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 1
  %97 = sext i32 %96 to i64
  %98 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %97) #2
  %99 = load i32, ptr %98, align 4, !tbaa !9
  %100 = mul nsw i32 %99, 12
  store i32 %100, ptr %5, align 4, !tbaa !9
  br label %101

101:                                              ; preds = %94, %85
  br label %102

102:                                              ; preds = %101, %47
  %103 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %103
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z19max_height_in_arraySt6vectorIiSaIiEEi(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = and i32 %1, 1
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader, label %.preheader24

.preheader24:                                     ; preds = %2
  %5 = add nsw i32 %1, -1
  %6 = icmp sgt i32 %1, 1
  br i1 %6, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %2
  %7 = icmp sgt i32 %1, 0
  br i1 %7, label %.lr.ph30, label %.loopexit

.lr.ph30:                                         ; preds = %.preheader, %23
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %23 ], [ 0, %.preheader ]
  %.02228 = phi i32 [ %.1, %23 ], [ 0, %.preheader ]
  %8 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv33) #1
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = mul nsw i32 %9, 12
  %11 = or disjoint i64 %indvars.iv33, 1
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #1
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add nsw i32 %13, %10
  %15 = icmp sgt i32 %14, %.02228
  br i1 %15, label %16, label %23

16:                                               ; preds = %.lr.ph30
  %17 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv33) #1
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = mul nsw i32 %18, 12
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %11) #1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, %19
  br label %23

23:                                               ; preds = %.lr.ph30, %16
  %.1 = phi i32 [ %22, %16 ], [ %.02228, %.lr.ph30 ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 2
  %24 = trunc nuw i64 %indvars.iv.next34 to i32
  %25 = icmp slt i32 %24, %1
  br i1 %25, label %.lr.ph30, label %.loopexit, !llvm.loop !9

._crit_edge:                                      ; preds = %46, %.preheader24
  %.2.lcssa = phi i32 [ 0, %.preheader24 ], [ %.3, %46 ]
  %26 = sext i32 %5 to i64
  %27 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %26) #1
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = mul nsw i32 %28, 12
  %30 = icmp sgt i32 %29, %.2.lcssa
  br i1 %30, label %49, label %.loopexit

.lr.ph:                                           ; preds = %.preheader24, %46
  %indvars.iv = phi i64 [ %indvars.iv.next, %46 ], [ 0, %.preheader24 ]
  %.225 = phi i32 [ %.3, %46 ], [ 0, %.preheader24 ]
  %31 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #1
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = mul nsw i32 %32, 12
  %34 = or disjoint i64 %indvars.iv, 1
  %35 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %34) #1
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %36, %33
  %38 = icmp sgt i32 %37, %.225
  br i1 %38, label %39, label %46

39:                                               ; preds = %.lr.ph
  %40 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = mul nsw i32 %41, 12
  %43 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %34) #1
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, %42
  br label %46

46:                                               ; preds = %.lr.ph, %39
  %.3 = phi i32 [ %45, %39 ], [ %.225, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %47 = trunc nuw i64 %indvars.iv.next to i32
  %48 = icmp sgt i32 %5, %47
  br i1 %48, label %.lr.ph, label %._crit_edge, !llvm.loop !11

49:                                               ; preds = %._crit_edge
  %50 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %26) #1
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = mul nsw i32 %51, 12
  br label %.loopexit

.loopexit:                                        ; preds = %23, %.preheader, %._crit_edge, %49
  %.4 = phi i32 [ %52, %49 ], [ %.2.lcssa, %._crit_edge ], [ 0, %.preheader ], [ %.1, %23 ]
  ret i32 %.4
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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 = { 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}


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