; LLVM IR from tyalie/Sudoku-Generator-CPP :: src/Generator/GenSudoku.ll (ZN9GenSudoku11isIndexLastEv)

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

%class.GenSudoku = type { %class.Sudoku, i64 }
%class.Sudoku = type { [81 x i8], i8 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN9GenSudoku11isIndexLastEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #0 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = getelementptr inbounds %class.GenSudoku, ptr %6, i32 0, i32 1
  %8 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %8, ptr %4, align 8, !tbaa !14
  br label %9

9:                                                ; preds = %22, %1
  %10 = load i64, ptr %4, align 8, !tbaa !14
  %11 = icmp ult i64 %10, 81
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %25

13:                                               ; preds = %9
  %14 = getelementptr inbounds %class.Sudoku, ptr %6, i32 0, i32 0
  %15 = load i64, ptr %4, align 8, !tbaa !14
  %16 = getelementptr inbounds [81 x i8], ptr %14, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !15
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %25

21:                                               ; preds = %13
  br label %22

22:                                               ; preds = %21
  %23 = load i64, ptr %4, align 8, !tbaa !14
  %24 = add i64 %23, 1
  store i64 %24, ptr %4, align 8, !tbaa !14
  br label %9, !llvm.loop !16

25:                                               ; preds = %20, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %26 = load i32, ptr %5, align 4
  switch i32 %26, label %30 [
    i32 2, label %27
    i32 1, label %28
  ]

27:                                               ; preds = %25
  store i1 true, ptr %2, align 1
  br label %28

28:                                               ; preds = %27, %25
  %29 = load i1, ptr %2, align 1
  ret i1 %29

30:                                               ; preds = %25
  unreachable
}

; 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !13, i64 88}
!10 = !{!"_ZTS9GenSudoku", !11, i64 0, !13, i64 88}
!11 = !{!"_ZTS6Sudoku", !7, i64 0, !12, i64 81}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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(argmem: read) uwtable
define dso_local noundef zeroext i1 @_ZN9GenSudoku11isIndexLastEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp ugt i64 %3, 80
  br i1 %4, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %5 = getelementptr inbounds [81 x i8], ptr %0, i64 0, i64 %3
  %6 = load i8, ptr %5, align 1, !tbaa !12
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %._crit_edge, label %.lr.ph11

.lr.ph11:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.05710 = phi i64 [ %8, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %8 = add i64 %.05710, 1
  %exitcond = icmp eq i64 %8, 81
  br i1 %exitcond, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph11
  %9 = getelementptr inbounds [81 x i8], ptr %0, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !12
  %11 = icmp eq i8 %10, 0
  br i1 %11, label %._crit_edge.loopexit, label %.lr.ph11, !llvm.loop !13

._crit_edge.loopexit:                             ; preds = %.lr.ph11, %.lr.ph
  %12 = icmp ugt i64 %.05710, 79
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph.preheader, %1
  %.lcssa = phi i1 [ true, %1 ], [ false, %.lr.ph.preheader ], [ %12, %._crit_edge.loopexit ]
  ret i1 %.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !11, i64 88}
!6 = !{!"_ZTS9GenSudoku", !7, i64 0, !11, i64 88}
!7 = !{!"_ZTS6Sudoku", !8, i64 0, !10, i64 81}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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