; LLVM IR from eyangch/competitive-programming :: CSES/Introductory_Problems/chessboard_and_queens.ll (Z3dfsiiiii)

; 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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z2cbB5cxx11 = external dso_local global [8 x %"class.std::__cxx11::basic_string"], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = shl i32 1, %16
  store i32 %17, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  %21 = shl i32 1, %20
  store i32 %21, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = add nsw i32 %24, 7
  %26 = shl i32 1, %25
  store i32 %26, ptr %13, align 4, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = and i32 %27, %28
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %51, label %31

31:                                               ; preds = %5
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = and i32 %32, %33
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %51, label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = and i32 %37, %38
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %51, label %41

41:                                               ; preds = %36
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [8 x %"class.std::__cxx11::basic_string"], ptr @_Z2cbB5cxx11, i64 0, i64 %43
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %44, i64 noundef %46)
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 42
  br i1 %50, label %51, label %52

51:                                               ; preds = %41, %36, %31, %5
  store i32 1, ptr %14, align 4
  br label %84

52:                                               ; preds = %41
  %53 = load i32, ptr %11, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = or i32 %54, %53
  store i32 %55, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = or i32 %57, %56
  store i32 %58, ptr %9, align 4, !tbaa !5
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = or i32 %60, %59
  store i32 %61, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = icmp eq i32 %62, 7
  br i1 %63, label %64, label %67

64:                                               ; preds = %52
  %65 = load i32, ptr @ans, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr @ans, align 4, !tbaa !5
  br label %83

67:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %79, %67
  %69 = load i32, ptr %15, align 4, !tbaa !5
  %70 = icmp slt i32 %69, 8
  br i1 %70, label %72, label %71

71:                                               ; preds = %68
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %82

72:                                               ; preds = %68
  %73 = load i32, ptr %15, align 4, !tbaa !5
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z3dfsiiiii(i32 noundef %73, i32 noundef %75, i32 noundef %76, i32 noundef %77, i32 noundef %78)
  br label %79

79:                                               ; preds = %72
  %80 = load i32, ptr %15, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %15, align 4, !tbaa !5
  br label %68, !llvm.loop !10

82:                                               ; preds = %71
  br label %83

83:                                               ; preds = %82, %64
  store i32 0, ptr %14, align 4
  br label %84

84:                                               ; preds = %83, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %85 = load i32, ptr %14, align 4
  switch i32 %85, label %87 [
    i32 0, label %86
    i32 1, label %86
  ]

86:                                               ; preds = %84, %84
  ret void

87:                                               ; preds = %84
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 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 = { 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 #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z2cbB5cxx11 = external dso_local global [8 x %"class.std::__cxx11::basic_string"], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.preheader, %5
  %.tr = phi i32 [ %0, %5 ], [ 7, %.preheader ]
  %.tr32 = phi i32 [ %1, %5 ], [ %27, %.preheader ]
  %.tr33 = phi i32 [ %2, %5 ], [ %26, %.preheader ]
  %.tr34 = phi i32 [ %3, %5 ], [ %25, %.preheader ]
  %.tr35 = phi i32 [ %4, %5 ], [ %24, %.preheader ]
  %6 = shl nuw i32 1, %.tr
  %7 = add nsw i32 %.tr32, %.tr
  %8 = shl nuw i32 1, %7
  %9 = add i32 %.tr, 7
  %10 = sub i32 %9, %.tr32
  %11 = shl nuw i32 1, %10
  %12 = and i32 %6, %.tr33
  %.not = icmp eq i32 %12, 0
  %13 = and i32 %8, %.tr34
  %.not28 = icmp eq i32 %13, 0
  %or.cond = select i1 %.not, i1 %.not28, i1 false
  %14 = and i32 %11, %.tr35
  %.not29 = icmp eq i32 %14, 0
  %or.cond30 = select i1 %or.cond, i1 %.not29, i1 false
  br i1 %or.cond30, label %15, label %.loopexit

15:                                               ; preds = %tailrecurse
  %16 = sext i32 %.tr to i64
  %17 = getelementptr inbounds [8 x %"class.std::__cxx11::basic_string"], ptr @_Z2cbB5cxx11, i64 0, i64 %16
  %18 = sext i32 %.tr32 to i64
  %19 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %17, i64 noundef %18)
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = icmp eq i8 %20, 42
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %15
  %23 = icmp eq i32 %.tr32, 7
  br i1 %23, label %28, label %.preheader

.preheader:                                       ; preds = %22
  %24 = or i32 %11, %.tr35
  %25 = or i32 %8, %.tr34
  %26 = or i32 %6, %.tr33
  %27 = add nsw i32 %.tr32, 1
  tail call void @_Z3dfsiiiii(i32 noundef 0, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 1, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 2, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 3, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 4, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 5, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  tail call void @_Z3dfsiiiii(i32 noundef 6, i32 noundef %27, i32 noundef %26, i32 noundef %25, i32 noundef %24)
  br label %tailrecurse

28:                                               ; preds = %22
  %29 = load i32, ptr @ans, align 4, !tbaa !8
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @ans, align 4, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %28, %tailrecurse, %15
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass