; LLVM IR from huawei-noah/bolt :: inference/engine/src (bolt_c_simplify)

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z10UNI_MALLOCm(i64 noundef) #1

; 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 i32 @MallocTensor(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #2 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !9
  store ptr %3, ptr %13, align 8, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !9
  store ptr %7, ptr %17, align 8, !tbaa !9
  store ptr %8, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store i32 0, ptr %19, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %78

24:                                               ; preds = %9
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = mul i64 8, %26
  %28 = call noundef ptr @_Z10UNI_MALLOCm(i64 noundef %27)
  %29 = load ptr, ptr %18, align 8, !tbaa !9
  store ptr %28, ptr %29, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %74, %24
  %31 = load i32, ptr %20, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  br label %77

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %36 = load ptr, ptr %12, align 8, !tbaa !9
  %37 = load i32, ptr %20, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load ptr, ptr %13, align 8, !tbaa !9
  %42 = load i32, ptr %20, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = mul nsw i32 %40, %45
  %47 = load ptr, ptr %14, align 8, !tbaa !9
  %48 = load i32, ptr %20, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = mul nsw i32 %46, %51
  %53 = load ptr, ptr %15, align 8, !tbaa !9
  %54 = load i32, ptr %20, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = mul nsw i32 %52, %57
  store i32 %58, ptr %21, align 4, !tbaa !5
  %59 = load ptr, ptr %16, align 8, !tbaa !9
  %60 = load i32, ptr %20, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = call i32 @GetDataTypeSize(i32 noundef %63)
  %65 = load i32, ptr %21, align 4, !tbaa !5
  %66 = mul nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = call noundef ptr @_Z10UNI_MALLOCm(i64 noundef %67)
  %69 = load ptr, ptr %18, align 8, !tbaa !9
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = load i32, ptr %20, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds ptr, ptr %70, i64 %72
  store ptr %68, ptr %73, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %74

74:                                               ; preds = %35
  %75 = load i32, ptr %20, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %20, align 4, !tbaa !5
  br label %30, !llvm.loop !13

77:                                               ; preds = %34
  br label %78

78:                                               ; preds = %77, %9
  %79 = load i32, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  ret i32 %79
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local i32 @GetDataTypeSize(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS9DATA_TYPE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z10UNI_MALLOCm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @MallocTensor(i32 noundef %0, ptr nocapture noundef readnone %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef readonly %6, ptr nocapture noundef readnone %7, ptr nocapture noundef %8) local_unnamed_addr #1 {
  %10 = icmp sgt i32 %0, 0
  br i1 %10, label %11, label %.loopexit

11:                                               ; preds = %9
  %12 = zext nneg i32 %0 to i64
  %13 = shl nuw nsw i64 %12, 3
  %14 = tail call noundef ptr @_Z10UNI_MALLOCm(i64 noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %11, %15
  %indvars.iv = phi i64 [ 0, %11 ], [ %indvars.iv.next, %15 ]
  %16 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = mul nsw i32 %19, %17
  %21 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = mul nsw i32 %20, %22
  %24 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = mul nsw i32 %23, %25
  %27 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = tail call i32 @GetDataTypeSize(i32 noundef %28)
  %30 = mul nsw i32 %26, %29
  %31 = sext i32 %30 to i64
  %32 = tail call noundef ptr @_Z10UNI_MALLOCm(i64 noundef %31)
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds ptr, ptr %33, i64 %indvars.iv
  store ptr %32, ptr %34, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %12
  br i1 %exitcond.not, label %.loopexit, label %15, !llvm.loop !13

.loopexit:                                        ; preds = %15, %9
  ret i32 0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local i32 @GetDataTypeSize(i32 noundef) local_unnamed_addr #2

attributes #0 = { inlinehint 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 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 = { inlinehint 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" }

!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, !12, i64 0}
!12 = !{!"_ZTS9DATA_TYPE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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