; LLVM IR from wuzhouhui/leetcode :: 85_max_rect (maximalRectangle)

; 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 @maximalRectangle(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16, %3
  store i32 0, ptr %4, align 4
  br label %76

20:                                               ; preds = %16
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = call ptr @llvm.stacksave.p0()
  store ptr %23, ptr %8, align 8
  %24 = alloca i32, i64 %22, align 16
  store i64 %22, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %25 = mul nuw i64 4, %22
  call void @llvm.memset.p0.i64(ptr align 16 %24, i8 0, i64 %25, i1 false)
  store i32 -1, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %70, %20
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %73

30:                                               ; preds = %26
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %58, %30
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %61

35:                                               ; preds = %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 48
  br i1 %46, label %47, label %51

47:                                               ; preds = %35
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %24, i64 %49
  store i32 0, ptr %50, align 4, !tbaa !9
  br label %57

51:                                               ; preds = %35
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %24, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %51, %47
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %31, !llvm.loop !12

61:                                               ; preds = %31
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = call i32 @max_rect(ptr noundef %24, i32 noundef %62)
  store i32 %63, ptr %12, align 4, !tbaa !9
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = icmp sgt i32 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %61
  %68 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %68, ptr %13, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %67, %61
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %10, align 4, !tbaa !9
  br label %26, !llvm.loop !14

73:                                               ; preds = %26
  %74 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %74, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %75 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %75)
  br label %76

76:                                               ; preds = %73, %19
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @max_rect(ptr noundef, i32 noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @maximalRectangle(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ne i32 %1, 0
  %5 = icmp ne i32 %2, 0
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %6, label %53

6:                                                ; preds = %3
  %7 = zext i32 %2 to i64
  %8 = tail call ptr @llvm.stacksave.p0()
  %9 = alloca i32, i64 %7, align 16
  %10 = shl nuw nsw i64 %7, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %9, i8 0, i64 %10, i1 false)
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.preheader.lr.ph, label %._crit_edge30

.preheader.lr.ph:                                 ; preds = %6
  %12 = icmp sgt i32 %2, 0
  br i1 %12, label %.preheader.us.preheader, label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count37 = zext nneg i32 %1 to i64
  %13 = shl nuw nsw i64 %7, 2
  %scevgep = getelementptr i8, ptr %9, i64 %13
  %min.iters.check = icmp ult i32 %2, 8
  %n.vec = and i64 %7, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %7
  %xtraiter = and i64 %7, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %14 = add nsw i64 %7, -1
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv34 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next35, %._crit_edge.us ]
  %.029.us = phi i32 [ -1, %.preheader.us.preheader ], [ %spec.select.us, %._crit_edge.us ]
  %15 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv34
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us
  %scevgep41 = getelementptr i8, ptr %16, i64 %7
  %bound0 = icmp ult ptr %9, %scevgep41
  %bound1 = icmp ult ptr %16, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %17 = getelementptr inbounds i8, ptr %16, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %wide.load = load <4 x i8>, ptr %17, align 1, !tbaa !9, !alias.scope !10
  %wide.load42 = load <4 x i8>, ptr %18, align 1, !tbaa !9, !alias.scope !10
  %19 = icmp eq <4 x i8> %wide.load, <i8 48, i8 48, i8 48, i8 48>
  %20 = icmp eq <4 x i8> %wide.load42, <i8 48, i8 48, i8 48, i8 48>
  %21 = getelementptr i32, ptr %9, i64 %index
  %22 = getelementptr i8, ptr %21, i64 16
  %wide.load43 = load <4 x i32>, ptr %21, align 16, !tbaa !13, !alias.scope !15, !noalias !10
  %wide.load44 = load <4 x i32>, ptr %22, align 16, !tbaa !13, !alias.scope !15, !noalias !10
  %23 = add nsw <4 x i32> %wide.load43, <i32 1, i32 1, i32 1, i32 1>
  %24 = add nsw <4 x i32> %wide.load44, <i32 1, i32 1, i32 1, i32 1>
  %predphi = select <4 x i1> %19, <4 x i32> zeroinitializer, <4 x i32> %23
  %predphi45 = select <4 x i1> %20, <4 x i32> zeroinitializer, <4 x i32> %24
  %25 = getelementptr inbounds i8, ptr %21, i64 16
  store <4 x i32> %predphi, ptr %21, align 16, !tbaa !13, !alias.scope !15, !noalias !10
  store <4 x i32> %predphi45, ptr %25, align 16, !tbaa !13, !alias.scope !15, !noalias !10
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %27 = getelementptr inbounds i8, ptr %16, i64 %indvars.iv.ph
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = icmp eq i8 %28, 48
  %30 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.ph
  br i1 %29, label %scalar.ph.prol.loopexit.unr-lcssa, label %31

