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

%class.anon = type { ptr, ptr, ptr }
%class.anon.0 = type { i8 }

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

47:                                               ; preds = %52, %5
  %48 = load i64, ptr %14, align 8, !tbaa !5
  %49 = load i16, ptr %15, align 2, !tbaa !13
  %50 = zext i16 %49 to i64
  %51 = icmp uge i64 %48, %50
  br i1 %51, label %52, label %64

52:                                               ; preds = %47
  %53 = load i16, ptr %15, align 2, !tbaa !13
  %54 = zext i16 %53 to i64
  %55 = load i64, ptr %14, align 8, !tbaa !5
  %56 = sub i64 %55, %54
  store i64 %56, ptr %14, align 8, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !11
  %58 = add i32 %57, 1
  store i32 %58, ptr %12, align 4, !tbaa !11
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds i16, ptr %59, i64 %61
  %63 = load i16, ptr %62, align 2, !tbaa !13
  store i16 %63, ptr %15, align 2, !tbaa !13
  br label %47, !llvm.loop !15

64:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %65 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %65, ptr %16, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %80, %64
  %67 = load i64, ptr %16, align 8, !tbaa !5
  %68 = icmp ugt i64 %67, 0
  br i1 %68, label %69, label %97

69:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %70 = load i64, ptr %14, align 8, !tbaa !5
  %71 = load i64, ptr %16, align 8, !tbaa !5
  %72 = add i64 %70, %71
  store i64 %72, ptr %17, align 8, !tbaa !5
  %73 = load i64, ptr %17, align 8, !tbaa !5
  %74 = load i16, ptr %15, align 2, !tbaa !13
  %75 = zext i16 %74 to i64
  %76 = icmp ugt i64 %73, %75
  br i1 %76, label %77, label %80

77:                                               ; preds = %69
  %78 = load i16, ptr %15, align 2, !tbaa !13
  %79 = zext i16 %78 to i64
  store i64 %79, ptr %17, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %77, %69
  call void @llvm.lifetime.start.p0(i64 82, ptr %18) #4
  %81 = load i32, ptr %12, align 4, !tbaa !11
  %82 = getelementptr inbounds [82 x i8], ptr %18, i64 0, i64 0
  call void @GetPattern(i32 noundef %81, ptr noundef %82)
  call void @llvm.lifetime.start.p0(i64 24, ptr %19) #4
  %83 = getelementptr inbounds %class.anon, ptr %19, i32 0, i32 0
  store ptr %14, ptr %83, align 8, !tbaa !9
  %84 = getelementptr inbounds %class.anon, ptr %19, i32 0, i32 1
  store ptr %10, ptr %84, align 8, !tbaa !9
  %85 = getelementptr inbounds %class.anon, ptr %19, i32 0, i32 2
  store ptr %16, ptr %85, align 8, !tbaa !9
  %86 = getelementptr inbounds [82 x i8], ptr %18, i64 0, i64 0
  %87 = load i64, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %20) #4
  %88 = call noundef ptr @"_ZZ14EnumerateGridsENK3$_1cvPFvPKcPvEEv"(ptr noundef nonnull align 1 dereferenceable(1) %20) #4
  %89 = call i64 @TdokuEnumerate(ptr noundef %86, i64 noundef %87, ptr noundef %88, ptr noundef %19)
  call void @llvm.lifetime.end.p0(i64 1, ptr %20) #4
  %90 = load i32, ptr %12, align 4, !tbaa !11
  %91 = add i32 %90, 1
  store i32 %91, ptr %12, align 4, !tbaa !11
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  %93 = load i32, ptr %12, align 4, !tbaa !11
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds i16, ptr %92, i64 %94
  %96 = load i16, ptr %95, align 2, !tbaa !13
  store i16 %96, ptr %15, align 2, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 24, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 82, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %66, !llvm.loop !17

97:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret void
}

declare i64 @TdokuEnumerate(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @"_ZZ14EnumerateGridsENK3$_1cvPFvPKcPvEEv"(ptr noundef nonnull align 1 dereferenceable(1)) #3 align 2

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 = { "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 = { 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 #4 = { 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"}
!17 = distinct !{!17, !16}


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

%class.anon = type { ptr, ptr, ptr }
%class.anon.0 = type { i8 }

; Function Attrs: mustprogress uwtable
declare dso_local void @GetPattern(i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @EnumerateGrids(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca [82 x i8], align 16
  %10 = alloca %class.anon, align 8
  %11 = alloca %class.anon.0, align 1
  store ptr %4, ptr %6, align 8, !tbaa !5
  %12 = lshr i64 %0, 20
  %13 = mul nuw nsw i64 %12, 6
  %14 = getelementptr inbounds i8, ptr %2, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %14, i64 4
  %17 = load i16, ptr %16, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %18 = zext i16 %17 to i64
  %19 = and i64 %0, 1048575
  %20 = add nuw nsw i64 %19, %18
  %.pn32 = zext i32 %15 to i64
  %.023.in33 = getelementptr inbounds i16, ptr %3, i64 %.pn32
  %.02334 = load i16, ptr %.023.in33, align 2, !tbaa !11
  %21 = zext i16 %.02334 to i64
  %.not35 = icmp ult i64 %20, %21
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %22 = phi i64 [ %26, %.lr.ph ], [ %21, %5 ]
  %.02436 = phi i32 [ %25, %.lr.ph ], [ %15, %5 ]
  %23 = phi i64 [ %24, %.lr.ph ], [ %20, %5 ]
  %24 = sub i64 %23, %22
  %25 = add i32 %.02436, 1
  %.pn = zext i32 %25 to i64
  %.023.in = getelementptr inbounds i16, ptr %3, i64 %.pn
  %.023 = load i16, ptr %.023.in, align 2, !tbaa !11
  %26 = zext i16 %.023 to i64
  %.not = icmp ult i64 %24, %26
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.lcssa = phi i64 [ %20, %5 ], [ %24, %.lr.ph ]
  %.024.lcssa = phi i32 [ %15, %5 ], [ %25, %.lr.ph ]
  %.023.lcssa = phi i16 [ %.02334, %5 ], [ %.023, %.lr.ph ]
  store i64 %.lcssa, ptr %7, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  store i64 %1, ptr %8, align 8, !tbaa !15
  %.not3139 = icmp eq i64 %1, 0
  br i1 %.not3139, label %._crit_edge44, label %.lr.ph43

.lr.ph43:                                         ; preds = %._crit_edge
  %27 = getelementptr inbounds i8, ptr %10, i64 8
  %28 = getelementptr inbounds i8, ptr %10, i64 16
  br label %29

29:                                               ; preds = %.lr.ph43, %29
  %.141 = phi i16 [ %.023.lcssa, %.lr.ph43 ], [ %39, %29 ]
  %.12540 = phi i32 [ %.024.lcssa, %.lr.ph43 ], [ %36, %29 ]
  %30 = phi i64 [ %1, %.lr.ph43 ], [ %.pr, %29 ]
  %31 = load i64, ptr %7, align 8, !tbaa !15
  %32 = add i64 %31, %30
  %33 = zext i16 %.141 to i64
  %spec.select = call i64 @llvm.umin.i64(i64 %32, i64 %33)
  call void @llvm.lifetime.start.p0(i64 82, ptr nonnull %9) #5
  call void @GetPattern(i32 noundef %.12540, ptr noundef nonnull %9)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #5
  store ptr %7, ptr %10, align 8, !tbaa !5
  store ptr %6, ptr %27, align 8, !tbaa !5
  store ptr %8, ptr %28, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %11) #5
  %34 = call noundef ptr @"_ZZ14EnumerateGridsENK3$_1cvPFvPKcPvEEv"(ptr noundef nonnull align 1 dereferenceable(1) %11) #5
  %35 = call i64 @TdokuEnumerate(ptr noundef nonnull %9, i64 noundef %spec.select, ptr noundef %34, ptr noundef nonnull %10)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %11) #5
  %36 = add i32 %.12540, 1
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i16, ptr %3, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 82, ptr nonnull %9) #5
  %.pr = load i64, ptr %8, align 8, !tbaa !15
  %.not31 = icmp eq i64 %.pr, 0
  br i1 %.not31, label %._crit_edge44, label %29, !llvm.loop !17

._crit_edge44:                                    ; preds = %29, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  ret void
}

declare i64 @TdokuEnumerate(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @"_ZZ14EnumerateGridsENK3$_1cvPFvPKcPvEEv"(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #3 align 2

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

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 = { "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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !14}


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