; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu (rnn)

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

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@stdout = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [18 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: inlinehint mustprogress nounwind uwtable
declare dso_local ptr @ee2str(i32 noundef) #3

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

; 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 noundef i32 @_Z30rnn_transform_filter_bytes_cpuPK10TensorDesc12RNNParamSpecPj(ptr noundef %0, ptr noundef byval(%struct.RNNParamSpec) align 8 %1, ptr noundef %2) #5 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %29

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 1, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %28

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %17 = call i64 (i64, ...) @syscall(i64 noundef 186) #7
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !11
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %19)
  %21 = load ptr, ptr @stdout, align 8, !tbaa !5
  %22 = call i32 @fflush(ptr noundef %21)
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call ptr @ee2str(i32 noundef %23)
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %24)
  %26 = load ptr, ptr @stdout, align 8, !tbaa !5
  %27 = call i32 @fflush(ptr noundef %26)
  call void @exit(i32 noundef 1) #8
  unreachable

28:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %29

29:                                               ; preds = %28, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %30 = getelementptr inbounds %struct.RNNParamSpec, ptr %1, i32 0, i32 6
  %31 = load i8, ptr %30, align 8, !tbaa !13, !range !19, !noundef !20
  %32 = trunc i8 %31 to i1
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 2, i32 1
  store i32 %34, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %35 = getelementptr inbounds %struct.RNNParamSpec, ptr %1, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !21
  %37 = icmp sgt i32 %36, 0
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 2, i32 1
  store i32 %39, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %105, %29
  %41 = load i32, ptr %10, align 4, !tbaa !11
  %42 = load i32, ptr %8, align 4, !tbaa !11
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = mul nsw i32 %42, %43
  %45 = icmp slt i32 %41, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %108

47:                                               ; preds = %40
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.TensorDesc, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.TensorDesc, ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds [20 x i32], ptr %52, i64 0, i64 1
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = add i32 %54, 32
  %56 = sub i32 %55, 1
  %57 = udiv i32 %56, 32
  %58 = mul i32 %57, 32
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !11
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.TensorDesc, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.TensorDesc, ptr %62, i32 0, i32 3
  %64 = getelementptr inbounds [20 x i32], ptr %63, i64 0, i64 0
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = add i32 %65, 32
  %67 = sub i32 %66, 1
  %68 = udiv i32 %67, 32
  %69 = mul i32 %68, 32
  %70 = mul i32 %58, %69
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i32, ptr %10, align 4, !tbaa !11
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.TensorDesc, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.TensorDesc, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 4, !tbaa !22
  %77 = call noundef i32 @_Z7bytesOf8DataType(i32 noundef %76)
  %78 = mul i32 %70, %77
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !11
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i32, ptr %79, i64 %81
  store i32 %78, ptr %82, align 4, !tbaa !11
  %83 = getelementptr inbounds %struct.RNNParamSpec, ptr %1, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !26
  %85 = icmp eq i32 %84, 1
  br i1 %85, label %86, label %104

86:                                               ; preds = %47
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = load i32, ptr %10, align 4, !tbaa !11
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.TensorDesc, ptr %87, i64 %89
  %91 = getelementptr inbounds %struct.TensorDesc, ptr %90, i32 0, i32 3
  %92 = getelementptr inbounds [20 x i32], ptr %91, i64 0, i64 1
  %93 = load i32, ptr %92, align 4, !tbaa !11
  %94 = zext i32 %93 to i64
  %95 = mul i64 %94, 4
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = load i32, ptr %10, align 4, !tbaa !11
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i32, ptr %96, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !11
  %101 = zext i32 %100 to i64
  %102 = add i64 %101, %95
  %103 = trunc i64 %102 to i32
  store i32 %103, ptr %99, align 4, !tbaa !11
  br label %104

104:                                              ; preds = %86, %47
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %10, align 4, !tbaa !11
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %10, align 4, !tbaa !11
  br label %40, !llvm.loop !27

108:                                              ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z7bytesOf8DataType(i32 noundef) #6

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 = { 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 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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, !10, i64 0}
!10 = !{!"_ZTS2EE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !17, i64 24}
!14 = !{!"_ZTS12RNNParamSpec", !15, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !16, i64 16, !16, i64 20, !17, i64 24, !16, i64 28, !18, i64 32}
!15 = !{!"_ZTS7RNNMode", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTS14ActivationMode", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !12, i64 12}
!22 = !{!23, !24, i64 0}
!23 = !{!"_ZTS10TensorDesc", !24, i64 0, !25, i64 4, !12, i64 8, !7, i64 12}
!24 = !{!"_ZTS8DataType", !7, i64 0}
!25 = !{!"_ZTS10DataFormat", !7, i64 0}
!26 = !{!14, !15, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"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"

%struct.RNNParamSpec = type { i32, i32, i32, i32, float, float, i8, float, i32 }
%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.1 = external hidden unnamed_addr constant [18 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: inlinehint mustprogress nounwind uwtable
declare dso_local ptr @ee2str(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z30rnn_transform_filter_bytes_cpuPK10TensorDesc12RNNParamSpecPj(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly byval(%struct.RNNParamSpec) align 8 %1, ptr noundef writeonly %2) local_unnamed_addr #4 {
  %4 = icmp eq ptr %2, null
  br i1 %4, label %5, label %15

5:                                                ; preds = %3
  %6 = tail call i64 (i64, ...) @syscall(i64 noundef 186) #6
  %7 = trunc i64 %6 to i32
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %7)
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  %10 = tail call i32 @fflush(ptr noundef %9)
  %11 = tail call ptr @ee2str(i32 noundef 1)
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %11)
  %13 = load ptr, ptr @stdout, align 8, !tbaa !5
  %14 = tail call i32 @fflush(ptr noundef %13)
  tail call void @exit(i32 noundef 1) #7
  unreachable

15:                                               ; preds = %3
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = load i8, ptr %16, align 8, !tbaa !9, !range !16, !noundef !17
  %18 = zext nneg i8 %17 to i32
  %19 = getelementptr inbounds i8, ptr %1, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %.inv = icmp slt i32 %20, 1
  %21 = select i1 %.inv, i32 1, i32 2
  %22 = shl nuw nsw i32 %21, %18
  %23 = load i32, ptr %1, align 8
  %.fr22 = freeze i32 %23
  %24 = icmp eq i32 %.fr22, 1
  %wide.trip.count29 = zext nneg i32 %22 to i64
  br i1 %24, label %.split.us, label %.split

.split.us:                                        ; preds = %15, %.split.us
  %indvars.iv25 = phi i64 [ %indvars.iv.next26, %.split.us ], [ 0, %15 ]
  %25 = getelementptr inbounds %struct.TensorDesc, ptr %0, i64 %indvars.iv25
  %26 = getelementptr inbounds i8, ptr %25, i64 12
  %27 = getelementptr inbounds i8, ptr %25, i64 16
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %29 = add i32 %28, 31
  %30 = and i32 %29, -32
  %31 = load i32, ptr %26, align 4, !tbaa !19
  %32 = add i32 %31, 31
  %33 = and i32 %32, -32
  %34 = mul i32 %33, %30
  %35 = load i32, ptr %25, align 4, !tbaa !20
  %36 = tail call noundef i32 @_Z7bytesOf8DataType(i32 noundef %35)
  %37 = mul i32 %34, %36
  %38 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv25
  store i32 %37, ptr %38, align 4, !tbaa !19
  %39 = load i32, ptr %27, align 4, !tbaa !19
  %40 = shl i32 %39, 2
  %41 = add i32 %40, %37
  store i32 %41, ptr %38, align 4, !tbaa !19
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count29
  br i1 %exitcond30.not, label %.split21.us, label %.split.us, !llvm.loop !24

.split21.us:                                      ; preds = %.split, %.split.us
  ret i32 0

.split:                                           ; preds = %15, %.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.split ], [ 0, %15 ]
  %42 = getelementptr inbounds %struct.TensorDesc, ptr %0, i64 %indvars.iv
  %43 = getelementptr inbounds i8, ptr %42, i64 12
  %44 = getelementptr inbounds i8, ptr %42, i64 16
  %45 = load i32, ptr %44, align 4, !tbaa !19
  %46 = add i32 %45, 31
  %47 = and i32 %46, -32
  %48 = load i32, ptr %43, align 4, !tbaa !19
  %49 = add i32 %48, 31
  %50 = and i32 %49, -32
  %51 = mul i32 %50, %47
  %52 = load i32, ptr %42, align 4, !tbaa !20
  %53 = tail call noundef i32 @_Z7bytesOf8DataType(i32 noundef %52)
  %54 = mul i32 %51, %53
  %55 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  store i32 %54, ptr %55, align 4, !tbaa !19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count29
  br i1 %exitcond.not, label %.split21.us, label %.split, !llvm.loop !24
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z7bytesOf8DataType(i32 noundef) local_unnamed_addr #5

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 = { 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 #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 = { 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 #6 = { nounwind }
attributes #7 = { 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, !14, i64 24}
!10 = !{!"_ZTS12RNNParamSpec", !11, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !13, i64 20, !14, i64 24, !13, i64 28, !15, i64 32}
!11 = !{!"_ZTS7RNNMode", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTS14ActivationMode", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !12, i64 12}
!19 = !{!12, !12, i64 0}
!20 = !{!21, !22, i64 0}
!21 = !{!"_ZTS10TensorDesc", !22, i64 0, !23, i64 4, !12, i64 8, !7, i64 12}
!22 = !{!"_ZTS8DataType", !7, i64 0}
!23 = !{!"_ZTS10DataFormat", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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