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

; 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_prefetch.displ = external hidden unnamed_addr constant [3 x i32], align 4

; 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_prefetch(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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [3 x i32], align 4
  %11 = alloca i32, align 4
  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 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 2, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 @__const.test_prefetch.displ, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, 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 i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %33, %3
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ult i32 %15, 16
  br i1 %16, label %17, label %36

17:                                               ; preds = %14
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %29, %17
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = icmp ult i32 %19, 3
  br i1 %20, label %21, label %32

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [3 x i32], ptr %10, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  call void @libxsmm_x86_instruction_prefetch(ptr noundef %22, i32 noundef %23, i32 noundef %24, i32 noundef 127, i32 noundef 0, i32 noundef %28)
  br label %29

29:                                               ; preds = %21
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = add i32 %30, 1
  store i32 %31, ptr %11, align 4, !tbaa !9
  br label %18, !llvm.loop !11

32:                                               ; preds = %18
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !13

36:                                               ; preds = %14
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %66, %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp ult i32 %38, 16
  br i1 %39, label %40, label %69

40:                                               ; preds = %37
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %62, %40
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = icmp ult i32 %42, 16
  br i1 %43, label %44, label %65

44:                                               ; preds = %41
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %58, %44
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = icmp ult i32 %46, 3
  br i1 %47, label %48, label %61

48:                                               ; preds = %45
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds [3 x i32], ptr %10, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  call void @libxsmm_x86_instruction_prefetch(ptr noundef %49, i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %57)
  br label %58

58:                                               ; preds = %48
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %45, !llvm.loop !14

61:                                               ; preds = %45
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = add i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !9
  br label %41, !llvm.loop !15

65:                                               ; preds = %41
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %7, align 4, !tbaa !9
  br label %37, !llvm.loop !16

69:                                               ; preds = %37
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  call void @dump_code_buffer(ptr noundef %70, ptr noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #4
  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
  ret void
}

declare void @libxsmm_x86_instruction_prefetch(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


; 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_prefetch.displ = external hidden unnamed_addr constant [3 x i32], align 4

; 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_prefetch(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 = load i32, ptr @__const.test_prefetch.displ, align 4, !tbaa !5
  %.pre39 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_prefetch.displ, i64 4), align 4, !tbaa !5
  %.pre40 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_prefetch.displ, i64 8), align 4, !tbaa !5
  br label %.preheader28

.preheader28:                                     ; preds = %3, %.preheader28
  %.02330 = phi i32 [ 0, %3 ], [ %4, %.preheader28 ]
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.02330, i32 noundef 127, i32 noundef 0, i32 noundef %.pre) #2
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.02330, i32 noundef 127, i32 noundef 0, i32 noundef %.pre39) #2
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.02330, i32 noundef 127, i32 noundef 0, i32 noundef %.pre40) #2
  %4 = add nuw nsw i32 %.02330, 1
  %exitcond.not = icmp eq i32 %4, 16
  br i1 %exitcond.not, label %.preheader26, label %.preheader28, !llvm.loop !9

.preheader26:                                     ; preds = %.preheader28, %6
  %.12433 = phi i32 [ %7, %6 ], [ 0, %.preheader28 ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader26, %.preheader
  %.02532 = phi i32 [ 0, %.preheader26 ], [ %5, %.preheader ]
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.12433, i32 noundef %.02532, i32 noundef 2, i32 noundef %.pre) #2
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.12433, i32 noundef %.02532, i32 noundef 2, i32 noundef %.pre39) #2
  tail call void @libxsmm_x86_instruction_prefetch(ptr noundef %1, i32 noundef %2, i32 noundef %.12433, i32 noundef %.02532, i32 noundef 2, i32 noundef %.pre40) #2
  %5 = add nuw nsw i32 %.02532, 1
  %exitcond37.not = icmp eq i32 %5, 16
  br i1 %exitcond37.not, label %6, label %.preheader, !llvm.loop !11

6:                                                ; preds = %.preheader
  %7 = add nuw nsw i32 %.12433, 1
  %exitcond38.not = icmp eq i32 %7, 16
  br i1 %exitcond38.not, label %8, label %.preheader26, !llvm.loop !12

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

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


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