; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1464)

; 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: nounwind uwtable
define dso_local i32 @maxProduct(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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %27, %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %30

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %16, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %15
  %25 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %25, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %26, ptr %7, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %24, %15
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %11, !llvm.loop !11

30:                                               ; preds = %11
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  store i32 -1, ptr %38, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %54, %30
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %57

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  store i32 %48, ptr %10, align 4, !tbaa !9
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %54

52:                                               ; preds = %43
  %53 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52, %43
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %39, !llvm.loop !13

57:                                               ; preds = %39
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sub nsw i32 %58, 1
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = mul nsw i32 %60, %59
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %62
}

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

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

attributes #0 = { 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/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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 -2147483646, -2147483648) i32 @maxProduct(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %2
  store i32 -1, ptr %0, align 4, !tbaa !5
  br label %._crit_edge40

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %4 = icmp ult i32 %1, 4
  br i1 %4, label %._crit_edge.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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.02333 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %spec.select30.3, %.lr.ph ]
  %.02532 = phi i32 [ undef, %.lr.ph.preheader.new ], [ %spec.select.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %5 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %.02333, %6
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select = select i1 %7, i32 %8, i32 %.02532
  %spec.select30 = tail call i32 @llvm.smax.i32(i32 %.02333, i32 %6)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp slt i32 %spec.select30, %10
  %12 = trunc nuw nsw i64 %indvars.iv.next to i32
  %spec.select.1 = select i1 %11, i32 %12, i32 %spec.select
  %spec.select30.1 = tail call i32 @llvm.smax.i32(i32 %spec.select30, i32 %10)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %13 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp slt i32 %spec.select30.1, %14
  %16 = trunc nuw nsw i64 %indvars.iv.next.1 to i32
  %spec.select.2 = select i1 %15, i32 %16, i32 %spec.select.1
  %spec.select30.2 = tail call i32 @llvm.smax.i32(i32 %spec.select30.1, i32 %14)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %17 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp slt i32 %spec.select30.2, %18
  %20 = trunc nuw nsw i64 %indvars.iv.next.2 to i32
  %spec.select.3 = select i1 %19, i32 %20, i32 %spec.select.2
  %spec.select30.3 = tail call i32 @llvm.smax.i32(i32 %spec.select30.2, i32 %18)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %spec.select.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %spec.select.3, %.lr.ph ]
  %spec.select30.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %spec.select30.3, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.02333.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %spec.select30.3, %.lr.ph ]
  %.02532.unr = phi i32 [ undef, %.lr.ph.preheader ], [ %spec.select.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %.02333.epil = phi i32 [ %spec.select30.epil, %.lr.ph.epil ], [ %.02333.unr, %._crit_edge.unr-lcssa ]
  %.02532.epil = phi i32 [ %spec.select.epil, %.lr.ph.epil ], [ %.02532.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %21 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.epil
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp slt i32 %.02333.epil, %22
  %24 = trunc nuw nsw i64 %indvars.iv.epil to i32
  %spec.select.epil = select i1 %23, i32 %24, i32 %.02532.epil
  %spec.select30.epil = tail call i32 @llvm.smax.i32(i32 %.02333.epil, i32 %22)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %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 %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %._crit_edge.unr-lcssa ], [ %spec.select.epil, %.lr.ph.epil ]
  %spec.select30.lcssa = phi i32 [ %spec.select30.lcssa.ph, %._crit_edge.unr-lcssa ], [ %spec.select30.epil, %.lr.ph.epil ]
  %25 = sext i32 %spec.select.lcssa to i64
  %26 = add nsw i32 %spec.select30.lcssa, -1
  %27 = getelementptr inbounds i32, ptr %0, i64 %25
  store i32 -1, ptr %27, align 4, !tbaa !5
  br i1 %3, label %.lr.ph39.preheader, label %._crit_edge40

.lr.ph39.preheader:                               ; preds = %._crit_edge
  %wide.trip.count46 = zext nneg i32 %1 to i64
  %min.iters.check = icmp ult i32 %1, 8
  br i1 %min.iters.check, label %.lr.ph39.preheader53, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph39.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %vec.phi51 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %31, %vector.body ]
  %28 = getelementptr inbounds i32, ptr %0, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load = load <4 x i32>, ptr %28, align 4, !tbaa !5
  %wide.load52 = load <4 x i32>, ptr %29, align 4, !tbaa !5
  %30 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %vec.phi, <4 x i32> %wide.load)
  %31 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %vec.phi51, <4 x i32> %wide.load52)
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %rdx.minmax = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %30, <4 x i32> %31)
  %33 = tail call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge40.loopexit, label %.lr.ph39.preheader53

.lr.ph39.preheader53:                             ; preds = %middle.block, %.lr.ph39.preheader
  %indvars.iv43.ph = phi i64 [ 0, %.lr.ph39.preheader ], [ %n.vec, %middle.block ]
  %.236.ph = phi i32 [ 0, %.lr.ph39.preheader ], [ %33, %middle.block ]
  br label %.lr.ph39

.lr.ph39:                                         ; preds = %.lr.ph39.preheader53, %.lr.ph39
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.lr.ph39 ], [ %indvars.iv43.ph, %.lr.ph39.preheader53 ]
  %.236 = phi i32 [ %spec.select31, %.lr.ph39 ], [ %.236.ph, %.lr.ph39.preheader53 ]
  %34 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv43
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %spec.select31 = tail call i32 @llvm.smax.i32(i32 %.236, i32 %35)
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %wide.trip.count46
  br i1 %exitcond47.not, label %._crit_edge40.loopexit, label %.lr.ph39, !llvm.loop !16

._crit_edge40.loopexit:                           ; preds = %.lr.ph39, %middle.block
  %spec.select31.lcssa = phi i32 [ %33, %middle.block ], [ %spec.select31, %.lr.ph39 ]
  %36 = add nsw i32 %spec.select31.lcssa, -1
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %._crit_edge.thread, %._crit_edge40.loopexit, %._crit_edge
  %.023.lcssa50 = phi i32 [ %26, %._crit_edge ], [ %26, %._crit_edge40.loopexit ], [ -1, %._crit_edge.thread ]
  %.2.lcssa = phi i32 [ -1, %._crit_edge ], [ %36, %._crit_edge40.loopexit ], [ -1, %._crit_edge.thread ]
  %37 = mul nsw i32 %.2.lcssa, %.023.lcssa50
  ret i32 %37
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smax.v4i32(<4 x i32>, <4 x i32>) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !10, !15, !14}


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