; LLVM IR from libxsmm/libxsmm :: src (generator_aarch64_instructions)

; 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.libxsmm_generated_code = type { ptr, i32, i32, i32, i32, i32, i32 }
%struct.libxsmm_const_data_tracker = type { [81920 x i8], i32, [128 x i32], i32 }

@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@libxsmm_ninit = external global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@__func__.libxsmm_aarch64_instruction_close_data = external hidden unnamed_addr constant [39 x i8], align 1

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_aarch64_instruction_close_data(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  store i32 %21, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !16
  store i32 %27, ptr %9, align 4, !tbaa !13
  %28 = load i32, ptr %8, align 4, !tbaa !13
  %29 = icmp ugt i32 %28, 0
  br i1 %29, label %30, label %113

30:                                               ; preds = %2
  %31 = load i32, ptr %7, align 4, !tbaa !13
  %32 = add i32 %31, 4095
  %33 = udiv i32 %32, 4096
  %34 = mul i32 %33, 4096
  store i32 %34, ptr %7, align 4, !tbaa !13
  %35 = load i32, ptr %9, align 4, !tbaa !13
  %36 = load i32, ptr %8, align 4, !tbaa !13
  %37 = load i32, ptr %7, align 4, !tbaa !13
  %38 = add i32 %36, %37
  %39 = icmp ult i32 %35, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %30
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !13
  %43 = icmp ult i32 1, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !13
  br label %47

46:                                               ; preds = %40
  br label %47

47:                                               ; preds = %46, %44
  %48 = phi i32 [ %45, %44 ], [ 1, %46 ]
  call void @libxsmm_handle_error(ptr noundef %41, i32 noundef 90002, ptr noundef @__func__.libxsmm_aarch64_instruction_close_data, ptr noundef @.str.1, i32 noundef 208, i32 noundef %48)
  store i32 1, ptr %10, align 4
  br label %114

49:                                               ; preds = %30
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !13
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [81920 x i8], ptr %55, i64 0, i64 0
  %57 = load i32, ptr %8, align 4, !tbaa !13
  %58 = zext i32 %57 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %53, ptr align 4 %56, i64 %58, i1 false)
  %59 = load i32, ptr %7, align 4, !tbaa !13
  %60 = load i32, ptr %8, align 4, !tbaa !13
  %61 = add i32 %59, %60
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !12
  %65 = sub i32 %61, %64
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %66, i32 0, i32 4
  store i32 %65, ptr %67, align 4, !tbaa !17
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %68

68:                                               ; preds = %109, %49
  %69 = load i32, ptr %5, align 4, !tbaa !13
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 4, !tbaa !18
  %73 = icmp ult i32 %69, %72
  br i1 %73, label %74, label %112

74:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %75, i32 0, i32 2
  %77 = load i32, ptr %5, align 4, !tbaa !13
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [128 x i32], ptr %76, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !13
  store i32 %80, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !13
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 1 %84, i64 4, i1 false)
  %85 = load i32, ptr %12, align 4, !tbaa !13
  %86 = lshr i32 %85, 27
  store i32 %86, ptr %13, align 4, !tbaa !13
  %87 = load i32, ptr %7, align 4, !tbaa !13
  %88 = load i32, ptr %11, align 4, !tbaa !13
  %89 = sub i32 %87, %88
  %90 = load i32, ptr %12, align 4, !tbaa !13
  %91 = and i32 2097151, %90
  %92 = add i32 %89, %91
  store i32 %92, ptr %14, align 4, !tbaa !13
  %93 = load i32, ptr %13, align 4, !tbaa !13
  %94 = and i32 31, %93
  %95 = or i32 268435456, %94
  store i32 %95, ptr %15, align 4, !tbaa !13
  %96 = load i32, ptr %14, align 4, !tbaa !13
  %97 = and i32 2097148, %96
  %98 = shl i32 %97, 3
  %99 = load i32, ptr %14, align 4, !tbaa !13
  %100 = and i32 3, %99
  %101 = shl i32 %100, 29
  %102 = or i32 %98, %101
  %103 = load i32, ptr %15, align 4, !tbaa !13
  %104 = or i32 %103, %102
  store i32 %104, ptr %15, align 4, !tbaa !13
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load i32, ptr %11, align 4, !tbaa !13
  %107 = zext i32 %106 to i64
  %108 = getelementptr inbounds i8, ptr %105, i64 %107
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %108, ptr align 4 %15, i64 4, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %109

