; LLVM IR from t-dillon/tdoku :: other/bb_sudoku/bb_sudoku_solver.ll (Z10InitTablesv)

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

@B2V = external dso_local global [512 x i32], align 16
@NSet = external dso_local global [512 x i32], align 16
@NSetX = external dso_local global [512 x [10 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8RND_Initv() #0

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z10InitTablesv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @_Z8RND_Initv()
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %50, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 512
  br i1 %5, label %6, label %53

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [512 x i32], ptr @NSet, i64 0, i64 %8
  store i32 0, ptr %9, align 4, !tbaa !5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [512 x i32], ptr @B2V, i64 0, i64 %11
  store i32 0, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %13, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %43, %6
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %49

17:                                               ; preds = %14
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sub nsw i32 0, %19
  %21 = and i32 %18, %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [512 x [10 x i32]], ptr @NSetX, i64 0, i64 %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [512 x i32], ptr @NSet, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10 x i32], ptr %24, i64 0, i64 %29
  store i32 %21, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [512 x [10 x i32]], ptr @NSetX, i64 0, i64 %33
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [512 x i32], ptr @NSet, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10 x i32], ptr %34, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = xor i32 %31, %41
  store i32 %42, ptr %2, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %17
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [512 x i32], ptr @NSet, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %46, align 4, !tbaa !5
  br label %14, !llvm.loop !9

49:                                               ; preds = %14
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %1, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !11

53:                                               ; preds = %3
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %64, %53
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = icmp sle i32 %55, 9
  br i1 %56, label %57, label %67

57:                                               ; preds = %54
  %58 = load i32, ptr %1, align 4, !tbaa !5
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = shl i32 1, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [512 x i32], ptr @B2V, i64 0, i64 %62
  store i32 %58, ptr %63, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %57
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %1, align 4, !tbaa !5
  br label %54, !llvm.loop !12

67:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i1 true
}

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


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

@B2V = external dso_local local_unnamed_addr global [512 x i32], align 16
@NSet = external dso_local local_unnamed_addr global [512 x i32], align 16
@NSetX = external dso_local local_unnamed_addr global [512 x [10 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8RND_Initv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z10InitTablesv() local_unnamed_addr #0 {
  tail call void @_Z8RND_Initv()
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) @B2V, i8 0, i64 2048, i1 false), !tbaa !5
  br label %1

1:                                                ; preds = %0, %10
  %indvars.iv24 = phi i64 [ 0, %0 ], [ %indvars.iv.next25, %10 ]
  %2 = getelementptr inbounds [512 x i32], ptr @NSet, i64 0, i64 %indvars.iv24
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not19 = icmp eq i64 %indvars.iv24, 0
  br i1 %.not19, label %10, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = trunc nuw nsw i64 %indvars.iv24 to i32
  br label %4

4:                                                ; preds = %.lr.ph, %4
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %4 ]
  %.020 = phi i32 [ %3, %.lr.ph ], [ %8, %4 ]
  %5 = sub nsw i32 0, %.020
  %6 = and i32 %.020, %5
  %7 = getelementptr inbounds [512 x [10 x i32]], ptr @NSetX, i64 0, i64 %indvars.iv24, i64 %indvars.iv
  store i32 %6, ptr %7, align 4, !tbaa !5
  %8 = xor i32 %6, %.020
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not = icmp eq i32 %6, %.020
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !9

._crit_edge:                                      ; preds = %4
  %9 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %9, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %._crit_edge, %1
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next25, 512
  br i1 %exitcond.not, label %.preheader.preheader, label %1, !llvm.loop !11

.preheader.preheader:                             ; preds = %10
  store i32 1, ptr getelementptr inbounds (i8, ptr @B2V, i64 4), align 4, !tbaa !5
  store i32 2, ptr getelementptr inbounds (i8, ptr @B2V, i64 8), align 8, !tbaa !5
  store i32 3, ptr getelementptr inbounds (i8, ptr @B2V, i64 16), align 16, !tbaa !5
  store i32 4, ptr getelementptr inbounds (i8, ptr @B2V, i64 32), align 16, !tbaa !5
  store i32 5, ptr getelementptr inbounds (i8, ptr @B2V, i64 64), align 16, !tbaa !5
  store i32 6, ptr getelementptr inbounds (i8, ptr @B2V, i64 128), align 16, !tbaa !5
  store i32 7, ptr getelementptr inbounds (i8, ptr @B2V, i64 256), align 16, !tbaa !5
  store i32 8, ptr getelementptr inbounds (i8, ptr @B2V, i64 512), align 16, !tbaa !5
  store i32 9, ptr getelementptr inbounds (i8, ptr @B2V, i64 1024), align 16, !tbaa !5
  ret i1 true
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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