; LLVM IR from sgtlaugh/algovault :: code_library/misc (n_queen)

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

@counter = external dso_local global i32, align 4
@lim = external dso_local global i32, align 4

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

14:                                               ; preds = %4
  %15 = load i32, ptr @counter, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @counter, align 4, !tbaa !5
  br label %58

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %5, align 4, !tbaa !5
  %20 = load i32, ptr @lim, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = or i32 %21, %22
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = or i32 %23, %24
  %26 = xor i32 %25, -1
  %27 = and i32 %20, %26
  store i32 %27, ptr %9, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %39, %17
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %55

31:                                               ; preds = %28
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = sub nsw i32 0, %32
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = and i32 %33, %34
  store i32 %35, ptr %10, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  store i32 1, ptr %11, align 4
  br label %56

39:                                               ; preds = %31
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = xor i32 %41, %40
  store i32 %42, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = or i32 %44, %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = or i32 %47, %48
  %50 = shl i32 %49, 1
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = or i32 %51, %52
  %54 = ashr i32 %53, 1
  call void @backtrack(i32 noundef %43, i32 noundef %46, i32 noundef %50, i32 noundef %54)
  br label %28, !llvm.loop !9

55:                                               ; preds = %28
  store i32 0, ptr %11, align 4
  br label %56

56:                                               ; preds = %55, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %57 = load i32, ptr %11, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56, %14
  ret void

59:                                               ; preds = %56
  unreachable
}

; 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

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@counter = external dso_local local_unnamed_addr global i32, align 4
@lim = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @backtrack(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %5, label %8

5:                                                ; preds = %4
  %6 = load i32, ptr @counter, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @counter, align 4, !tbaa !5
  br label %.loopexit

8:                                                ; preds = %4
  %9 = add nsw i32 %0, -1
  %10 = load i32, ptr @lim, align 4, !tbaa !5
  %11 = or i32 %2, %1
  %12 = or i32 %11, %3
  %13 = xor i32 %12, -1
  %14 = and i32 %10, %13
  %.not2022 = icmp eq i32 %14, 0
  br i1 %.not2022, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8, %17
  %.023 = phi i32 [ %18, %17 ], [ %14, %8 ]
  %15 = sub nsw i32 0, %.023
  %16 = and i32 %.023, %15
  %.not21 = icmp eq i32 %16, 0
  br i1 %.not21, label %.loopexit, label %17

17:                                               ; preds = %.lr.ph
  %18 = xor i32 %16, %.023
  %19 = or i32 %16, %1
  %20 = or i32 %16, %2
  %21 = shl i32 %20, 1
  %22 = or i32 %16, %3
  %23 = ashr i32 %22, 1
  tail call void @backtrack(i32 noundef %9, i32 noundef %19, i32 noundef %21, i32 noundef %23)
  %.not20 = icmp eq i32 %16, %.023
  br i1 %.not20, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit:                                        ; preds = %17, %.lr.ph, %8, %5
  ret void
}

attributes #0 = { nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass