; LLVM IR from libxsmm/libxsmm :: samples/encoder (encoder_aarch64)

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

@__const.test_gpr_alu_move_imm16.shift = external hidden unnamed_addr constant [4 x i8], align 1
@__const.test_gpr_alu_move_imm16.imm = external hidden unnamed_addr constant [4 x i16], align 2

; Function Attrs: nounwind uwtable
declare dso_local void @reset_code_buffer(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @dump_code_buffer(ptr noundef, ptr 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: 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

; Function Attrs: nounwind uwtable
define dso_local void @test_gpr_alu_move_imm16(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca [4 x i8], align 1
  %9 = alloca [4 x i16], align 2
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @__const.test_gpr_alu_move_imm16.shift, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %9, ptr align 2 @__const.test_gpr_alu_move_imm16.imm, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @reset_code_buffer(ptr noundef %11, ptr noundef %12)
  store i8 0, ptr %7, align 1, !tbaa !11
  br label %13

13:                                               ; preds = %68, %3
  %14 = load i8, ptr %7, align 1, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = icmp slt i32 %15, 64
  br i1 %16, label %17, label %71

17:                                               ; preds = %13
  %18 = load i8, ptr %7, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp slt i32 %19, 32
  br i1 %20, label %21, label %44

21:                                               ; preds = %17
  store i8 0, ptr %10, align 1, !tbaa !11
  br label %22

22:                                               ; preds = %40, %21
  %23 = load i8, ptr %10, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %24, 2
  br i1 %25, label %26, label %43

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i8, ptr %7, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = load i8, ptr %10, align 1, !tbaa !11
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds [4 x i8], ptr %8, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = load i8, ptr %10, align 1, !tbaa !11
  %36 = zext i8 %35 to i64
  %37 = getelementptr inbounds [4 x i16], ptr %9, i64 0, i64 %36
  %38 = load i16, ptr %37, align 2, !tbaa !12
  %39 = zext i16 %38 to i32
  call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %27, i32 noundef %28, i32 noundef %30, i8 noundef zeroext %34, i32 noundef %39)
  br label %40

40:                                               ; preds = %26
  %41 = load i8, ptr %10, align 1, !tbaa !11
  %42 = add i8 %41, 1
  store i8 %42, ptr %10, align 1, !tbaa !11
  br label %22, !llvm.loop !14

43:                                               ; preds = %22
  br label %67

44:                                               ; preds = %17
  store i8 0, ptr %10, align 1, !tbaa !11
  br label %45

45:                                               ; preds = %63, %44
  %46 = load i8, ptr %10, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = icmp slt i32 %47, 4
  br i1 %48, label %49, label %66

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = load i8, ptr %7, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = load i8, ptr %10, align 1, !tbaa !11
  %55 = zext i8 %54 to i64
  %56 = getelementptr inbounds [4 x i8], ptr %8, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = load i8, ptr %10, align 1, !tbaa !11
  %59 = zext i8 %58 to i64
  %60 = getelementptr inbounds [4 x i16], ptr %9, i64 0, i64 %59
  %61 = load i16, ptr %60, align 2, !tbaa !12
  %62 = zext i16 %61 to i32
  call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %50, i32 noundef %51, i32 noundef %53, i8 noundef zeroext %57, i32 noundef %62)
  br label %63

63:                                               ; preds = %49
  %64 = load i8, ptr %10, align 1, !tbaa !11
  %65 = add i8 %64, 1
  store i8 %65, ptr %10, align 1, !tbaa !11
  br label %45, !llvm.loop !16

66:                                               ; preds = %45
  br label %67

67:                                               ; preds = %66, %43
  br label %68

68:                                               ; preds = %67
  %69 = load i8, ptr %7, align 1, !tbaa !11
  %70 = add i8 %69, 1
  store i8 %70, ptr %7, align 1, !tbaa !11
  br label %13, !llvm.loop !17

71:                                               ; preds = %13
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  call void @dump_code_buffer(ptr noundef %72, ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  ret void
}

declare void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i32 noundef) #3

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


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

@__const.test_gpr_alu_move_imm16.shift = external hidden unnamed_addr constant [4 x i8], align 1
@__const.test_gpr_alu_move_imm16.imm = external hidden unnamed_addr constant [4 x i16], align 2

; Function Attrs: nounwind uwtable
declare dso_local void @reset_code_buffer(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @dump_code_buffer(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @test_gpr_alu_move_imm16(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @reset_code_buffer(ptr noundef %1, ptr noundef %0)
  %4 = load i8, ptr @__const.test_gpr_alu_move_imm16.shift, align 1
  %5 = load i16, ptr @__const.test_gpr_alu_move_imm16.imm, align 2
  %6 = zext i16 %5 to i32
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.shift, i64 1), align 1
  %8 = load i16, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.imm, i64 2), align 2
  %9 = zext i16 %8 to i32
  %10 = load i8, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.shift, i64 2), align 1
  %11 = load i16, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.imm, i64 4), align 2
  %12 = zext i16 %11 to i32
  %13 = load i8, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.shift, i64 3), align 1
  %14 = load i16, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.imm, i64 6), align 2
  %15 = zext i16 %14 to i32
  %16 = load i8, ptr @__const.test_gpr_alu_move_imm16.shift, align 1
  %17 = load i16, ptr @__const.test_gpr_alu_move_imm16.imm, align 2
  %18 = zext i16 %17 to i32
  %19 = load i8, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.shift, i64 1), align 1
  %20 = load i16, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_move_imm16.imm, i64 2), align 2
  %21 = zext i16 %20 to i32
  br label %22

22:                                               ; preds = %3, %.loopexit
  %indvars.iv = phi i32 [ 0, %3 ], [ %indvars.iv.next, %.loopexit ]
  %23 = icmp ult i32 %indvars.iv, 32
  br i1 %23, label %.preheader.preheader, label %.preheader22.preheader

.preheader22.preheader:                           ; preds = %22
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %4, i32 noundef %6) #2
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %7, i32 noundef %9) #2
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %10, i32 noundef %12) #2
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %13, i32 noundef %15) #2
  br label %.loopexit

.preheader.preheader:                             ; preds = %22
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %16, i32 noundef %18) #2
  tail call void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i8 noundef zeroext %19, i32 noundef %21) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader22.preheader, %.preheader.preheader
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %exitcond.not = icmp eq i32 %indvars.iv.next, 64
  br i1 %exitcond.not, label %24, label %22, !llvm.loop !5

24:                                               ; preds = %.loopexit
  tail call void @dump_code_buffer(ptr noundef %1, ptr noundef %0)
  ret void
}

declare void @libxsmm_aarch64_instruction_alu_move_imm16(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #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 = { "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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass