; LLVM IR from XiaoMi/mace :: micro/ops/shape.ll (ZN5micro3ops7ShapeOp3RunEv)

; 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.micro::base::Logger" = type { i32 }
%"class.micro::ops::ShapeOp" = type { %"class.micro::framework::Operator", ptr, i32, ptr }
%"class.micro::framework::Operator" = type { ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5micro3ops7ShapeOp3RunEv(ptr noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [1 x i32], align 4
  %5 = alloca i32, align 4
  %6 = alloca %"class.micro::base::Logger", align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  %12 = getelementptr inbounds %"class.micro::ops::ShapeOp", ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp ugt i32 %13, 0
  br i1 %14, label %15, label %45

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %16 = getelementptr inbounds %"class.micro::ops::ShapeOp", ptr %11, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !9
  store i32 %17, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %18 = getelementptr inbounds [1 x i32], ptr %4, i64 0, i64 0
  %19 = call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %11, i32 noundef 0, i32 noundef 1, ptr noundef %18)
  store i32 %19, ptr %5, align 4, !tbaa !14
  %20 = load i32, ptr %5, align 4, !tbaa !14
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %38

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef @.str, i32 noundef 34, i32 noundef 1)
  %23 = getelementptr inbounds [1 x i32], ptr %4, i64 0, i64 0
  %24 = invoke noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %11, i32 noundef 0, i32 noundef 1, ptr noundef %23)
          to label %25 unwind label %34

25:                                               ; preds = %22
  %26 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef %24)
          to label %27 unwind label %34

27:                                               ; preds = %25
  %28 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef @.str.1)
          to label %29 unwind label %34

29:                                               ; preds = %27
  %30 = load i32, ptr %5, align 4, !tbaa !14
  %31 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %28, i32 noundef %30)
          to label %32 unwind label %34

32:                                               ; preds = %29
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %33 = load i32, ptr %5, align 4, !tbaa !14
  store i32 %33, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %39

34:                                               ; preds = %29, %27, %25, %22
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %7, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %8, align 4
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %72

38:                                               ; preds = %15
  store i32 0, ptr %9, align 4
  br label %39

39:                                               ; preds = %38, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %40 = load i32, ptr %9, align 4
  switch i32 %40, label %42 [
    i32 0, label %41
  ]

41:                                               ; preds = %39
  store i32 0, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %43 = load i32, ptr %9, align 4
  switch i32 %43, label %77 [
    i32 0, label %44
    i32 1, label %70
  ]

44:                                               ; preds = %42
  br label %47

45:                                               ; preds = %1
  %46 = call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %11, i32 noundef 0, i32 noundef 0, ptr noundef null)
  br label %47

47:                                               ; preds = %45, %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !13
  br label %48

48:                                               ; preds = %66, %47
  %49 = load i32, ptr %10, align 4, !tbaa !13
  %50 = getelementptr inbounds %"class.micro::ops::ShapeOp", ptr %11, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !9
  %52 = icmp ult i32 %49, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %48
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %69

54:                                               ; preds = %48
  %55 = getelementptr inbounds %"class.micro::ops::ShapeOp", ptr %11, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load i32, ptr %10, align 4, !tbaa !13
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = getelementptr inbounds %"class.micro::ops::ShapeOp", ptr %11, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load i32, ptr %10, align 4, !tbaa !13
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  store i32 %60, ptr %65, align 4, !tbaa !13
  br label %66

66:                                               ; preds = %54
  %67 = load i32, ptr %10, align 4, !tbaa !13
  %68 = add i32 %67, 1
  store i32 %68, ptr %10, align 4, !tbaa !13
  br label %48, !llvm.loop !18

69:                                               ; preds = %53
  store i32 0, ptr %2, align 4
  br label %70

70:                                               ; preds = %69, %42
  %71 = load i32, ptr %2, align 4
  ret i32 %71

72:                                               ; preds = %34
  %73 = load ptr, ptr %7, align 8
  %74 = load i32, ptr %8, align 4
  %75 = insertvalue { ptr, i32 } poison, ptr %73, 0
  %76 = insertvalue { ptr, i32 } %75, i32 %74, 1
  resume { ptr, i32 } %76

77:                                               ; preds = %42
  unreachable
}

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

declare noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef) #2

declare void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, i32 noundef, i32 noundef) unnamed_addr #2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2

declare i32 @__gxx_personality_v0(...)

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) #2

; Function Attrs: nounwind
declare void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3

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

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 = { "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 "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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"_ZTSN5micro3ops7ShapeOpE", !11, i64 0, !6, i64 32, !12, i64 40, !6, i64 48}
!11 = !{!"_ZTSN5micro9framework8OperatorE", !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_ZTSN5micro10MaceStatusE", !7, i64 0}
!16 = !{!10, !6, i64 32}
!17 = !{!10, !6, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"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.micro::base::Logger" = type { i32 }

@.str = external hidden unnamed_addr constant [64 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5micro3ops7ShapeOp3RunEv(ptr noundef nonnull align 8 dereferenceable(56) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca [1 x i32], align 4
  %3 = alloca %"class.micro::base::Logger", align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %19, label %6

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 %5, ptr %2, align 4, !tbaa !12
  %7 = call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef 0, i32 noundef 1, ptr noundef nonnull %2)
  %.not15.not = icmp eq i32 %7, 0
  br i1 %.not15.not, label %.thread, label %8

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

8:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull @.str, i32 noundef 34, i32 noundef 1)
  %9 = invoke noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef 0, i32 noundef 1, ptr noundef nonnull %2)
          to label %10 unwind label %16

10:                                               ; preds = %8
  %11 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %9)
          to label %12 unwind label %16

12:                                               ; preds = %10
  %13 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull @.str.1)
          to label %14 unwind label %16

14:                                               ; preds = %12
  %15 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef %7)
          to label %18 unwind label %16

16:                                               ; preds = %14, %12, %10, %8
  %17 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  resume { ptr, i32 } %17

18:                                               ; preds = %14
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %.loopexit

19:                                               ; preds = %1
  %20 = tail call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef 0, i32 noundef 0, ptr noundef null)
  br label %21

21:                                               ; preds = %.thread, %19
  %22 = load i32, ptr %4, align 8, !tbaa !5
  %.not18 = icmp eq i32 %22, 0
  br i1 %.not18, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %.lr.ph, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %28 = getelementptr inbounds i32, ptr %24, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = getelementptr inbounds i32, ptr %26, i64 %indvars.iv
  store i32 %29, ptr %30, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %4, align 8, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %27, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %27, %21, %18
  %.1 = phi i32 [ %7, %18 ], [ 0, %21 ], [ 0, %27 ]
  ret i32 %.1
}

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

declare noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, i32 noundef, i32 noundef) unnamed_addr #2

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3

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

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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 "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 #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, !11, i64 40}
!6 = !{!"_ZTSN5micro3ops7ShapeOpE", !7, i64 0, !8, i64 32, !11, i64 40, !8, i64 48}
!7 = !{!"_ZTSN5micro9framework8OperatorE", !8, i64 8, !8, i64 16, !8, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!6, !8, i64 32}
!14 = !{!6, !8, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass