; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Week 2/rectangles/rectangles.ll (Z17no_of_rectangles2i)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17no_of_rectangles2i(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sub nsw i32 %9, 1
  %11 = and i32 %8, %10
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %27

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store float 0.000000e+00, ptr %4, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %17, %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = ashr i32 %18, 1
  store i32 %19, ptr %3, align 4, !tbaa !5
  %20 = load float, ptr %4, align 4, !tbaa !9
  %21 = fadd float %20, 1.000000e+00
  store float %21, ptr %4, align 4, !tbaa !9
  br label %14, !llvm.loop !11

22:                                               ; preds = %14
  %23 = load float, ptr %4, align 4, !tbaa !9
  %24 = fdiv float %23, 2.000000e+00
  %25 = call noundef float @_ZSt4ceilf(float noundef %24)
  %26 = fptosi float %25 to i32
  store i32 %26, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %49

27:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store float 1.000000e+00, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %28)
  %30 = fptosi double %29 to i32
  store i32 %30, ptr %7, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %43, %27
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %35, label %46

35:                                               ; preds = %31
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %35
  %41 = load float, ptr %5, align 4, !tbaa !9
  %42 = fadd float %41, 1.000000e+00
  store float %42, ptr %5, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %35
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %6, align 4, !tbaa !5
  br label %31, !llvm.loop !13

46:                                               ; preds = %31
  %47 = load float, ptr %5, align 4, !tbaa !9
  %48 = fptosi float %47 to i32
  store i32 %48, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %49

49:                                               ; preds = %46, %22
  %50 = load i32, ptr %2, align 4
  ret i32 %50
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4ceilf(float noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"float", !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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z17no_of_rectangles2i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %0)
  %3 = icmp ult i32 %2, 2
  br i1 %3, label %.preheader, label %9

.preheader:                                       ; preds = %1
  %4 = icmp sgt i32 %0, 0
  br i1 %4, label %.lr.ph23, label %._crit_edge

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %.01622 = phi float [ %6, %.lr.ph23 ], [ 0.000000e+00, %.preheader ]
  %.01721 = phi i32 [ %5, %.lr.ph23 ], [ %0, %.preheader ]
  %5 = lshr i32 %.01721, 1
  %6 = fadd float %.01622, 1.000000e+00
  %.not = icmp ult i32 %.01721, 2
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph23, !llvm.loop !5

._crit_edge.loopexit:                             ; preds = %.lr.ph23
  %7 = fmul float %6, 5.000000e-01
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.016.lcssa = phi float [ 0.000000e+00, %.preheader ], [ %7, %._crit_edge.loopexit ]
  %8 = tail call noundef float @_ZSt4ceilf(float noundef %.016.lcssa)
  br label %.loopexit

9:                                                ; preds = %1
  %10 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %11 = fptosi double %10 to i32
  %.not18 = icmp slt i32 %11, 2
  br i1 %.not18, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %12 = add nsw i32 %11, -1
  %xtraiter = and i32 %12, 1
  %13 = icmp eq i32 %11, 2
  br i1 %13, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %12, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01420 = phi i32 [ 2, %.lr.ph.preheader.new ], [ %21, %.lr.ph ]
  %.01519 = phi float [ 1.000000e+00, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %14 = srem i32 %0, %.01420
  %15 = icmp eq i32 %14, 0
  %16 = fadd float %.01519, 1.000000e+00
  %.1 = select i1 %15, float %16, float %.01519
  %17 = or disjoint i32 %.01420, 1
  %18 = srem i32 %0, %17
  %19 = icmp eq i32 %18, 0
  %20 = fadd float %.1, 1.000000e+00
  %.1.1 = select i1 %19, float %20, float %.1
  %21 = add nuw i32 %.01420, 2
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !7

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %.1.lcssa.ph = phi float [ poison, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %.01420.unr = phi i32 [ 2, %.lr.ph.preheader ], [ %21, %.lr.ph ]
  %.01519.unr = phi float [ 1.000000e+00, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa
  %22 = srem i32 %0, %.01420.unr
  %23 = icmp eq i32 %22, 0
  %24 = fadd float %.01519.unr, 1.000000e+00
  %.1.epil = select i1 %23, float %24, float %.01519.unr
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %9, %._crit_edge
  %.0.in = phi float [ %8, %._crit_edge ], [ 1.000000e+00, %9 ], [ %.1.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %.1.epil, %.lr.ph.epil ]
  %.0 = fptosi float %.0.in to i32
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4ceilf(float noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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