31:                                               ; preds = %scalar.ph.prol
  %32 = load i32, ptr %30, align 16, !tbaa !13
  %33 = add nsw i32 %32, 1
  br label %scalar.ph.prol.loopexit.unr-lcssa

scalar.ph.prol.loopexit.unr-lcssa:                ; preds = %31, %scalar.ph.prol
  %.sink.prol = phi i32 [ %33, %31 ], [ 0, %scalar.ph.prol ]
  store i32 %.sink.prol, ptr %30, align 16, !tbaa !13
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol.loopexit.unr-lcssa, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol.loopexit.unr-lcssa ]
  %34 = icmp eq i64 %indvars.iv.ph, %14
  br i1 %34, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %49
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %49 ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %35 = getelementptr inbounds i8, ptr %16, i64 %indvars.iv
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = icmp eq i8 %36, 48
  %38 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  br i1 %37, label %scalar.ph.1, label %39

39:                                               ; preds = %scalar.ph
  %40 = load i32, ptr %38, align 4, !tbaa !13
  %41 = add nsw i32 %40, 1
  br label %scalar.ph.1

scalar.ph.1:                                      ; preds = %scalar.ph, %39
  %.sink = phi i32 [ %41, %39 ], [ 0, %scalar.ph ]
  store i32 %.sink, ptr %38, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = getelementptr inbounds i8, ptr %16, i64 %indvars.iv.next
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = icmp eq i8 %43, 48
  %45 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next
  br i1 %44, label %49, label %46

46:                                               ; preds = %scalar.ph.1
  %47 = load i32, ptr %45, align 4, !tbaa !13
  %48 = add nsw i32 %47, 1
  br label %49

49:                                               ; preds = %46, %scalar.ph.1
  %.sink.1 = phi i32 [ %48, %46 ], [ 0, %scalar.ph.1 ]
  store i32 %.sink.1, ptr %45, align 4, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond33.not.1 = icmp eq i64 %indvars.iv.next.1, %7
  br i1 %exitcond33.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !21

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %49, %middle.block
  %50 = call i32 @max_rect(ptr noundef nonnull %9, i32 noundef %2)
  %spec.select.us = call i32 @llvm.smax.i32(i32 %50, i32 %.029.us)
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge30, label %.preheader.us, !llvm.loop !22

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.029 = phi i32 [ %spec.select, %.preheader ], [ -1, %.preheader.lr.ph ]
  %.02328 = phi i32 [ %52, %.preheader ], [ 0, %.preheader.lr.ph ]
  %51 = call i32 @max_rect(ptr noundef nonnull %9, i32 noundef %2)
  %spec.select = call i32 @llvm.smax.i32(i32 %51, i32 %.029)
  %52 = add nuw nsw i32 %.02328, 1
  %exitcond.not = icmp eq i32 %52, %1
  br i1 %exitcond.not, label %._crit_edge30, label %.preheader, !llvm.loop !22

._crit_edge30:                                    ; preds = %.preheader, %._crit_edge.us, %6
  %.0.lcssa = phi i32 [ -1, %6 ], [ %spec.select.us, %._crit_edge.us ], [ %spec.select, %.preheader ]
  call void @llvm.stackrestore.p0(ptr %8)
  br label %53

53:                                               ; preds = %3, %._crit_edge30
  %.021 = phi i32 [ %.0.lcssa, %._crit_edge30 ], [ 0, %3 ]
  ret i32 %.021
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @max_rect(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11}
!11 = distinct !{!11, !12}
!12 = distinct !{!12, !"LVerDomain"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !19}
!22 = distinct !{!22, !18}


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