; LLVM IR from XiaoMi/mace :: micro/framework (graph)

; 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.micro::MaceMicroEngineConfig" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }

; 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK5micro9framework5Graph12input_op_idxEj(ptr noundef nonnull align 4 dereferenceable(24), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5micro9framework5Graph17input_op_idx_sizeEv(ptr noundef nonnull align 4 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5micro9framework5Graph17RegisterInputDataEPNS_21MaceMicroEngineConfigEjPKvPKi(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #2 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.micro::MaceMicroEngineConfig", ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  store ptr %19, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.micro::MaceMicroEngineConfig", ptr %27, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  store ptr %26, ptr %32, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = call noundef ptr @_ZNK5micro9framework5Graph12input_op_idxEj(ptr noundef nonnull align 4 dereferenceable(24) %18, i32 noundef %33)
  store ptr %34, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %66, %5
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = call noundef i32 @_ZNK5micro9framework5Graph17input_op_idx_sizeEv(ptr noundef nonnull align 4 dereferenceable(24) %18)
  %38 = icmp ult i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 2, ptr %14, align 4
  br label %69

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i32, ptr %13, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  store i32 %45, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.micro::MaceMicroEngineConfig", ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  store ptr %52, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %53 = load ptr, ptr %16, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds ptr, ptr %54, i64 0
  %56 = load ptr, ptr %55, align 8
  %57 = call noundef i32 %56(ptr noundef nonnull align 8 dereferenceable(32) %53)
  store i32 %57, ptr %17, align 4, !tbaa !17
  %58 = load i32, ptr %17, align 4, !tbaa !17
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %40
  %61 = load i32, ptr %17, align 4, !tbaa !17
  store i32 %61, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %63

62:                                               ; preds = %40
  store i32 0, ptr %14, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  %64 = load i32, ptr %14, align 4
  switch i32 %64, label %69 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %13, align 4, !tbaa !9
  br label %35, !llvm.loop !19

69:                                               ; preds = %63, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %70 = load i32, ptr %14, align 4
  switch i32 %70, label %72 [
    i32 2, label %71
  ]

71:                                               ; preds = %69
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %72

72:                                               ; preds = %71, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %73 = load i32, ptr %6, align 4
  ret i32 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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, !6, i64 40}
!12 = !{!"_ZTSN5micro21MaceMicroEngineConfigE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64}
!13 = !{!12, !6, i64 48}
!14 = !{!12, !6, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_ZTSN5micro10MaceStatusE", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5micro9framework5Graph12input_op_idxEj(ptr noundef nonnull align 4 dereferenceable(24), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5micro9framework5Graph17input_op_idx_sizeEv(ptr noundef nonnull align 4 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5micro9framework5Graph17RegisterInputDataEPNS_21MaceMicroEngineConfigEjPKvPKi(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 align 2 {
  %6 = getelementptr inbounds i8, ptr %1, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = zext i32 %2 to i64
  %9 = getelementptr inbounds ptr, ptr %7, i64 %8
  store ptr %3, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 48
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds ptr, ptr %11, i64 %8
  store ptr %4, ptr %12, align 8, !tbaa !11
  %13 = tail call noundef ptr @_ZNK5micro9framework5Graph12input_op_idxEj(ptr noundef nonnull align 4 dereferenceable(24) %0, i32 noundef %2)
  %14 = tail call noundef i32 @_ZNK5micro9framework5Graph17input_op_idx_sizeEv(ptr noundef nonnull align 4 dereferenceable(24) %0)
  %.not2425.not = icmp eq i32 %14, 0
  br i1 %.not2425.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %15 = getelementptr inbounds i8, ptr %1, i64 24
  br label %19

16:                                               ; preds = %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = tail call noundef i32 @_ZNK5micro9framework5Graph17input_op_idx_sizeEv(ptr noundef nonnull align 4 dereferenceable(24) %0)
  %18 = zext i32 %17 to i64
  %.not24 = icmp ult i64 %indvars.iv.next, %18
  br i1 %.not24, label %19, label %._crit_edge, !llvm.loop !13

19:                                               ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %20 = getelementptr inbounds i32, ptr %13, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = load ptr, ptr %15, align 8, !tbaa !16
  %23 = zext i32 %21 to i64
  %24 = getelementptr inbounds ptr, ptr %22, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %26, align 8
  %28 = tail call noundef i32 %27(ptr noundef nonnull align 8 dereferenceable(32) %25)
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %16, label %._crit_edge

._crit_edge:                                      ; preds = %19, %16, %5
  %spec.select = phi i32 [ 0, %5 ], [ 0, %16 ], [ %28, %19 ]
  ret i32 %spec.select
}

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 = { 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" }

!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 40}
!6 = !{!"_ZTSN5micro21MaceMicroEngineConfigE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 48}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !7, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !9, i64 0}


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