; LLVM IR from libxsmm/libxsmm :: src (generator_x86_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 = external hidden unnamed_addr constant [82 x i8], align 1
@libxsmm_ninit = external global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@__func__.libxsmm_x86_instruction_close_data = external hidden unnamed_addr constant [35 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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) #1

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

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

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

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

42:                                               ; preds = %38
  %43 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !13
  br label %45

44:                                               ; preds = %38
  br label %45

45:                                               ; preds = %44, %42
  %46 = phi i32 [ %43, %42 ], [ 1, %44 ]
  call void @libxsmm_handle_error(ptr noundef %39, i32 noundef 90002, ptr noundef @__func__.libxsmm_x86_instruction_close_data, ptr noundef @.str, i32 noundef 5041, i32 noundef %46)
  store i32 1, ptr %10, align 4
  br label %100

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

66:                                               ; preds = %95, %47
  %67 = load i32, ptr %5, align 4, !tbaa !13
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 4, !tbaa !18
  %71 = icmp ult i32 %67, %70
  br i1 %71, label %72, label %98

72:                                               ; preds = %66
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.libxsmm_const_data_tracker, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %5, align 4, !tbaa !13
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds [128 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !13
  store i32 %78, 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
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !13
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = getelementptr inbounds i8, ptr %82, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 1 %83, i64 4, i1 false)
  %84 = load i32, ptr %7, align 4, !tbaa !13
  %85 = load i32, ptr %11, align 4, !tbaa !13
  %86 = sub i32 %84, %85
  %87 = sub i32 %86, 7
  %88 = load i32, ptr %12, align 4, !tbaa !13
  %89 = add i32 %87, %88
  store i32 %89, ptr %13, align 4, !tbaa !13
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load i32, ptr %11, align 4, !tbaa !13
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %90, i64 %92
  %94 = getelementptr inbounds i8, ptr %93, i64 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %94, ptr align 4 %13, i64 4, i1 false)
  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 %95

95:                                               ; preds = %72
  %96 = load i32, ptr %5, align 4, !tbaa !13
  %97 = add i32 %96, 1
  store i32 %97, ptr %5, align 4, !tbaa !13
  br label %66, !llvm.loop !19

98:                                               ; preds = %66
  br label %99

99:                                               ; preds = %98, %2
  store i32 0, ptr %10, align 4
  br label %100

100:                                              ; preds = %99, %45
  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
  %101 = load i32, ptr %10, align 4
  switch i32 %101, label %103 [
    i32 0, label %102
    i32 1, label %102
  ]

102:                                              ; preds = %100, %100
  ret void

103:                                              ; preds = %100
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = external hidden unnamed_addr constant [82 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_x86_instruction_close_data = external hidden unnamed_addr constant [35 x i8], align 1

; 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) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_x86_instruction_close_data(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %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_x86_instruction_close_data, ptr noundef nonnull @.str, i32 noundef 5041, 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
  %invariant.gep = getelementptr inbounds i8, ptr %3, i64 3
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %.not33 = icmp eq i32 %28, 0
  br i1 %.not33, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %20
  %29 = getelementptr inbounds i8, ptr %1, i64 81924
  %30 = add i32 %12, -7
  br label %31

31:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %32 = getelementptr inbounds [128 x i32], ptr %29, i64 0, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = zext i32 %33 to i64
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %34
  %.0.copyload1 = load i32, ptr %gep, align 1
  %35 = sub i32 %30, %33
  %36 = add i32 %35, %.0.copyload1
  store i32 %36, ptr %gep, align 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr %27, align 4, !tbaa !17
  %38 = zext i32 %37 to i64
  %39 = icmp ult i64 %indvars.iv.next, %38
  br i1 %39, label %31, label %.loopexit, !llvm.loop !18

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass