; LLVM IR from PetarV-/Algorithms :: Greedy Algorithms/First-Fit Bin Packing.ll (Z5Queryidii)

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

@ST = external dso_local global [4000004 x double], align 16

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

13:                                               ; preds = %4
  %14 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %14, ptr %5, align 4
  br label %46

15:                                               ; preds = %4
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = mul nsw i32 2, %16
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4000004 x double], ptr @ST, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = load double, ptr %7, align 8, !tbaa !9
  %22 = fsub double 1.000000e+00, %21
  %23 = fcmp ole double %20, %22
  br i1 %23, label %24, label %34

24:                                               ; preds = %15
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = mul nsw i32 2, %25
  %27 = load double, ptr %7, align 8, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = sdiv i32 %31, 2
  %33 = call noundef i32 @_Z5Queryidii(i32 noundef %26, double noundef %27, i32 noundef %28, i32 noundef %32)
  store i32 %33, ptr %5, align 4
  br label %46

34:                                               ; preds = %15
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = mul nsw i32 2, %35
  %37 = add nsw i32 %36, 1
  %38 = load double, ptr %7, align 8, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = sdiv i32 %41, 2
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = call noundef i32 @_Z5Queryidii(i32 noundef %37, double noundef %38, i32 noundef %43, i32 noundef %44)
  store i32 %45, ptr %5, align 4
  br label %46

46:                                               ; preds = %34, %24, %13
  %47 = load i32, ptr %5, align 4
  ret i32 %47
}

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

!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 = !{!"double", !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"

@ST = external dso_local local_unnamed_addr global [4000004 x double], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z5Queryidii(i32 noundef %0, double noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %2, %3
  br i1 %5, label %tailrecurse.outer._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %4
  %6 = fsub double 1.000000e+00, %1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer
  %.tr19.ph26 = phi i32 [ %3, %.lr.ph.lr.ph ], [ %.tr1922, %tailrecurse.outer ]
  %.tr18.ph25 = phi i32 [ %2, %.lr.ph.lr.ph ], [ %19, %tailrecurse.outer ]
  %.tr.ph24 = phi i32 [ %0, %.lr.ph.lr.ph ], [ %16, %tailrecurse.outer ]
  br label %7

7:                                                ; preds = %.lr.ph, %tailrecurse
  %.tr1922 = phi i32 [ %.tr19.ph26, %.lr.ph ], [ %14, %tailrecurse ]
  %.tr21 = phi i32 [ %.tr.ph24, %.lr.ph ], [ %8, %tailrecurse ]
  %8 = shl nsw i32 %.tr21, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [4000004 x double], ptr @ST, i64 0, i64 %9
  %11 = load double, ptr %10, align 16, !tbaa !5
  %12 = fcmp ugt double %11, %6
  br i1 %12, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %7
  %13 = add nsw i32 %.tr1922, %.tr18.ph25
  %14 = sdiv i32 %13, 2
  %15 = icmp eq i32 %.tr18.ph25, %14
  br i1 %15, label %tailrecurse.outer._crit_edge, label %7

tailrecurse.outer:                                ; preds = %7
  %16 = or disjoint i32 %8, 1
  %17 = add nsw i32 %.tr1922, %.tr18.ph25
  %18 = sdiv i32 %17, 2
  %19 = add nsw i32 %18, 1
  %20 = icmp eq i32 %19, %.tr1922
  br i1 %20, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %4
  %.tr18.ph.lcssa = phi i32 [ %2, %4 ], [ %.tr18.ph25, %tailrecurse ], [ %.tr1922, %tailrecurse.outer ]
  ret i32 %.tr18.ph.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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" }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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