; LLVM IR from onnx/onnx-mlir :: src/Runtime (OMTensor)

; 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.OMTensor = type { ptr, ptr, i64, ptr, ptr, i64, i32, i64 }

@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.omTensorGetNumElems = external hidden unnamed_addr constant [46 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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @getNumElems(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @omTensorGetNumElems(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.OMTensor, ptr %7, i32 0, i32 5
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = sub nsw i64 %9, 1
  store i64 %10, ptr %3, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %49, %1
  %12 = load i64, ptr %3, align 8, !tbaa !13
  %13 = icmp sge i64 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %52

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 1, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load i64, ptr %3, align 8, !tbaa !13
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr %6, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %34, %15
  %19 = load i64, ptr %6, align 8, !tbaa !13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.OMTensor, ptr %20, i32 0, i32 5
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = icmp slt i64 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %37

25:                                               ; preds = %18
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.OMTensor, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i64, ptr %6, align 8, !tbaa !13
  %30 = getelementptr inbounds i64, ptr %28, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = load i64, ptr %5, align 8, !tbaa !13
  %33 = mul nsw i64 %32, %31
  store i64 %33, ptr %5, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %25
  %35 = load i64, ptr %6, align 8, !tbaa !13
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %6, align 8, !tbaa !13
  br label %18, !llvm.loop !15

37:                                               ; preds = %24
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.OMTensor, ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i64, ptr %3, align 8, !tbaa !13
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = load i64, ptr %5, align 8, !tbaa !13
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %37
  br label %48

47:                                               ; preds = %37
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 367, ptr noundef @__PRETTY_FUNCTION__.omTensorGetNumElems) #5
  unreachable

48:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %3, align 8, !tbaa !13
  %51 = add nsw i64 %50, -1
  store i64 %51, ptr %3, align 8, !tbaa !13
  br label %11, !llvm.loop !18

52:                                               ; preds = %14
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.OMTensor, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.OMTensor, ptr %56, i32 0, i32 5
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = call i64 @getNumElems(ptr noundef %55, i64 noundef %58)
  ret i64 %59
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #3 = { noreturn 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 }
attributes #5 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !11, i64 40}
!10 = !{!"OMTensor", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !12, i64 48, !11, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 32}
!18 = distinct !{!18, !16}


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

@.str = external hidden unnamed_addr constant [44 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.omTensorGetNumElems = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @getNumElems(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @omTensorGetNumElems(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  br label %6

6:                                                ; preds = %._crit_edge, %1
  %indvar = phi i64 [ %indvar.next, %._crit_edge ], [ 0, %1 ]
  %.015.in = phi i64 [ %.015, %._crit_edge ], [ %3, %1 ]
  %7 = add i64 %indvar, -1
  %.015 = add nsw i64 %.015.in, -1
  %8 = icmp sgt i64 %.015.in, 0
  br i1 %8, label %.preheader, label %12

.preheader:                                       ; preds = %6
  %9 = icmp slt i64 %.015.in, %3
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %10 = load ptr, ptr %4, align 8, !tbaa !12
  %xtraiter = and i64 %indvar, 7
  %11 = icmp ult i64 %7, 7
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %indvar, -8
  %invariant.gep = getelementptr i8, ptr %10, i64 8
  %invariant.gep22 = getelementptr i8, ptr %10, i64 16
  %invariant.gep24 = getelementptr i8, ptr %10, i64 24
  %invariant.gep26 = getelementptr i8, ptr %10, i64 32
  %invariant.gep28 = getelementptr i8, ptr %10, i64 40
  %invariant.gep30 = getelementptr i8, ptr %10, i64 48
  %invariant.gep32 = getelementptr i8, ptr %10, i64 56
  br label %23

12:                                               ; preds = %6
  %13 = load ptr, ptr %4, align 8, !tbaa !12
  %14 = tail call i64 @getNumElems(ptr noundef %13, i64 noundef %3)
  ret i64 %14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %23, %.lr.ph
  %.lcssa.ph = phi i64 [ poison, %.lr.ph ], [ %40, %23 ]
  %.017.unr = phi i64 [ %.015.in, %.lr.ph ], [ %41, %23 ]
  %.01416.unr = phi i64 [ 1, %.lr.ph ], [ %40, %23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %.017.epil = phi i64 [ %18, %.epil.preheader ], [ %.017.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01416.epil = phi i64 [ %17, %.epil.preheader ], [ %.01416.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %15 = getelementptr inbounds i64, ptr %10, i64 %.017.epil
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = mul nsw i64 %16, %.01416.epil
  %18 = add nuw nsw i64 %.017.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %.preheader
  %.014.lcssa = phi i64 [ 1, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %17, %.epil.preheader ]
  %19 = load ptr, ptr %5, align 8, !tbaa !16
  %20 = getelementptr inbounds i64, ptr %19, i64 %.015
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp eq i64 %21, %.014.lcssa
  %indvar.next = add i64 %indvar, 1
  br i1 %22, label %6, label %42, !llvm.loop !17

23:                                               ; preds = %23, %.lr.ph.new
  %.017 = phi i64 [ %.015.in, %.lr.ph.new ], [ %41, %23 ]
  %.01416 = phi i64 [ 1, %.lr.ph.new ], [ %40, %23 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.7, %23 ]
  %24 = getelementptr inbounds i64, ptr %10, i64 %.017
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = mul nsw i64 %25, %.01416
  %gep = getelementptr i64, ptr %invariant.gep, i64 %.017
  %27 = load i64, ptr %gep, align 8, !tbaa !13
  %28 = mul nsw i64 %27, %26
  %gep23 = getelementptr i64, ptr %invariant.gep22, i64 %.017
  %29 = load i64, ptr %gep23, align 8, !tbaa !13
  %30 = mul nsw i64 %29, %28
  %gep25 = getelementptr i64, ptr %invariant.gep24, i64 %.017
  %31 = load i64, ptr %gep25, align 8, !tbaa !13
  %32 = mul nsw i64 %31, %30
  %gep27 = getelementptr i64, ptr %invariant.gep26, i64 %.017
  %33 = load i64, ptr %gep27, align 8, !tbaa !13
  %34 = mul nsw i64 %33, %32
  %gep29 = getelementptr i64, ptr %invariant.gep28, i64 %.017
  %35 = load i64, ptr %gep29, align 8, !tbaa !13
  %36 = mul nsw i64 %35, %34
  %gep31 = getelementptr i64, ptr %invariant.gep30, i64 %.017
  %37 = load i64, ptr %gep31, align 8, !tbaa !13
  %38 = mul nsw i64 %37, %36
  %gep33 = getelementptr i64, ptr %invariant.gep32, i64 %.017
  %39 = load i64, ptr %gep33, align 8, !tbaa !13
  %40 = mul nsw i64 %39, %38
  %41 = add nuw nsw i64 %.017, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %23, !llvm.loop !19

42:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 367, ptr noundef nonnull @__PRETTY_FUNCTION__.omTensorGetNumElems) #3
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { inlinehint 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 = { 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 = { noreturn 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 = { noreturn 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, !10, i64 40}
!6 = !{!"OMTensor", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !11, i64 48, !10, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = !{!6, !7, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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