; LLVM IR from t-dillon/tdoku :: other/zerodoku (zerodoku_v2)

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

%struct.Puzzle = type { [81 x i32], [9 x i32], [9 x i32], [9 x i32], i32 }

@maxSolutions = external dso_local global i32, align 4
@p = external dso_local global %struct.Puzzle, align 4
@numGuesses = external dso_local global ptr, align 8
@uninitialized = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @set(i32 noundef, i32 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: nounwind uwtable
declare dso_local i32 @backTrackSolve() #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @OtherSolverZeroDoku(ptr noundef %0, i64 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load i32, ptr @uninitialized, align 4, !tbaa !11
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %5
  call void @initializeTables()
  br label %15

15:                                               ; preds = %14, %5
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr @maxSolutions, align 4, !tbaa !11
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %18, ptr @numGuesses, align 8, !tbaa !5
  %19 = load ptr, ptr @numGuesses, align 8, !tbaa !5
  store i64 0, ptr %19, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 4 @p, i8 0, i64 436, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %43, %15
  %21 = load i32, ptr %11, align 4, !tbaa !11
  %22 = icmp slt i32 %21, 81
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %20
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = sext i8 %29 to i32
  %31 = icmp ne i32 %30, 46
  br i1 %31, label %32, label %42

32:                                               ; preds = %24
  %33 = load i32, ptr %11, align 4, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = sext i8 %38 to i32
  %40 = sub nsw i32 %39, 48
  %41 = shl i32 1, %40
  call void @set(i32 noundef %33, i32 noundef %41)
  br label %42

42:                                               ; preds = %32, %24
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !11
  br label %20, !llvm.loop !14

46:                                               ; preds = %23
  %47 = call i32 @backTrackSolve()
  %48 = sext i32 %47 to i64
  ret i64 %48
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.Puzzle = type { [81 x i32], [9 x i32], [9 x i32], [9 x i32], i32 }

@maxSolutions = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global %struct.Puzzle, align 4
@numGuesses = external dso_local local_unnamed_addr global ptr, align 8
@uninitialized = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @set(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @backTrackSolve() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @OtherSolverZeroDoku(ptr nocapture noundef readonly %0, i64 noundef %1, i32 noundef %2, ptr nocapture noundef readnone %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr @uninitialized, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %8, label %7

7:                                                ; preds = %5
  tail call void @initializeTables()
  br label %8

8:                                                ; preds = %7, %5
  %9 = trunc i64 %1 to i32
  store i32 %9, ptr @maxSolutions, align 4, !tbaa !5
  store ptr %4, ptr @numGuesses, align 8, !tbaa !9
  store i64 0, ptr %4, align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(436) @p, i8 0, i64 436, i1 false)
  br label %13

10:                                               ; preds = %21
  %11 = tail call i32 @backTrackSolve()
  %12 = sext i32 %11 to i64
  ret i64 %12

13:                                               ; preds = %8, %21
  %indvars.iv = phi i64 [ 0, %8 ], [ %indvars.iv.next, %21 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %15 = load i8, ptr %14, align 1, !tbaa !13
  %.not9 = icmp eq i8 %15, 46
  br i1 %.not9, label %21, label %16

16:                                               ; preds = %13
  %17 = sext i8 %15 to i32
  %18 = add nsw i32 %17, -48
  %19 = shl nuw i32 1, %18
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @set(i32 noundef %20, i32 noundef %19)
  br label %21

21:                                               ; preds = %13, %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 81
  br i1 %exitcond.not, label %10, label %13, !llvm.loop !14
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { 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 = { mustprogress 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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