; LLVM IR from DionysiosB/CodeForces :: CodeforcesEDU/BinarySearch5B-MultiplicationTable.ll (Z5checkxxx)

; 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
define dso_local noundef zeroext i1 @_Z5checkxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 1, ptr %9, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %41, %3
  %13 = load i64, ptr %9, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  br label %44

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %18 = load i64, ptr %7, align 8, !tbaa !5
  %19 = load i64, ptr %9, align 8, !tbaa !5
  %20 = sdiv i64 %18, %19
  store i64 %20, ptr %11, align 8, !tbaa !5
  %21 = load i64, ptr %11, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %17
  %25 = load i64, ptr %11, align 8, !tbaa !5
  br label %28

26:                                               ; preds = %17
  %27 = load i64, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi i64 [ %25, %24 ], [ %27, %26 ]
  store i64 %29, ptr %11, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !5
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %8, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = icmp sge i64 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %38

37:                                               ; preds = %28
  store i32 0, ptr %10, align 4
  br label %38

38:                                               ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %39 = load i32, ptr %10, align 4
  switch i32 %39, label %44 [
    i32 0, label %40
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %9, align 8, !tbaa !5
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %9, align 8, !tbaa !5
  br label %12, !llvm.loop !9

44:                                               ; preds = %38, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %45 = load i32, ptr %10, align 4
  switch i32 %45, label %47 [
    i32 2, label %46
  ]

46:                                               ; preds = %44
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %48 = load i1, ptr %4, align 1
  ret i1 %48
}

; 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 = { 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i1 @_Z5checkxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not22 = icmp sgt i64 %0, 0
  br i1 %.not22, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %3
  %4 = tail call i64 @llvm.smin.i64(i64 %2, i64 %0)
  %.not2128 = icmp slt i64 %4, %1
  br i1 %.not2128, label %.lr.ph30, label %.critedge

.lr.ph30:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %5 = phi i64 [ %9, %.lr.ph ], [ %4, %.lr.ph.preheader ]
  %.0182429 = phi i64 [ %6, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %exitcond.not = icmp eq i64 %.0182429, %0
  br i1 %exitcond.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph30
  %6 = add nuw i64 %.0182429, 1
  %7 = sdiv i64 %2, %6
  %8 = tail call i64 @llvm.smin.i64(i64 %7, i64 %0)
  %9 = add nsw i64 %8, %5
  %.not21 = icmp slt i64 %9, %1
  br i1 %.not21, label %.lr.ph30, label %.critedge.loopexit, !llvm.loop !5

.critedge.loopexit:                               ; preds = %.lr.ph, %.lr.ph30
  %.not.le = icmp slt i64 %.0182429, %0
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph.preheader, %3
  %.not.lcssa = phi i1 [ false, %3 ], [ true, %.lr.ph.preheader ], [ %.not.le, %.critedge.loopexit ]
  ret i1 %.not.lcssa
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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