109:                                              ; preds = %74
  %110 = load i32, ptr %5, align 4, !tbaa !13
  %111 = add i32 %110, 1
  store i32 %111, ptr %5, align 4, !tbaa !13
  br label %68, !llvm.loop !19

112:                                              ; preds = %68
  br label %113

113:                                              ; preds = %112, %2
  store i32 0, ptr %10, align 4
  br label %114

114:                                              ; preds = %113, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %115 = load i32, ptr %10, align 4
  switch i32 %115, label %117 [
    i32 0, label %116
    i32 1, label %116
  ]

116:                                              ; preds = %114, %114
  ret void

117:                                              ; preds = %114
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #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 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"libxsmm_generated_code", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 81920}
!15 = !{!"libxsmm_const_data_tracker", !7, i64 0, !11, i64 81920, !7, i64 81924, !11, i64 82436}
!16 = !{!10, !11, i64 8}
!17 = !{!10, !11, i64 20}
!18 = !{!15, !11, i64 82436}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@libxsmm_ninit = external local_unnamed_addr global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@__func__.libxsmm_aarch64_instruction_close_data = external hidden unnamed_addr constant [39 x i8], align 1

declare void @libxsmm_handle_error(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_aarch64_instruction_close_data(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = getelementptr inbounds i8, ptr %1, i64 81920
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.loopexit, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = load i32, ptr %4, align 4, !tbaa !14
  %11 = add i32 %10, 4095
  %12 = and i32 %11, -4096
  %13 = add i32 %12, %6
  %14 = icmp ult i32 %9, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %7
  %16 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !15
  %17 = icmp ugt i32 %16, 1
  %18 = load i32, ptr @libxsmm_verbosity, align 4
  %19 = select i1 %17, i32 %18, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90002, ptr noundef nonnull @__func__.libxsmm_aarch64_instruction_close_data, ptr noundef nonnull @.str.1, i32 noundef 208, i32 noundef %19) #3
  br label %.loopexit

20:                                               ; preds = %7
  %21 = zext i32 %12 to i64
  %22 = getelementptr inbounds i8, ptr %3, i64 %21
  %23 = zext i32 %6 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr nonnull align 4 %1, i64 %23, i1 false)
  %24 = load i32, ptr %4, align 4, !tbaa !14
  %25 = sub i32 %13, %24
  %26 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %25, ptr %26, align 4, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %1, i64 82436
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %.not38 = icmp eq i32 %28, 0
  br i1 %.not38, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %20
  %29 = getelementptr inbounds i8, ptr %1, i64 81924
  br label %30

30:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %31 = getelementptr inbounds [128 x i32], ptr %29, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %3, i64 %33
  %.0.copyload4 = load i32, ptr %34, align 1
  %35 = lshr i32 %.0.copyload4, 27
  %36 = sub i32 %12, %32
  %37 = add i32 %.0.copyload4, %36
  %38 = shl i32 %37, 3
  %39 = and i32 %38, 16777184
  %40 = shl i32 %37, 29
  %41 = and i32 %40, 1610612736
  %42 = or disjoint i32 %35, %41
  %43 = or disjoint i32 %42, %39
  %44 = or disjoint i32 %43, 268435456
  store i32 %44, ptr %34, align 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %45 = load i32, ptr %27, align 4, !tbaa !17
  %46 = zext i32 %45 to i64
  %47 = icmp ult i64 %indvars.iv.next, %46
  br i1 %47, label %30, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %30, %20, %2, %15
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 0}
!6 = !{!"libxsmm_generated_code", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 81920}
!12 = !{!"libxsmm_const_data_tracker", !8, i64 0, !10, i64 81920, !8, i64 81924, !10, i64 82436}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 12}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !10, i64 20}
!17 = !{!12, !10, i64 82436}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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