; LLVM IR from huawei-noah/bolt :: inference/engine/src/bolt_dllite.ll (Z14UpdateDataDesc10TensorDescP8DataDesc)

; 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.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.DataDesc = type { [8 x i32], [128 x i8], i32, i32, ptr }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@stdout = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [50 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: nounwind
declare i64 @syscall(i64 noundef, ...) #1

declare i32 @printf(ptr noundef, ...) #2

declare i32 @fflush(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; 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 void @_Z14UpdateDataDesc10TensorDescP8DataDesc(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.DataDesc, ptr %9, i32 0, i32 2
  store i32 %8, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !16
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DataDesc, ptr %13, i32 0, i32 3
  store i32 %12, ptr %14, align 4, !tbaa !17
  %15 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !18
  %17 = icmp ugt i32 %16, 4
  br i1 %17, label %18, label %30

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %19 = call i64 (i64, ...) @syscall(i64 noundef 186) #5
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %4, align 4, !tbaa !19
  %21 = load i32, ptr %4, align 4, !tbaa !19
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %21)
  %23 = load ptr, ptr @stdout, align 8, !tbaa !5
  %24 = call i32 @fflush(ptr noundef %23)
  %25 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %26)
  %28 = load ptr, ptr @stdout, align 8, !tbaa !5
  %29 = call i32 @fflush(ptr noundef %28)
  call void @exit(i32 noundef 1) #6
  unreachable

30:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !19
  br label %31

31:                                               ; preds = %52, %30
  %32 = load i32, ptr %5, align 4, !tbaa !19
  %33 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !18
  %35 = icmp ult i32 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %55

37:                                               ; preds = %31
  %38 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 3
  %39 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = sub i32 %40, 1
  %42 = load i32, ptr %5, align 4, !tbaa !19
  %43 = sub i32 %41, %42
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [20 x i32], ptr %38, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !19
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.DataDesc, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %5, align 4, !tbaa !19
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [8 x i32], ptr %48, i64 0, i64 %50
  store i32 %46, ptr %51, align 4, !tbaa !19
  br label %52

52:                                               ; preds = %37
  %53 = load i32, ptr %5, align 4, !tbaa !19
  %54 = add i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !19
  br label %31, !llvm.loop !20

55:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %56 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !18
  store i32 %57, ptr %6, align 4, !tbaa !19
  br label %58

58:                                               ; preds = %68, %55
  %59 = load i32, ptr %6, align 4, !tbaa !19
  %60 = icmp slt i32 %59, 4
  br i1 %60, label %62, label %61

61:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %71

62:                                               ; preds = %58
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.DataDesc, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %6, align 4, !tbaa !19
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [8 x i32], ptr %64, i64 0, i64 %66
  store i32 1, ptr %67, align 4, !tbaa !19
  br label %68

68:                                               ; preds = %62
  %69 = load i32, ptr %6, align 4, !tbaa !19
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %6, align 4, !tbaa !19
  br label %58, !llvm.loop !22

71:                                               ; preds = %61
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { 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 #5 = { nounwind }
attributes #6 = { 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS10TensorDesc", !11, i64 0, !12, i64 4, !13, i64 8, !7, i64 12}
!11 = !{!"_ZTS8DataType", !7, i64 0}
!12 = !{!"_ZTS10DataFormat", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !11, i64 160}
!15 = !{!"_ZTS8DataDesc", !7, i64 0, !7, i64 32, !11, i64 160, !12, i64 164, !6, i64 168}
!16 = !{!10, !12, i64 4}
!17 = !{!15, !12, i64 164}
!18 = !{!10, !13, i64 8}
!19 = !{!13, !13, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind
declare i64 @syscall(i64 noundef, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z14UpdateDataDesc10TensorDescP8DataDesc(ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #3 {
  %3 = getelementptr inbounds i8, ptr %1, i64 160
  %4 = load <2 x i32>, ptr %0, align 8, !tbaa !5
  store <2 x i32> %4, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !8
  %7 = icmp ugt i32 %6, 4
  br i1 %7, label %13, label %.preheader13

.preheader13:                                     ; preds = %2
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.lr.ph16.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader13
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = add nsw i32 %6, -1
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [20 x i32], ptr %8, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !13
  store i32 %12, ptr %1, align 4, !tbaa !13
  %cond = icmp eq i32 %6, 1
  br i1 %cond, label %.lr.ph16.preheader, label %29

13:                                               ; preds = %2
  %14 = tail call i64 (i64, ...) @syscall(i64 noundef 186) #5
  %15 = trunc i64 %14 to i32
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %15)
  %17 = load ptr, ptr @stdout, align 8, !tbaa !14
  %18 = tail call i32 @fflush(ptr noundef %17)
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i32 noundef %6)
  %20 = load ptr, ptr @stdout, align 8, !tbaa !14
  %21 = tail call i32 @fflush(ptr noundef %20)
  tail call void @exit(i32 noundef 1) #6
  unreachable

.lr.ph16.preheader:                               ; preds = %35, %29, %.lr.ph, %.preheader13, %.preheader
  %22 = zext nneg i32 %6 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %6, i32 3)
  %23 = sub nsw i32 %smax, %6
  %24 = zext i32 %23 to i64
  %25 = add nuw nsw i64 %24, 1
  %min.iters.check = icmp ult i32 %23, 7
  br i1 %min.iters.check, label %.lr.ph16.preheader23, label %vector.ph

.lr.ph16.preheader23:                             ; preds = %middle.block, %.lr.ph16.preheader
  %indvars.iv19.ph = phi i64 [ %22, %.lr.ph16.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph16

vector.ph:                                        ; preds = %.lr.ph16.preheader
  %n.vec = and i64 %25, 8589934584
  %ind.end = or disjoint i64 %n.vec, %22
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, %22
  %26 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %offset.idx
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %26, align 4, !tbaa !13
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %27, align 4, !tbaa !13
  %index.next = add nuw i64 %index, 8
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %25, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph16.preheader23

29:                                               ; preds = %.lr.ph
  %30 = add nsw i32 %6, -2
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [20 x i32], ptr %8, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %33, ptr %34, align 4, !tbaa !13
  %cond24 = icmp eq i32 %6, 2
  br i1 %cond24, label %.lr.ph16.preheader, label %35

35:                                               ; preds = %29
  %36 = add nsw i32 %6, -3
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [20 x i32], ptr %8, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %39, ptr %40, align 4, !tbaa !13
  %cond25 = icmp eq i32 %6, 3
  br i1 %cond25, label %.lr.ph16.preheader, label %.preheader

.preheader:                                       ; preds = %35
  %41 = add nsw i32 %6, -4
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds [20 x i32], ptr %8, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !13
  %45 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %44, ptr %45, align 4, !tbaa !13
  %.not17 = icmp eq i32 %6, 4
  br i1 %.not17, label %._crit_edge, label %.lr.ph16.preheader

._crit_edge:                                      ; preds = %.lr.ph16, %middle.block, %.preheader
  ret void

.lr.ph16:                                         ; preds = %.lr.ph16.preheader23, %.lr.ph16
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %.lr.ph16 ], [ %indvars.iv19.ph, %.lr.ph16.preheader23 ]
  %46 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %indvars.iv19
  store i32 1, ptr %46, align 4, !tbaa !13
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %47 = trunc nuw i64 %indvars.iv19 to i32
  %48 = icmp slt i32 %47, 3
  br i1 %48, label %.lr.ph16, label %._crit_edge, !llvm.loop !20
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

attributes #0 = { 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 #1 = { nofree 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 #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !12, i64 8}
!9 = !{!"_ZTS10TensorDesc", !10, i64 0, !11, i64 4, !12, i64 8, !6, i64 12}
!10 = !{!"_ZTS8DataType", !6, i64 0}
!11 = !{!"_ZTS10DataFormat", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !19, !18}


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