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

; 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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }
%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] }

@manhattonCache = external dso_local global %"class.std::unordered_map", align 8

; 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
define dso_local noundef i32 @_Z9manhattonR1P(ptr noundef nonnull align 8 dereferenceable(152) %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call noundef i64 @_ZNKSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEE5countERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %7)
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %11)
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %2, align 4
  br label %56

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

15:                                               ; preds = %48, %14
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp sle i32 %16, 9
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %51

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.P, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x %"struct.std::pair"], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds %"struct.std::pair", ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sub nsw i32 %27, 1
  %29 = sdiv i32 %28, 3
  %30 = sub nsw i32 %26, %29
  %31 = call i32 @llvm.abs.i32(i32 %30, i1 true)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.P, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x %"struct.std::pair"], ptr %33, i64 0, i64 %35
  %37 = getelementptr inbounds %"struct.std::pair", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = srem i32 %40, 3
  %42 = sub nsw i32 %38, %41
  %43 = call i32 @llvm.abs.i32(i32 %42, i1 true)
  %44 = add nsw i32 %31, %43
  store i32 %44, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = add nsw i32 %46, %45
  store i32 %47, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %48

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

51:                                               ; preds = %18
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %53)
  store i32 %52, ptr %54, align 4, !tbaa !9
  %55 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %55, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %56

56:                                               ; preds = %51, %10
  %57 = load i32, ptr %2, align 4
  ret i32 %57
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEE5countERS6_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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 = !{!12, !10, i64 0}
!12 = !{!"_ZTSSt4pairIiiE", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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::unordered_map" = type { %"class.std::_Hashtable" }
%"class.std::_Hashtable" = type { ptr, i64, %"struct.std::__detail::_Hash_node_base", i64, %"struct.std::__detail::_Prime_rehash_policy", ptr }
%"struct.std::__detail::_Hash_node_base" = type { ptr }
%"struct.std::__detail::_Prime_rehash_policy" = type { float, i64 }

@manhattonCache = external dso_local global %"class.std::unordered_map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9manhattonR1P(ptr noundef nonnull align 8 dereferenceable(152) %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEE5countERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %0)
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %.preheader, label %48

.preheader:                                       ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 @llvm.abs.i32(i32 %4, i1 true)
  %6 = getelementptr inbounds i8, ptr %0, i64 52
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = tail call i32 @llvm.abs.i32(i32 %7, i1 true)
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = tail call i32 @llvm.abs.i32(i32 %10, i1 true)
  %12 = getelementptr inbounds i8, ptr %0, i64 60
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = add nsw i32 %13, -1
  %15 = tail call i32 @llvm.abs.i32(i32 %14, i1 true)
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = tail call i32 @llvm.abs.i32(i32 %17, i1 true)
  %19 = getelementptr inbounds i8, ptr %0, i64 68
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = add nsw i32 %20, -2
  %22 = tail call i32 @llvm.abs.i32(i32 %21, i1 true)
  %23 = getelementptr inbounds i8, ptr %0, i64 72
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = add i32 %24, -1
  %26 = tail call i32 @llvm.abs.i32(i32 %25, i1 true)
  %27 = getelementptr inbounds i8, ptr %0, i64 76
  %28 = load i32, ptr %27, align 4, !tbaa !10
  %29 = tail call i32 @llvm.abs.i32(i32 %28, i1 true)
  %30 = getelementptr inbounds i8, ptr %0, i64 80
  %31 = load <4 x i32>, ptr %30, align 8, !tbaa !11
  %32 = add <4 x i32> %31, <i32 -1, i32 -1, i32 -1, i32 -2>
  %33 = tail call <4 x i32> @llvm.abs.v4i32(<4 x i32> %32, i1 true)
  %34 = getelementptr inbounds i8, ptr %0, i64 96
  %35 = load i32, ptr %34, align 8, !tbaa !5
  %36 = add i32 %35, -2
  %37 = tail call i32 @llvm.abs.i32(i32 %36, i1 true)
  %38 = getelementptr inbounds i8, ptr %0, i64 100
  %39 = load i32, ptr %38, align 4, !tbaa !10
  %40 = tail call i32 @llvm.abs.i32(i32 %39, i1 true)
  %41 = getelementptr inbounds i8, ptr %0, i64 104
  %42 = load <4 x i32>, ptr %41, align 8, !tbaa !11
  %43 = add <4 x i32> %42, <i32 -2, i32 -1, i32 -2, i32 -2>
  %44 = tail call <4 x i32> @llvm.abs.v4i32(<4 x i32> %43, i1 true)
  %45 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %33)
  %46 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %44)
  %op.rdx = add i32 %45, %46
  %op.rdx21 = add i32 %op.rdx, %5
  %op.rdx22 = add nuw i32 %8, %11
  %op.rdx23 = add nuw i32 %15, %18
  %op.rdx24 = add nuw i32 %22, %26
  %op.rdx25 = add nuw i32 %29, %37
  %op.rdx26 = add i32 %op.rdx21, %op.rdx22
  %op.rdx27 = add i32 %op.rdx23, %op.rdx24
  %op.rdx28 = add i32 %op.rdx25, %40
  %op.rdx29 = add i32 %op.rdx26, %op.rdx27
  %op.rdx30 = add i32 %op.rdx29, %op.rdx28
  %47 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %0)
  store i32 %op.rdx30, ptr %47, align 4, !tbaa !11
  br label %51

48:                                               ; preds = %1
  %49 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56) @manhattonCache, ptr noundef nonnull align 8 dereferenceable(152) %0)
  %50 = load i32, ptr %49, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %.preheader, %48
  %.0 = phi i32 [ %50, %48 ], [ %op.rdx30, %.preheader ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEE5countERS6_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt13unordered_mapI1PiSt4hashIS0_ESt8equal_toIS0_ESaISt4pairIKS0_iEEEixERS6_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass