; LLVM IR from XiaoMi/mace :: micro/ops/softmax.ll (ZN5micro3ops9SoftmaxOp3RunEv)

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

@.str.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1

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

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

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

declare i32 @__gxx_personality_v0(...)

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

; 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 @_ZN5micro3ops9SoftmaxOp3RunEv(ptr noundef nonnull align 8 dereferenceable(72) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %"class.micro::base::Logger", align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %"class.micro::base::Logger", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %11 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 3
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef 0, i32 noundef %12, ptr noundef %14)
  store i32 %15, ptr %4, align 4, !tbaa !16
  %16 = load i32, ptr %4, align 4, !tbaa !16
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %37

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef @.str.1, i32 noundef 38, i32 noundef 1)
  %19 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 3
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = invoke noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %10, i32 noundef 0, i32 noundef %20, ptr noundef %22)
          to label %24 unwind label %33

24:                                               ; preds = %18
  %25 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %23)
          to label %26 unwind label %33

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

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

31:                                               ; preds = %28
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %32 = load i32, ptr %4, align 4, !tbaa !16
  store i32 %32, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %38

33:                                               ; preds = %28, %26, %24, %18
  %34 = landingpad { ptr, i32 }
          cleanup
  %35 = extractvalue { ptr, i32 } %34, 0
  store ptr %35, ptr %6, align 8
  %36 = extractvalue { ptr, i32 } %34, 1
  store i32 %36, ptr %7, align 4
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %5) #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 %61

37:                                               ; preds = %1
  store i32 0, ptr %8, align 4
  br label %38

38:                                               ; preds = %37, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %39 = load i32, ptr %8, align 4
  switch i32 %39, label %66 [
    i32 0, label %40
    i32 1, label %59
  ]

40:                                               ; preds = %38
  %41 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 6
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = icmp eq i32 1, %42
  br i1 %43, label %48, label %44

44:                                               ; preds = %40
  %45 = getelementptr inbounds %"class.micro::ops::SoftmaxOp", ptr %10, i32 0, i32 6
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = icmp eq i32 1000, %46
  br i1 %47, label %48, label %50

48:                                               ; preds = %44, %40
  %49 = call noundef i32 @_ZN5micro3ops9SoftmaxOp10RunForNHWCEv(ptr noundef nonnull align 8 dereferenceable(72) %10)
  store i32 %49, ptr %2, align 4
  br label %59

50:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef @.str.1, i32 noundef 43, i32 noundef 4)
  %51 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef @.str.6)
          to label %52 unwind label %55

52:                                               ; preds = %50
  %53 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %51, ptr noundef @.str.7)
          to label %54 unwind label %55

54:                                               ; preds = %52
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  store i32 3, ptr %2, align 4
  br label %59

55:                                               ; preds = %52, %50
  %56 = landingpad { ptr, i32 }
          cleanup
  %57 = extractvalue { ptr, i32 } %56, 0
  store ptr %57, ptr %6, align 8
  %58 = extractvalue { ptr, i32 } %56, 1
  store i32 %58, ptr %7, align 4
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %61

59:                                               ; preds = %54, %48, %38
  %60 = load i32, ptr %2, align 4
  ret i32 %60

61:                                               ; preds = %55, %33
  %62 = load ptr, ptr %6, align 8
  %63 = load i32, ptr %7, align 4
  %64 = insertvalue { ptr, i32 } poison, ptr %62, 0
  %65 = insertvalue { ptr, i32 } %64, i32 %63, 1
  resume { ptr, i32 } %65

66:                                               ; preds = %38
  unreachable
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5micro3ops9SoftmaxOp10RunForNHWCEv(ptr noundef nonnull align 8 dereferenceable(72)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = { 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 #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 48}
!10 = !{!"_ZTSN5micro3ops9SoftmaxOpE", !11, i64 0, !6, i64 32, !6, i64 40, !12, i64 48, !6, i64 56, !13, i64 64, !14, i64 68}
!11 = !{!"_ZTSN5micro9framework8OperatorE", !6, i64 8, !6, i64 16, !6, i64 24}
!12 = !{!"int", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN5micro10DataFormatE", !7, i64 0}
!15 = !{!10, !6, i64 40}
!16 = !{!17, !17, i64 0}
!17 = !{!"_ZTSN5micro10MaceStatusE", !7, i64 0}
!18 = !{!10, !14, i64 68}


; 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.1 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [16 x i8], align 1

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

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

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

declare i32 @__gxx_personality_v0(...)

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

; 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
define dso_local noundef i32 @_ZN5micro3ops9SoftmaxOp3RunEv(ptr noundef nonnull align 8 dereferenceable(72) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.micro::base::Logger", align 4
  %3 = alloca %"class.micro::base::Logger", align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = tail call noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef 0, i32 noundef %5, ptr noundef %7)
  %.not.not = icmp eq i32 %8, 0
  br i1 %.not.not, label %22, label %9

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @_ZN5micro4base6LoggerC1EPKcjNS_8LogLevelE(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull @.str.1, i32 noundef 38, i32 noundef 1)
  %10 = load i32, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !14
  %12 = invoke noundef i32 @_ZN5micro9framework8Operator17ResizeOutputShapeEjjPKi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef 0, i32 noundef %10, ptr noundef %11)
          to label %13 unwind label %19

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

15:                                               ; preds = %13
  %16 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull @.str.5)
          to label %17 unwind label %19

17:                                               ; preds = %15
  %18 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEi(ptr noundef nonnull align 4 dereferenceable(4) %16, i32 noundef %8)
          to label %21 unwind label %19

19:                                               ; preds = %17, %15, %13, %9
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5micro4base6LoggerD1Ev(ptr noundef nonnull align 4 dereferenceable(4) %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %35

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

22:                                               ; preds = %1
  %23 = getelementptr inbounds i8, ptr %0, i64 68
  %24 = load i32, ptr %23, align 4, !tbaa !15
  switch i32 %24, label %27 [
    i32 1, label %25
    i32 1000, label %25
  ]

25:                                               ; preds = %22, %22
  %26 = tail call noundef i32 @_ZN5micro3ops9SoftmaxOp10RunForNHWCEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  br label %34

27:                                               ; preds = %22
  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.1, i32 noundef 43, i32 noundef 4)
  %28 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull @.str.6)
          to label %29 unwind label %32

29:                                               ; preds = %27
  %30 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNK5micro4base6LoggerlsEPKc(ptr noundef nonnull align 4 dereferenceable(4) %28, ptr noundef nonnull @.str.7)
          to label %31 unwind label %32

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

32:                                               ; preds = %29, %27
  %33 = 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
  br label %35

34:                                               ; preds = %21, %31, %25
  %.1 = phi i32 [ %8, %21 ], [ %26, %25 ], [ 3, %31 ]
  ret i32 %.1

35:                                               ; preds = %32, %19
  %.pn = phi { ptr, i32 } [ %33, %32 ], [ %20, %19 ]
  resume { ptr, i32 } %.pn
}

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5micro3ops9SoftmaxOp10RunForNHWCEv(ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #3 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = { 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 #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 48}
!6 = !{!"_ZTSN5micro3ops9SoftmaxOpE", !7, i64 0, !8, i64 32, !8, i64 40, !11, i64 48, !8, i64 56, !12, i64 64, !13, i64 68}
!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 = !{!"bool", !9, i64 0}
!13 = !{!"_ZTSN5micro10DataFormatE", !9, i64 0}
!14 = !{!6, !8, i64 40}
!15 = !{!6, !13, i64 68}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass