; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Backtracking/Nqueen/nqueen.ll (Z5solveii)

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

@grid = external dso_local global [10 x [10 x i32]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5printi(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: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isSafeiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5solveii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z5printi(i32 noundef %12)
  store i1 true, ptr %3, align 1
  br label %55

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %49, %13
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = icmp sle i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %52

20:                                               ; preds = %14
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = call noundef zeroext i1 @_Z6isSafeiii(i32 noundef %21, i32 noundef %22, i32 noundef %23)
  br i1 %24, label %25, label %48

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x [10 x i32]], ptr @grid, i64 0, i64 %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x i32], ptr %28, i64 0, i64 %30
  store i32 1, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = call noundef zeroext i1 @_Z5solveii(i32 noundef %32, i32 noundef %34)
  br i1 %35, label %39, label %36

36:                                               ; preds = %25
  %37 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %38 = trunc i8 %37 to i1
  br label %39

39:                                               ; preds = %36, %25
  %40 = phi i1 [ true, %25 ], [ %38, %36 ]
  %41 = zext i1 %40 to i8
  store i8 %41, ptr %6, align 1, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10 x [10 x i32]], ptr @grid, i64 0, i64 %43
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [10 x i32], ptr %44, i64 0, i64 %46
  store i32 0, ptr %47, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %39, %20
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !13

52:                                               ; preds = %19
  %53 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %54 = trunc i8 %53 to i1
  store i1 %54, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %55

55:                                               ; preds = %52, %11
  %56 = load i1, ptr %3, align 1
  ret i1 %56
}

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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@grid = external dso_local local_unnamed_addr global [10 x [10 x i32]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isSafeiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5solveii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, %1
  br i1 %3, label %6, label %.preheader

.preheader:                                       ; preds = %2
  %.not.not22 = icmp sgt i32 %0, 0
  br i1 %.not.not22, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %4 = sext i32 %1 to i64
  %5 = add nsw i32 %1, 1
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %7

6:                                                ; preds = %2
  tail call void @_Z5printi(i32 noundef %0)
  br label %.loopexit

7:                                                ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %.01723 = phi i1 [ false, %.lr.ph ], [ %.1, %14 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = tail call noundef zeroext i1 @_Z6isSafeiii(i32 noundef %8, i32 noundef %1, i32 noundef %0)
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = getelementptr inbounds [10 x [10 x i32]], ptr @grid, i64 0, i64 %4, i64 %indvars.iv
  store i32 1, ptr %11, align 4, !tbaa !5
  %12 = tail call noundef zeroext i1 @_Z5solveii(i32 noundef %0, i32 noundef %5)
  %13 = select i1 %12, i1 true, i1 %.01723
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %7, %10
  %.1 = phi i1 [ %13, %10 ], [ %.01723, %7 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %7, !llvm.loop !9

.loopexit:                                        ; preds = %14, %.preheader, %6
  %.018 = phi i1 [ true, %6 ], [ false, %.preheader ], [ %.1, %14 ]
  ret i1 %.018
}

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


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass