; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @backTrackSolve() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = load i32, ptr getelementptr inbounds (%struct.Puzzle, ptr @p, i32 0, i32 4), align 4, !tbaa !5
  %9 = icmp eq i32 %8, 81
  br i1 %9, label %10, label %11

10:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  br label %66

11:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 -1, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 -1, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = call i32 @findSingles(ptr noundef %4, ptr noundef %5)
  store i32 %12, ptr %6, align 4, !tbaa !10
  %13 = load i32, ptr %6, align 4, !tbaa !10
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %65

16:                                               ; preds = %11
  %17 = load i32, ptr %6, align 4, !tbaa !10
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load i32, ptr %4, align 4, !tbaa !10
  %21 = load i32, ptr %5, align 4, !tbaa !10
  call void @set(i32 noundef %20, i32 noundef %21)
  %22 = call i32 @backTrackSolve()
  store i32 %22, ptr %3, align 4, !tbaa !10
  %23 = load i32, ptr %4, align 4, !tbaa !10
  call void @clear(i32 noundef %23)
  %24 = load i32, ptr %3, align 4, !tbaa !10
  store i32 %24, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %65

25:                                               ; preds = %16
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %5, align 4, !tbaa !10
  %28 = load i32, ptr %5, align 4, !tbaa !10
  %29 = sub nsw i32 0, %28
  %30 = and i32 %27, %29
  store i32 %30, ptr %2, align 4, !tbaa !10
  br label %31

31:                                               ; preds = %58, %26
  %32 = load i32, ptr %5, align 4, !tbaa !10
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %63

34:                                               ; preds = %31
  %35 = load i32, ptr %2, align 4, !tbaa !10
  %36 = xor i32 %35, -1
  %37 = load i32, ptr %5, align 4, !tbaa !10
  %38 = and i32 %37, %36
  store i32 %38, ptr %5, align 4, !tbaa !10
  %39 = load i32, ptr %5, align 4, !tbaa !10
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %45

41:                                               ; preds = %34
  %42 = load ptr, ptr @numGuesses, align 8, !tbaa !11
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = add i64 %43, 1
  store i64 %44, ptr %42, align 8, !tbaa !13
  br label %45

45:                                               ; preds = %41, %34
  %46 = load i32, ptr %4, align 4, !tbaa !10
  %47 = load i32, ptr %2, align 4, !tbaa !10
  call void @set(i32 noundef %46, i32 noundef %47)
  %48 = call i32 @backTrackSolve()
  %49 = load i32, ptr %3, align 4, !tbaa !10
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %3, align 4, !tbaa !10
  %51 = load i32, ptr %3, align 4, !tbaa !10
  %52 = load i32, ptr @maxSolutions, align 4, !tbaa !10
  %53 = icmp uge i32 %51, %52
  br i1 %53, label %54, label %56

54:                                               ; preds = %45
  %55 = load i32, ptr %3, align 4, !tbaa !10
  store i32 %55, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %65

56:                                               ; preds = %45
  %57 = load i32, ptr %4, align 4, !tbaa !10
  call void @clear(i32 noundef %57)
  br label %58

58:                                               ; preds = %56
  %59 = load i32, ptr %5, align 4, !tbaa !10
  %60 = load i32, ptr %5, align 4, !tbaa !10
  %61 = sub nsw i32 0, %60
  %62 = and i32 %59, %61
  store i32 %62, ptr %2, align 4, !tbaa !10
  br label %31, !llvm.loop !15

63:                                               ; preds = %31
  %64 = load i32, ptr %3, align 4, !tbaa !10
  store i32 %64, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %63, %54, %19, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %66

66:                                               ; preds = %65, %10
  %67 = load i32, ptr %1, align 4
  ret i32 %67
}

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 = { 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, !9, i64 432}
!6 = !{!"Puzzle", !7, i64 0, !7, i64 324, !7, i64 360, !7, i64 396, !9, i64 432}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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"

%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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @backTrackSolve() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 432), align 4, !tbaa !5
  %4 = icmp eq i32 %3, 81
  br i1 %4, label %33, label %5

5:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #2
  store i32 -1, ptr %1, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  store i32 -1, ptr %2, align 4, !tbaa !10
  %6 = call i32 @findSingles(ptr noundef nonnull %1, ptr noundef nonnull %2)
  switch i32 %6, label %12 [
    i32 0, label %.loopexit
    i32 1, label %7
  ]

7:                                                ; preds = %5
  %8 = load i32, ptr %1, align 4, !tbaa !10
  %9 = load i32, ptr %2, align 4, !tbaa !10
  call void @set(i32 noundef %8, i32 noundef %9)
  %10 = call i32 @backTrackSolve()
  %11 = load i32, ptr %1, align 4, !tbaa !10
  call void @clear(i32 noundef %11)
  br label %.loopexit

12:                                               ; preds = %5
  %13 = load i32, ptr %2, align 4, !tbaa !10
  %.not18 = icmp eq i32 %13, 0
  br i1 %.not18, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  %14 = sub nsw i32 0, %13
  %15 = and i32 %13, %14
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %.01020 = phi i32 [ %26, %28 ], [ 0, %.lr.ph.preheader ]
  %.01119 = phi i32 [ %32, %28 ], [ %15, %.lr.ph.preheader ]
  %16 = phi i32 [ %30, %28 ], [ %13, %.lr.ph.preheader ]
  %17 = xor i32 %.01119, -1
  %18 = and i32 %16, %17
  store i32 %18, ptr %2, align 4, !tbaa !10
  %.not16 = icmp eq i32 %18, 0
  br i1 %.not16, label %23, label %19

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr @numGuesses, align 8, !tbaa !11
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = add i64 %21, 1
  store i64 %22, ptr %20, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %19, %.lr.ph
  %24 = load i32, ptr %1, align 4, !tbaa !10
  call void @set(i32 noundef %24, i32 noundef %.01119)
  %25 = call i32 @backTrackSolve()
  %26 = add nsw i32 %25, %.01020
  %27 = load i32, ptr @maxSolutions, align 4, !tbaa !10
  %.not17 = icmp ult i32 %26, %27
  br i1 %.not17, label %28, label %.loopexit

28:                                               ; preds = %23
  %29 = load i32, ptr %1, align 4, !tbaa !10
  call void @clear(i32 noundef %29)
  %30 = load i32, ptr %2, align 4, !tbaa !10
  %31 = sub nsw i32 0, %30
  %32 = and i32 %30, %31
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %23, %28, %12, %5, %7
  %.0 = phi i32 [ %10, %7 ], [ %6, %5 ], [ 0, %12 ], [ %26, %28 ], [ %26, %23 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #2
  br label %33

33:                                               ; preds = %0, %.loopexit
  %.1 = phi i32 [ %.0, %.loopexit ], [ 1, %0 ]
  ret i32 %.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 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, !9, i64 432}
!6 = !{!"Puzzle", !7, i64 0, !7, i64 324, !7, i64 360, !7, i64 396, !9, i64 432}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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