; 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_compute_imm12.shift = external hidden unnamed_addr constant [2 x i8], align 1

; 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_compute_imm12(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 i8, align 1
  %9 = alloca [2 x i8], align 1
  %10 = alloca i16, align 2
  %11 = 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 1, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 @__const.test_gpr_alu_compute_imm12.shift, i64 2, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #4
  store i16 1091, ptr %10, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @reset_code_buffer(ptr noundef %12, ptr noundef %13)
  store i8 0, ptr %7, align 1, !tbaa !13
  br label %14

14:                                               ; preds = %49, %3
  %15 = load i8, ptr %7, align 1, !tbaa !13
  %16 = zext i8 %15 to i32
  %17 = icmp slt i32 %16, 32
  br i1 %17, label %18, label %52

18:                                               ; preds = %14
  store i8 0, ptr %8, align 1, !tbaa !13
  br label %19

19:                                               ; preds = %45, %18
  %20 = load i8, ptr %8, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 32
  br i1 %22, label %23, label %48

23:                                               ; preds = %19
  store i8 0, ptr %11, align 1, !tbaa !13
  br label %24

24:                                               ; preds = %41, %23
  %25 = load i8, ptr %11, align 1, !tbaa !13
  %26 = zext i8 %25 to i32
  %27 = icmp slt i32 %26, 2
  br i1 %27, label %28, label %44

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

41:                                               ; preds = %28
  %42 = load i8, ptr %11, align 1, !tbaa !13
  %43 = add i8 %42, 1
  store i8 %43, ptr %11, align 1, !tbaa !13
  br label %24, !llvm.loop !14

44:                                               ; preds = %24
  br label %45

45:                                               ; preds = %44
  %46 = load i8, ptr %8, align 1, !tbaa !13
  %47 = add i8 %46, 1
  store i8 %47, ptr %8, align 1, !tbaa !13
  br label %19, !llvm.loop !16

48:                                               ; preds = %19
  br label %49

49:                                               ; preds = %48
  %50 = load i8, ptr %7, align 1, !tbaa !13
  %51 = add i8 %50, 1
  store i8 %51, ptr %7, align 1, !tbaa !13
  br label %14, !llvm.loop !17

52:                                               ; preds = %14
  store i8 32, ptr %7, align 1, !tbaa !13
  br label %53

53:                                               ; preds = %88, %52
  %54 = load i8, ptr %7, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = icmp slt i32 %55, 64
  br i1 %56, label %57, label %91

57:                                               ; preds = %53
  store i8 32, ptr %8, align 1, !tbaa !13
  br label %58

58:                                               ; preds = %84, %57
  %59 = load i8, ptr %8, align 1, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = icmp slt i32 %60, 64
  br i1 %61, label %62, label %87

62:                                               ; preds = %58
  store i8 0, ptr %11, align 1, !tbaa !13
  br label %63

63:                                               ; preds = %80, %62
  %64 = load i8, ptr %11, align 1, !tbaa !13
  %65 = zext i8 %64 to i32
  %66 = icmp slt i32 %65, 2
  br i1 %66, label %67, label %83

67:                                               ; preds = %63
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = load i8, ptr %8, align 1, !tbaa !13
  %71 = zext i8 %70 to i32
  %72 = load i8, ptr %7, align 1, !tbaa !13
  %73 = zext i8 %72 to i32
  %74 = load i16, ptr %10, align 2, !tbaa !11
  %75 = zext i16 %74 to i32
  %76 = load i8, ptr %11, align 1, !tbaa !13
  %77 = zext i8 %76 to i64
  %78 = getelementptr inbounds [2 x i8], ptr %9, i64 0, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !13
  call void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef %68, i32 noundef %69, i32 noundef %71, i32 noundef %73, i32 noundef %75, i8 noundef zeroext %79)
  br label %80

80:                                               ; preds = %67
  %81 = load i8, ptr %11, align 1, !tbaa !13
  %82 = add i8 %81, 1
  store i8 %82, ptr %11, align 1, !tbaa !13
  br label %63, !llvm.loop !18

83:                                               ; preds = %63
  br label %84

84:                                               ; preds = %83
  %85 = load i8, ptr %8, align 1, !tbaa !13
  %86 = add i8 %85, 1
  store i8 %86, ptr %8, align 1, !tbaa !13
  br label %58, !llvm.loop !19

87:                                               ; preds = %58
  br label %88

88:                                               ; preds = %87
  %89 = load i8, ptr %7, align 1, !tbaa !13
  %90 = add i8 %89, 1
  store i8 %90, ptr %7, align 1, !tbaa !13
  br label %53, !llvm.loop !20

91:                                               ; preds = %53
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  call void @dump_code_buffer(ptr noundef %92, ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  ret void
}

declare void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) #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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !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_compute_imm12.shift = external hidden unnamed_addr constant [2 x i8], align 1

; 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_compute_imm12(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)
  %.pre.pre = load i8, ptr @__const.test_gpr_alu_compute_imm12.shift, align 1, !tbaa !5
  %.pre62.pre = load i8, ptr getelementptr inbounds (i8, ptr @__const.test_gpr_alu_compute_imm12.shift, i64 1), align 1, !tbaa !5
  br label %.preheader38

.preheader38:                                     ; preds = %3, %4
  %indvars.iv47 = phi i32 [ 0, %3 ], [ %indvars.iv.next48, %4 ]
  br label %.preheader37

.preheader37:                                     ; preds = %.preheader38, %.preheader37
  %indvars.iv = phi i32 [ 0, %.preheader38 ], [ %indvars.iv.next, %.preheader37 ]
  tail call void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i32 noundef %indvars.iv47, i32 noundef 1091, i8 noundef zeroext %.pre.pre) #2
  tail call void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv, i32 noundef %indvars.iv47, i32 noundef 1091, i8 noundef zeroext %.pre62.pre) #2
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %exitcond.not = icmp eq i32 %indvars.iv.next, 32
  br i1 %exitcond.not, label %4, label %.preheader37, !llvm.loop !8

4:                                                ; preds = %.preheader37
  %indvars.iv.next48 = add nuw nsw i32 %indvars.iv47, 1
  %exitcond50.not = icmp eq i32 %indvars.iv.next48, 32
  br i1 %exitcond50.not, label %.preheader35, label %.preheader38, !llvm.loop !10

.preheader35:                                     ; preds = %4, %5
  %indvars.iv58 = phi i32 [ %indvars.iv.next59, %5 ], [ 32, %4 ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader35, %.preheader
  %indvars.iv54 = phi i32 [ 32, %.preheader35 ], [ %indvars.iv.next55, %.preheader ]
  tail call void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv54, i32 noundef %indvars.iv58, i32 noundef 1091, i8 noundef zeroext %.pre.pre) #2
  tail call void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef %1, i32 noundef %2, i32 noundef %indvars.iv54, i32 noundef %indvars.iv58, i32 noundef 1091, i8 noundef zeroext %.pre62.pre) #2
  %indvars.iv.next55 = add nuw nsw i32 %indvars.iv54, 1
  %exitcond57.not = icmp eq i32 %indvars.iv.next55, 64
  br i1 %exitcond57.not, label %5, label %.preheader, !llvm.loop !11

5:                                                ; preds = %.preheader
  %indvars.iv.next59 = add nuw nsw i32 %indvars.iv58, 1
  %exitcond61.not = icmp eq i32 %indvars.iv.next59, 64
  br i1 %exitcond61.not, label %6, label %.preheader35, !llvm.loop !12

6:                                                ; preds = %5
  tail call void @dump_code_buffer(ptr noundef %1, ptr noundef %0)
  ret void
}

declare void @libxsmm_aarch64_instruction_alu_compute_imm12(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}
!12 = distinct !{!12, !9}


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