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

; 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.Sudoku = type { [81 x i8], i8 }
%class.GenSudoku = type { %class.Sudoku, i64 }

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

; 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 ptr @_ZNK9GenSudoku11rule3_blockEPb(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %63, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 9
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %66

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %13 = getelementptr inbounds %class.Sudoku, ptr %7, i32 0, i32 0
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %16 = fptosi double %15 to i32
  %17 = srem i32 %14, %16
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %20 = fptosi double %19 to i32
  %21 = sdiv i32 %18, %20
  %22 = mul nsw i32 %21, 9
  %23 = add nsw i32 %17, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %class.GenSudoku, ptr %7, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = urem i64 %26, 9
  %28 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %29 = fptosi double %28 to i32
  %30 = sext i32 %29 to i64
  %31 = udiv i64 %27, %30
  %32 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %33 = fptosi double %32 to i32
  %34 = sext i32 %33 to i64
  %35 = mul i64 %31, %34
  %36 = add i64 %24, %35
  %37 = getelementptr inbounds %class.GenSudoku, ptr %7, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %40 = fptosi double %39 to i32
  %41 = mul nsw i32 9, %40
  %42 = sext i32 %41 to i64
  %43 = udiv i64 %38, %42
  %44 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %45 = fptosi double %44 to i32
  %46 = mul nsw i32 9, %45
  %47 = sext i32 %46 to i64
  %48 = mul i64 %43, %47
  %49 = add i64 %36, %48
  %50 = getelementptr inbounds [81 x i8], ptr %13, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !16
  store i8 %51, ptr %6, align 1, !tbaa !16
  %52 = load i8, ptr %6, align 1, !tbaa !16
  %53 = zext i8 %52 to i32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %62

55:                                               ; preds = %12
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i8, ptr %6, align 1, !tbaa !16
  %58 = zext i8 %57 to i32
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = getelementptr inbounds i8, ptr %60, i64 -1
  store i8 0, ptr %61, align 1, !tbaa !17
  br label %62

62:                                               ; preds = %55, %12
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !18

66:                                               ; preds = %11
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  ret ptr %67
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 88}
!12 = !{!"_ZTS9GenSudoku", !13, i64 0, !15, i64 88}
!13 = !{!"_ZTS6Sudoku", !7, i64 0, !14, i64 81}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!14, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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 nounwind uwtable
define dso_local noundef ptr @_ZNK9GenSudoku11rule3_blockEPb(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0, ptr noundef returned writeonly %1) local_unnamed_addr #0 align 2 {
  %invariant.gep = getelementptr i8, ptr %1, i64 -1
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  br label %5

4:                                                ; preds = %42
  ret ptr %1

5:                                                ; preds = %2, %42
  %.09 = phi i32 [ 0, %2 ], [ %43, %42 ]
  %6 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %7 = fptosi double %6 to i32
  %8 = srem i32 %.09, %7
  %9 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %10 = fptosi double %9 to i32
  %11 = sdiv i32 %.09, %10
  %12 = mul nsw i32 %11, 9
  %13 = add nsw i32 %12, %8
  %14 = sext i32 %13 to i64
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = urem i64 %15, 9
  %17 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %18 = fptosi double %17 to i32
  %19 = sext i32 %18 to i64
  %20 = udiv i64 %16, %19
  %21 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %22 = fptosi double %21 to i32
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %20, %23
  %25 = add nsw i64 %24, %14
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %28 = fptosi double %27 to i32
  %29 = mul nsw i32 %28, 9
  %30 = sext i32 %29 to i64
  %31 = udiv i64 %26, %30
  %32 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef 9)
  %33 = fptosi double %32 to i32
  %34 = mul nsw i32 %33, 9
  %35 = sext i32 %34 to i64
  %36 = mul i64 %31, %35
  %37 = add i64 %25, %36
  %38 = getelementptr inbounds [81 x i8], ptr %0, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !12
  %.not = icmp eq i8 %39, 0
  br i1 %.not, label %42, label %40

40:                                               ; preds = %5
  %41 = zext i8 %39 to i64
  %gep = getelementptr i8, ptr %invariant.gep, i64 %41
  store i8 0, ptr %gep, align 1, !tbaa !13
  br label %42

42:                                               ; preds = %40, %5
  %43 = add nuw nsw i32 %.09, 1
  %exitcond.not = icmp eq i32 %43, 9
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !14
}

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

!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 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass