; LLVM IR from UtkarshPathrabe/Competitive-Coding :: HackerRank Solutions/Algorithms/Dynamic Programming (The Maximum Subarray)

; 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
declare dso_local noundef i32 @_Z23FindMaxCrossingSubarrayRSt6vectorIiSaIiEEiiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr 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: 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %36

26:                                               ; preds = %5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %27, ptr %28, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %29, ptr %30, align 4, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i32, ptr %8, 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) %31, i64 noundef %33) #4
  %35 = load i32, ptr %34, align 4, !tbaa !9
  store i32 %35, ptr %6, align 4
  br label %91

36:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = add nsw i32 %37, %38
  %40 = sdiv i32 %39, 2
  %41 = call noundef double @_ZSt5floorIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %40)
  %42 = fptosi double %41 to i32
  store i32 %42, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = load i32, ptr %12, align 4, !tbaa !9
  %46 = call noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %43, i32 noundef %44, i32 noundef %45, ptr noundef %13, ptr noundef %16)
  store i32 %46, ptr %19, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = call noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %47, i32 noundef %49, i32 noundef %50, ptr noundef %14, ptr noundef %17)
  store i32 %51, ptr %20, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = call noundef i32 @_Z23FindMaxCrossingSubarrayRSt6vectorIiSaIiEEiiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, ptr noundef %15, ptr noundef %18)
  store i32 %56, ptr %21, align 4, !tbaa !9
  %57 = load i32, ptr %19, align 4, !tbaa !9
  %58 = load i32, ptr %20, align 4, !tbaa !9
  %59 = icmp sgt i32 %57, %58
  br i1 %59, label %60, label %70

60:                                               ; preds = %36
  %61 = load i32, ptr %19, align 4, !tbaa !9
  %62 = load i32, ptr %21, align 4, !tbaa !9
  %63 = icmp sgt i32 %61, %62
  br i1 %63, label %64, label %70

64:                                               ; preds = %60
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %65, ptr %66, align 4, !tbaa !9
  %67 = load i32, ptr %16, align 4, !tbaa !9
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %67, ptr %68, align 4, !tbaa !9
  %69 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %69, ptr %6, align 4
  store i32 1, ptr %22, align 4
  br label %90

70:                                               ; preds = %60, %36
  %71 = load i32, ptr %19, align 4, !tbaa !9
  %72 = load i32, ptr %20, align 4, !tbaa !9
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %74, label %84

74:                                               ; preds = %70
  %75 = load i32, ptr %20, align 4, !tbaa !9
  %76 = load i32, ptr %21, align 4, !tbaa !9
  %77 = icmp sgt i32 %75, %76
  br i1 %77, label %78, label %84

78:                                               ; preds = %74
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !9
  %81 = load i32, ptr %17, align 4, !tbaa !9
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %81, ptr %82, align 4, !tbaa !9
  %83 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %83, ptr %6, align 4
  store i32 1, ptr %22, align 4
  br label %90

84:                                               ; preds = %74, %70
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %85, ptr %86, align 4, !tbaa !9
  %87 = load i32, ptr %18, align 4, !tbaa !9
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %87, ptr %88, align 4, !tbaa !9
  %89 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %89, ptr %6, align 4
  store i32 1, ptr %22, align 4
  br label %90

90:                                               ; preds = %84, %78, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %91

91:                                               ; preds = %90, %26
  %92 = load i32, ptr %6, align 4
  ret i32 %92
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5floorIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #3

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 = { 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 = { 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 #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 = !{!"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}


; 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
declare dso_local noundef i32 @_Z23FindMaxCrossingSubarrayRSt6vectorIiSaIiEEiiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = icmp eq i32 %2, %1
  br i1 %12, label %13, label %17

13:                                               ; preds = %5
  store i32 %2, ptr %3, align 4, !tbaa !5
  store i32 %2, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %2 to i64
  %15 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %14) #3
  %16 = load i32, ptr %15, align 4, !tbaa !5
  br label %32

17:                                               ; preds = %5
  %18 = add nsw i32 %2, %1
  %19 = sdiv i32 %18, 2
  %20 = tail call noundef double @_ZSt5floorIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %19)
  %21 = fptosi double %20 to i32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #3
  %22 = call noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %21, ptr noundef nonnull %6, ptr noundef nonnull %9)
  %23 = add nsw i32 %21, 1
  %24 = call noundef i32 @_Z15FindMaxSubarrayRSt6vectorIiSaIiEEiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %23, i32 noundef %2, ptr noundef nonnull %7, ptr noundef nonnull %10)
  %25 = call noundef i32 @_Z23FindMaxCrossingSubarrayRSt6vectorIiSaIiEEiiiPiS3_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %21, i32 noundef %2, ptr noundef nonnull %8, ptr noundef nonnull %11)
  %26 = icmp sgt i32 %22, %24
  %27 = icmp sgt i32 %22, %25
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %31, label %28

28:                                               ; preds = %17
  %29 = icmp slt i32 %22, %24
  %30 = icmp sgt i32 %24, %25
  %or.cond43 = and i1 %29, %30
  %. = select i1 %or.cond43, ptr %7, ptr %8
  %.45 = select i1 %or.cond43, ptr %10, ptr %11
  %.46 = select i1 %or.cond43, i32 %24, i32 %25
  br label %31

31:                                               ; preds = %28, %17
  %.sink44.in = phi ptr [ %6, %17 ], [ %., %28 ]
  %.sink.in = phi ptr [ %9, %17 ], [ %.45, %28 ]
  %.0 = phi i32 [ %22, %17 ], [ %.46, %28 ]
  %.sink44 = load i32, ptr %.sink44.in, align 4, !tbaa !5
  store i32 %.sink44, ptr %3, align 4, !tbaa !5
  %.sink = load i32, ptr %.sink.in, align 4, !tbaa !5
  store i32 %.sink, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %32

32:                                               ; preds = %31, %13
  %.1 = phi i32 [ %16, %13 ], [ %.0, %31 ]
  ret i32 %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt5floorIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #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 = { mustprogress 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"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass