; LLVM IR from xuxping/codelife :: algorthms/greedy (8queue)

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

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

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

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  call void @display(ptr noundef %9)
  br label %34

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %31, %10
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 8
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %34

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = call i32 @isOk(ptr noundef %16, i32 noundef %17, i32 noundef %18)
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %30

21:                                               ; preds = %15
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  call void @cal8queue(ptr noundef %27, i32 noundef %29)
  br label %30

30:                                               ; preds = %21, %15
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !9
  br label %11, !llvm.loop !11

34:                                               ; preds = %14, %8
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @display(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cal8queue(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %38, %2
  %.tr13 = phi i32 [ %1, %2 ], [ %6, %38 ]
  %3 = icmp eq i32 %.tr13, 8
  br i1 %3, label %9, label %.preheader

.preheader:                                       ; preds = %tailrecurse
  %4 = sext i32 %.tr13 to i64
  %5 = getelementptr inbounds i32, ptr %0, i64 %4
  %6 = add nsw i32 %.tr13, 1
  %7 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 0)
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %10, label %11

9:                                                ; preds = %tailrecurse
  tail call void @display(ptr noundef %0)
  br label %.loopexit

10:                                               ; preds = %.preheader
  store i32 0, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %11

11:                                               ; preds = %.preheader, %10
  %12 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 1)
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 1, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %15

15:                                               ; preds = %14, %11
  %16 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 2)
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 2, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %19

19:                                               ; preds = %18, %15
  %20 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 3)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 3, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %23

23:                                               ; preds = %22, %19
  %24 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 4)
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 4, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %27

27:                                               ; preds = %26, %23
  %28 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 5)
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 5, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %31

31:                                               ; preds = %30, %27
  %32 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 6)
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i32 6, ptr %5, align 4, !tbaa !5
  tail call void @cal8queue(ptr noundef %0, i32 noundef %6)
  br label %35

35:                                               ; preds = %34, %31
  %36 = tail call i32 @isOk(ptr noundef %0, i32 noundef %.tr13, i32 noundef 7)
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %.loopexit

38:                                               ; preds = %35
  store i32 7, ptr %5, align 4, !tbaa !5
  br label %tailrecurse

.loopexit:                                        ; preds = %35, %9
  ret void
}

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

!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"}


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