; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x28-IDA-Star/181. 回转游戏.ll (Z4getMv)

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

@a = external dso_local global [7 x [7 x i32]], align 16
@k = external dso_local global i32, align 4
@center = external dso_local global [8 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4getMv() #0 {
  %1 = alloca [4 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #3
  call void @llvm.memset.p0.i64(ptr align 16 %1, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %30, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 8
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %33

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [8 x [2 x i32]], ptr @center, i64 0, i64 %12
  %14 = getelementptr inbounds [2 x i32], ptr %13, i64 0, i64 0
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [8 x [2 x i32]], ptr @center, i64 0, i64 %19
  %21 = getelementptr inbounds [2 x i32], ptr %20, i64 0, i64 1
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [7 x i32], ptr %17, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x i32], ptr %1, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !5
  br label %30

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

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

34:                                               ; preds = %51, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = icmp sle i32 %35, 3
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %54

38:                                               ; preds = %34
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4 x i32], ptr %1, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr @k, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4 x i32], ptr %1, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp sgt i32 %42, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %38
  %49 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %49, ptr @k, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %48, %38
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %34, !llvm.loop !11

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

55:                                               ; preds = %81, %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 8
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %55
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [8 x [2 x i32]], ptr @center, i64 0, i64 %61
  %63 = getelementptr inbounds [2 x i32], ptr %62, i64 0, i64 0
  %64 = load i32, ptr %63, align 8, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [8 x [2 x i32]], ptr @center, i64 0, i64 %68
  %70 = getelementptr inbounds [2 x i32], ptr %69, i64 0, i64 1
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [7 x i32], ptr %66, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = load i32, ptr @k, align 4, !tbaa !5
  %76 = icmp ne i32 %74, %75
  br i1 %76, label %77, label %80

77:                                               ; preds = %59
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %77, %59
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %5, align 4, !tbaa !5
  br label %55, !llvm.loop !12

84:                                               ; preds = %58
  %85 = load i32, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #3
  ret i32 %85
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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

@a = external dso_local local_unnamed_addr global [7 x [7 x i32]], align 16
@k = external dso_local local_unnamed_addr global i32, align 4
@center = external dso_local local_unnamed_addr global [8 x [2 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z4getMv() local_unnamed_addr #0 {
.preheader:
  %0 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %0) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  %1 = load i32, ptr @center, align 16, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 4), align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %2, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 8), align 8, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 12), align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %12, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !5
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 16), align 16, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 20), align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %22, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 24), align 8, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 28), align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %32, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !5
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 32), align 16, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 36), align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %48, align 4, !tbaa !5
  %51 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 40), align 8, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 44), align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %58, align 4, !tbaa !5
  %61 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 48), align 16, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 52), align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %62, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %68, align 4, !tbaa !5
  %71 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 56), align 8, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = load i32, ptr getelementptr inbounds (i8, ptr @center, i64 60), align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [7 x [7 x i32]], ptr @a, i64 0, i64 %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [4 x i32], ptr %0, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %78, align 4, !tbaa !5
  store i32 1, ptr @k, align 4, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %0, i64 8
  %82 = load i32, ptr %81, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %0, i64 4
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = icmp sgt i32 %82, %84
  %spec.store.select = select i1 %85, i32 2, i32 1
  store i32 %spec.store.select, ptr @k, align 4
  %spec.select = tail call i32 @llvm.smax.i32(i32 %82, i32 %84)
  %spec.select27 = select i1 %85, i32 2, i32 1
  %86 = getelementptr inbounds i8, ptr %0, i64 12
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = icmp sgt i32 %87, %spec.select
  %spec.store.select28 = select i1 %88, i32 3, i32 %spec.store.select
  store i32 %spec.store.select28, ptr @k, align 4
  %spec.select29 = select i1 %88, i32 3, i32 %spec.select27
  %.not = icmp ne i32 %6, %spec.select29
  %89 = zext i1 %.not to i32
  %.not.1 = icmp ne i32 %16, %spec.select29
  %90 = zext i1 %.not.1 to i32
  %spec.select.1 = add nuw nsw i32 %89, %90
  %.not.2 = icmp ne i32 %26, %spec.select29
  %91 = zext i1 %.not.2 to i32
  %spec.select.2 = add nuw nsw i32 %spec.select.1, %91
  %.not.3 = icmp ne i32 %36, %spec.select29
  %92 = zext i1 %.not.3 to i32
  %spec.select.3 = add nuw nsw i32 %spec.select.2, %92
  %.not.4 = icmp ne i32 %46, %spec.select29
  %93 = zext i1 %.not.4 to i32
  %spec.select.4 = add nuw nsw i32 %spec.select.3, %93
  %.not.5 = icmp ne i32 %56, %spec.select29
  %94 = zext i1 %.not.5 to i32
  %spec.select.5 = add nuw nsw i32 %spec.select.4, %94
  %.not.6 = icmp ne i32 %66, %spec.select29
  %95 = zext i1 %.not.6 to i32
  %spec.select.6 = add nuw nsw i32 %spec.select.5, %95
  %.not.7 = icmp ne i32 %76, %spec.select29
  %96 = zext i1 %.not.7 to i32
  %spec.select.7 = add nuw nsw i32 %spec.select.6, %96
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %0) #4
  ret i32 %spec.select.7
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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 willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass