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

; Function Attrs: nounwind uwtable
define dso_local ptr @omTensorCreate(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = call noalias ptr @malloc(i64 noundef 64) #5
  store ptr %13, ptr %10, align 8, !tbaa !5
  %14 = load ptr, ptr %10, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %107

17:                                               ; preds = %4
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = mul i64 %18, 8
  %20 = call noalias ptr @malloc(i64 noundef %19) #5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.OMTensor, ptr %21, i32 0, i32 3
  store ptr %20, ptr %22, align 8, !tbaa !13
  %23 = icmp ne ptr %20, null
  br i1 %23, label %24, label %48

24:                                               ; preds = %17
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = mul i64 %25, 8
  %27 = call noalias ptr @malloc(i64 noundef %26) #5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.OMTensor, ptr %28, i32 0, i32 4
  store ptr %27, ptr %29, align 8, !tbaa !15
  %30 = icmp ne ptr %27, null
  br i1 %30, label %31, label %48

31:                                               ; preds = %24
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.OMTensor, ptr %33, i32 0, i32 0
  store ptr %32, ptr %34, align 8, !tbaa !16
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.OMTensor, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !17
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.OMTensor, ptr %38, i32 0, i32 2
  store i64 0, ptr %39, align 8, !tbaa !18
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.OMTensor, ptr %41, i32 0, i32 5
  store i64 %40, ptr %42, align 8, !tbaa !19
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.OMTensor, ptr %44, i32 0, i32 6
  store i32 %43, ptr %45, align 8, !tbaa !20
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.OMTensor, ptr %46, i32 0, i32 7
  store i64 0, ptr %47, align 8, !tbaa !21
  br label %53

48:                                               ; preds = %24, %17
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.OMTensor, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  call void @free(ptr noundef %51) #4
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %52) #4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %107

53:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = sub nsw i64 %54, 1
  store i64 %55, ptr %12, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %102, %53
  %57 = load i64, ptr %12, align 8, !tbaa !9
  %58 = icmp sge i64 %57, 0
  br i1 %58, label %60, label %59

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

60:                                               ; preds = %56
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = getelementptr inbounds i64, ptr %61, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.OMTensor, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load i64, ptr %12, align 8, !tbaa !9
  %69 = getelementptr inbounds i64, ptr %67, i64 %68
  store i64 %64, ptr %69, align 8, !tbaa !9
  %70 = load i64, ptr %12, align 8, !tbaa !9
  %71 = load i64, ptr %8, align 8, !tbaa !9
  %72 = sub nsw i64 %71, 1
  %73 = icmp eq i64 %70, %72
  br i1 %73, label %74, label %80

74:                                               ; preds = %60
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.OMTensor, ptr %75, i32 0, i32 4
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load i64, ptr %12, align 8, !tbaa !9
  %79 = getelementptr inbounds i64, ptr %77, i64 %78
  store i64 1, ptr %79, align 8, !tbaa !9
  br label %101

80:                                               ; preds = %60
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.OMTensor, ptr %81, i32 0, i32 4
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  %84 = load i64, ptr %12, align 8, !tbaa !9
  %85 = add nsw i64 %84, 1
  %86 = getelementptr inbounds i64, ptr %83, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.OMTensor, ptr %88, i32 0, i32 3
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = load i64, ptr %12, align 8, !tbaa !9
  %92 = add nsw i64 %91, 1
  %93 = getelementptr inbounds i64, ptr %90, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !9
  %95 = mul nsw i64 %87, %94
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.OMTensor, ptr %96, i32 0, i32 4
  %98 = load ptr, ptr %97, align 8, !tbaa !15
  %99 = load i64, ptr %12, align 8, !tbaa !9
  %100 = getelementptr inbounds i64, ptr %98, i64 %99
  store i64 %95, ptr %100, align 8, !tbaa !9
  br label %101

101:                                              ; preds = %80, %74
  br label %102

102:                                              ; preds = %101
  %103 = load i64, ptr %12, align 8, !tbaa !9
  %104 = add nsw i64 %103, -1
  store i64 %104, ptr %12, align 8, !tbaa !9
  br label %56, !llvm.loop !22

105:                                              ; preds = %59
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %106, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %107

107:                                              ; preds = %105, %48, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %108 = load ptr, ptr %5, align 8
  ret ptr %108
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

attributes #0 = { 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 = { nounwind allocsize(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 "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 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"OMTensor", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !12, i64 48, !10, i64 56}
!15 = !{!14, !6, i64 32}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !6, i64 8}
!18 = !{!14, !10, i64 16}
!19 = !{!14, !10, i64 40}
!20 = !{!14, !12, i64 48}
!21 = !{!14, !10, i64 56}
!22 = distinct !{!22, !23}
!23 = !{!"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: nounwind memory(readwrite, argmem: read) uwtable
define dso_local noalias noundef ptr @omTensorCreate(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call noalias dereferenceable_or_null(64) ptr @malloc(i64 noundef 64) #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %4
  %7 = shl i64 %2, 3
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #3
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %8, ptr %9, align 8, !tbaa !5
  %.not37 = icmp eq ptr %8, null
  br i1 %.not37, label %31, label %10

10:                                               ; preds = %6
  %11 = tail call noalias ptr @malloc(i64 noundef %7) #3
  %12 = getelementptr inbounds i8, ptr %5, i64 32
  store ptr %11, ptr %12, align 8, !tbaa !12
  %.not38 = icmp eq ptr %11, null
  br i1 %.not38, label %31, label %13

13:                                               ; preds = %10
  store ptr %0, ptr %5, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %0, ptr %14, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 0, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %5, i64 40
  store i64 %2, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %5, i64 48
  store i32 %3, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %5, i64 56
  store i64 0, ptr %18, align 8, !tbaa !18
  %19 = icmp sgt i64 %2, 0
  br i1 %19, label %20, label %.loopexit

20:                                               ; preds = %13
  %21 = add nsw i64 %2, -1
  %22 = getelementptr inbounds i64, ptr %1, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !19
  %24 = getelementptr inbounds i64, ptr %8, i64 %21
  store i64 %23, ptr %24, align 8, !tbaa !19
  %25 = getelementptr inbounds i64, ptr %11, i64 %21
  store i64 1, ptr %25, align 8
  %.not42 = icmp eq i64 %2, 1
  br i1 %.not42, label %.loopexit, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %20
  %26 = add nsw i64 %2, -2
  %27 = shl i64 %2, 3
  %28 = getelementptr i8, ptr %8, i64 %27
  %scevgep = getelementptr i8, ptr %28, i64 -8
  %load_initial = load i64, ptr %scevgep, align 8
  %29 = add nsw i64 %2, -1
  %xtraiter = and i64 %29, 1
  %30 = icmp eq i64 %26, 0
  br i1 %30, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.peel.next.new

.lr.ph.peel.next.new:                             ; preds = %.lr.ph.peel.next
  %unroll_iter = and i64 %29, -2
  br label %32

31:                                               ; preds = %10, %6
  tail call void @free(ptr noundef %8) #4
  tail call void @free(ptr noundef nonnull %5) #4
  br label %.loopexit

32:                                               ; preds = %32, %.lr.ph.peel.next.new
  %store_forwarded = phi i64 [ %load_initial, %.lr.ph.peel.next.new ], [ %41, %32 ]
  %33 = phi i64 [ 1, %.lr.ph.peel.next.new ], [ %43, %32 ]
  %.039 = phi i64 [ %26, %.lr.ph.peel.next.new ], [ %45, %32 ]
  %niter = phi i64 [ 0, %.lr.ph.peel.next.new ], [ %niter.next.1, %32 ]
  %34 = getelementptr inbounds i64, ptr %1, i64 %.039
  %35 = load i64, ptr %34, align 8, !tbaa !19
  %36 = getelementptr inbounds i64, ptr %8, i64 %.039
  store i64 %35, ptr %36, align 8, !tbaa !19
  %37 = mul nsw i64 %store_forwarded, %33
  %38 = getelementptr inbounds i64, ptr %11, i64 %.039
  store i64 %37, ptr %38, align 8
  %39 = add nsw i64 %.039, -1
  %40 = getelementptr inbounds i64, ptr %1, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !19
  %42 = getelementptr inbounds i64, ptr %8, i64 %39
  store i64 %41, ptr %42, align 8, !tbaa !19
  %43 = mul nsw i64 %35, %37
  %44 = getelementptr inbounds i64, ptr %11, i64 %39
  store i64 %43, ptr %44, align 8
  %45 = add nsw i64 %.039, -2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %32, !llvm.loop !20

.loopexit.loopexit.unr-lcssa:                     ; preds = %32, %.lr.ph.peel.next
  %store_forwarded.unr = phi i64 [ %load_initial, %.lr.ph.peel.next ], [ %41, %32 ]
  %.unr = phi i64 [ 1, %.lr.ph.peel.next ], [ %43, %32 ]
  %.039.unr = phi i64 [ %26, %.lr.ph.peel.next ], [ %45, %32 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %46 = getelementptr inbounds i64, ptr %1, i64 %.039.unr
  %47 = load i64, ptr %46, align 8, !tbaa !19
  %48 = getelementptr inbounds i64, ptr %8, i64 %.039.unr
  store i64 %47, ptr %48, align 8, !tbaa !19
  %49 = mul nsw i64 %store_forwarded.unr, %.unr
  %50 = getelementptr inbounds i64, ptr %11, i64 %.039.unr
  store i64 %49, ptr %50, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %20, %13, %4, %31
  %.035 = phi ptr [ null, %31 ], [ null, %4 ], [ %5, %13 ], [ %5, %20 ], [ %5, %.loopexit.loopexit.unr-lcssa ], [ %5, %.loopexit.loopexit.epilog-lcssa ]
  ret ptr %.035
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { nounwind memory(readwrite, argmem: read) 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
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, !7, i64 24}
!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 32}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !10, i64 40}
!17 = !{!6, !11, i64 48}
!18 = !{!6, !10, i64 56}
!19 = !{!10, !10, i64 0}
!20 = distinct !{!20, !21, !22}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass