; LLVM IR from t-dillon/tdoku :: src (grid_lib)

; 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 uwtable
declare dso_local void @GetPattern(i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @GetGrid(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca i64, align 8
  %13 = alloca i16, align 2
  %14 = alloca [82 x i8], align 16
  %15 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = and i64 %16, -1048576
  store i64 %17, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = lshr i64 %19, 20
  %21 = mul i64 %20, 6
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !11
  store i32 %23, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = lshr i64 %25, 20
  %27 = mul i64 %26, 6
  %28 = getelementptr inbounds i8, ptr %24, i64 %27
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  %30 = load i16, ptr %29, align 2, !tbaa !13
  store i16 %30, ptr %11, align 2, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %31 = load i16, ptr %11, align 2, !tbaa !13
  %32 = zext i16 %31 to i64
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !5
  %35 = sub i64 %33, %34
  %36 = add i64 %32, %35
  store i64 %36, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i16, ptr %37, i64 %39
  %41 = load i16, ptr %40, align 2, !tbaa !13
  store i16 %41, ptr %13, align 2, !tbaa !13
  br label %42

42:                                               ; preds = %47, %4
  %43 = load i64, ptr %12, align 8, !tbaa !5
  %44 = load i16, ptr %13, align 2, !tbaa !13
  %45 = zext i16 %44 to i64
  %46 = icmp uge i64 %43, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %42
  %48 = load i16, ptr %13, align 2, !tbaa !13
  %49 = zext i16 %48 to i64
  %50 = load i64, ptr %12, align 8, !tbaa !5
  %51 = sub i64 %50, %49
  store i64 %51, ptr %12, align 8, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = add i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !11
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = load i32, ptr %10, align 4, !tbaa !11
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i16, ptr %54, i64 %56
  %58 = load i16, ptr %57, align 2, !tbaa !13
  store i16 %58, ptr %13, align 2, !tbaa !13
  br label %42, !llvm.loop !15

59:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 82, ptr %14) #3
  %60 = load i32, ptr %10, align 4, !tbaa !11
  %61 = getelementptr inbounds [82 x i8], ptr %14, i64 0, i64 0
  call void @GetPattern(i32 noundef %60, ptr noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %62 = getelementptr inbounds [82 x i8], ptr %14, i64 0, i64 0
  %63 = load i64, ptr %12, align 8, !tbaa !5
  %64 = add i64 %63, 1
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  %66 = call noundef i64 @_ZL11SolveSudokuPKcmjPcPm(ptr noundef %62, i64 noundef %64, i32 noundef 1, ptr noundef %65, ptr noundef %15)
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 82, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i64 @_ZL11SolveSudokuPKcmjPcPm(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 uwtable
declare dso_local void @GetPattern(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @GetGrid(i64 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca [82 x i8], align 16
  %6 = alloca i64, align 8
  %7 = lshr i64 %0, 20
  %8 = mul nuw nsw i64 %7, 6
  %9 = getelementptr inbounds i8, ptr %1, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %9, i64 4
  %12 = load i16, ptr %11, align 2, !tbaa !9
  %13 = zext i16 %12 to i64
  %14 = and i64 %0, 1048575
  %15 = add nuw nsw i64 %14, %13
  %.pn22 = zext i32 %10 to i64
  %.0.in23 = getelementptr inbounds i16, ptr %2, i64 %.pn22
  %.024 = load i16, ptr %.0.in23, align 2, !tbaa !9
  %16 = zext i16 %.024 to i64
  %.not25 = icmp ult i64 %15, %16
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %17 = phi i64 [ %20, %.lr.ph ], [ %16, %4 ]
  %.01927 = phi i64 [ %18, %.lr.ph ], [ %15, %4 ]
  %.02026 = phi i32 [ %19, %.lr.ph ], [ %10, %4 ]
  %18 = sub i64 %.01927, %17
  %19 = add i32 %.02026, 1
  %.pn = zext i32 %19 to i64
  %.0.in = getelementptr inbounds i16, ptr %2, i64 %.pn
  %.0 = load i16, ptr %.0.in, align 2, !tbaa !9
  %20 = zext i16 %.0 to i64
  %.not = icmp ult i64 %18, %20
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.020.lcssa = phi i32 [ %10, %4 ], [ %19, %.lr.ph ]
  %.019.lcssa = phi i64 [ %15, %4 ], [ %18, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 82, ptr nonnull %5) #3
  call void @GetPattern(i32 noundef %.020.lcssa, ptr noundef nonnull %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %21 = add nuw nsw i64 %.019.lcssa, 1
  %22 = call noundef i64 @_ZL11SolveSudokuPKcmjPcPm(ptr noundef nonnull %5, i64 noundef %21, i32 noundef 1, ptr noundef %3, ptr noundef nonnull %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 82, ptr nonnull %5) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i64 @_ZL11SolveSudokuPKcmjPcPm(ptr noundef, i64 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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