; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x27-A-Star/179. 八数码.ll (Z10isSolvableRK1P)

; 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.P = type { [3 x [3 x i32]], i32, [10 x %"struct.std::pair"], %"class.std::__cxx11::basic_string" }
%"struct.std::pair" = type { i32, i32 }
%"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] }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9mergeSortPiiiRi(ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z10isSolvableRK1P(ptr noundef nonnull align 8 dereferenceable(152) %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca [8 x i32], align 16
  %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
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %49, %1
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 3
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %52

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

15:                                               ; preds = %45, %14
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 3
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %48

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.P, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [3 x [3 x i32]], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [3 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 9
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  br label %45

31:                                               ; preds = %19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.P, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [3 x [3 x i32]], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [3 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [8 x i32], ptr %4, i64 0, i64 %43
  store i32 %40, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %31, %30
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !11

48:                                               ; preds = %18
  br label %49

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

52:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  %53 = getelementptr inbounds [8 x i32], ptr %4, i64 0, i64 0
  call void @_Z9mergeSortPiiiRi(ptr noundef %53, i32 noundef 0, i32 noundef 7, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = srem i32 %54, 2
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %59

58:                                               ; preds = %52
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %59

59:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #2
  %60 = load i1, ptr %2, align 1
  ret i1 %60
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9mergeSortPiiiRi(ptr noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z10isSolvableRK1P(ptr nocapture noundef nonnull readonly align 8 dereferenceable(152) %0) local_unnamed_addr #1 {
.preheader:
  %1 = alloca [8 x i32], align 16
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #2
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 9
  br i1 %4, label %6, label %5

5:                                                ; preds = %.preheader
  store i32 %3, ptr %1, align 16, !tbaa !5
  br label %6

6:                                                ; preds = %.preheader, %5
  %.2 = phi i32 [ 0, %.preheader ], [ 1, %5 ]
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 9
  br i1 %9, label %14, label %10

10:                                               ; preds = %6
  %11 = add nuw nsw i32 %.2, 1
  %12 = zext nneg i32 %.2 to i64
  %13 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %12
  store i32 %8, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %10, %6
  %.2.1 = phi i32 [ %.2, %6 ], [ %11, %10 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = icmp eq i32 %16, 9
  br i1 %17, label %.preheader.1, label %18

18:                                               ; preds = %14
  %19 = add nuw nsw i32 %.2.1, 1
  %20 = zext nneg i32 %.2.1 to i64
  %21 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %20
  store i32 %16, ptr %21, align 4, !tbaa !5
  br label %.preheader.1

.preheader.1:                                     ; preds = %18, %14
  %.2.2 = phi i32 [ %.2.1, %14 ], [ %19, %18 ]
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 9
  br i1 %24, label %29, label %25

25:                                               ; preds = %.preheader.1
  %26 = add nuw nsw i32 %.2.2, 1
  %27 = zext nneg i32 %.2.2 to i64
  %28 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %27
  store i32 %23, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %25, %.preheader.1
  %.2.121 = phi i32 [ %.2.2, %.preheader.1 ], [ %26, %25 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = icmp eq i32 %31, 9
  br i1 %32, label %37, label %33

33:                                               ; preds = %29
  %34 = add nuw nsw i32 %.2.121, 1
  %35 = zext nneg i32 %.2.121 to i64
  %36 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %35
  store i32 %31, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %33, %29
  %.2.1.1 = phi i32 [ %.2.121, %29 ], [ %34, %33 ]
  %38 = getelementptr inbounds i8, ptr %0, i64 20
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 9
  br i1 %40, label %.preheader.2, label %41

41:                                               ; preds = %37
  %42 = add nuw nsw i32 %.2.1.1, 1
  %43 = zext nneg i32 %.2.1.1 to i64
  %44 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %43
  store i32 %39, ptr %44, align 4, !tbaa !5
  br label %.preheader.2

.preheader.2:                                     ; preds = %41, %37
  %.2.2.1 = phi i32 [ %.2.1.1, %37 ], [ %42, %41 ]
  %45 = getelementptr inbounds i8, ptr %0, i64 24
  %46 = load i32, ptr %45, align 8, !tbaa !5
  %47 = icmp eq i32 %46, 9
  br i1 %47, label %52, label %48

48:                                               ; preds = %.preheader.2
  %49 = add nuw nsw i32 %.2.2.1, 1
  %50 = zext nneg i32 %.2.2.1 to i64
  %51 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %50
  store i32 %46, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %48, %.preheader.2
  %.2.222 = phi i32 [ %.2.2.1, %.preheader.2 ], [ %49, %48 ]
  %53 = getelementptr inbounds i8, ptr %0, i64 28
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp eq i32 %54, 9
  br i1 %55, label %60, label %56

56:                                               ; preds = %52
  %57 = add nuw nsw i32 %.2.222, 1
  %58 = zext nneg i32 %.2.222 to i64
  %59 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %58
  store i32 %54, ptr %59, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %56, %52
  %.2.1.2 = phi i32 [ %.2.222, %52 ], [ %57, %56 ]
  %61 = getelementptr inbounds i8, ptr %0, i64 32
  %62 = load i32, ptr %61, align 8, !tbaa !5
  %63 = icmp eq i32 %62, 9
  br i1 %63, label %67, label %64

64:                                               ; preds = %60
  %65 = zext nneg i32 %.2.1.2 to i64
  %66 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %65
  store i32 %62, ptr %66, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %64, %60
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @_Z9mergeSortPiiiRi(ptr noundef nonnull %1, i32 noundef 0, i32 noundef 7, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = and i32 %68, 1
  %70 = icmp eq i32 %69, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #2
  ret i1 %70
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass