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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [98 x i8], align 1
@.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_stream = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_aarch64_instruction_restore_regs(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_aarch64_instruction_close_stream(ptr noundef %0, i16 noundef zeroext %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %8, i32 0, i32 6
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp ult i32 %10, 2001
  br i1 %11, label %12, label %23

12:                                               ; preds = %2
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !14
  %17 = icmp ult i32 1, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %12
  %19 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !14
  br label %21

20:                                               ; preds = %12
  br label %21

21:                                               ; preds = %20, %18
  %22 = phi i32 [ %19, %18 ], [ 1, %20 ]
  call void @libxsmm_handle_error(ptr noundef %15, i32 noundef 90000, ptr noundef @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef @.str.1, i32 noundef 162, i32 noundef %22)
  br label %78

23:                                               ; preds = %2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i16, ptr %4, align 2, !tbaa !9
  call void @libxsmm_aarch64_instruction_restore_regs(ptr noundef %24, i16 noundef zeroext %25)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = icmp ugt i32 %28, 1
  br i1 %29, label %30, label %67

30:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = udiv i32 %33, 4
  store i32 %34, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = sub i32 %40, %43
  %45 = icmp ult i32 %44, 4
  br i1 %45, label %46, label %55

46:                                               ; preds = %30
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !14
  %49 = icmp ult i32 1, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !14
  br label %53

52:                                               ; preds = %46
  br label %53

53:                                               ; preds = %52, %50
  %54 = phi i32 [ %51, %50 ], [ 1, %52 ]
  call void @libxsmm_handle_error(ptr noundef %47, i32 noundef 90002, ptr noundef @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef @.str.1, i32 noundef 175, i32 noundef %54)
  store i32 1, ptr %7, align 4
  br label %64

55:                                               ; preds = %30
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !14
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  store i32 -698416192, ptr %59, align 4, !tbaa !14
  %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 !16
  %63 = add i32 %62, 4
  store i32 %63, ptr %61, align 4, !tbaa !16
  store i32 0, ptr %7, align 4
  br label %64

64:                                               ; preds = %55, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %65 = load i32, ptr %7, align 4
  switch i32 %65, label %79 [
    i32 0, label %66
    i32 1, label %78
  ]

66:                                               ; preds = %64
  br label %78

67:                                               ; preds = %23
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str.3) #4
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !14
  %72 = icmp ult i32 1, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %67
  %74 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !14
  br label %76

75:                                               ; preds = %67
  br label %76

76:                                               ; preds = %75, %73
  %77 = phi i32 [ %74, %73 ], [ 1, %75 ]
  call void @libxsmm_handle_error(ptr noundef %70, i32 noundef 90000, ptr noundef @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef @.str.1, i32 noundef 187, i32 noundef %77)
  br label %78

78:                                               ; preds = %76, %66, %64, %21
  ret void

79:                                               ; preds = %64
  unreachable
}

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

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

attributes #0 = { nounwind "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 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 nosync 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !13, i64 28}
!12 = !{!"libxsmm_generated_code", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 12}
!17 = !{!12, !6, i64 0}
!18 = !{!12, !13, i64 8}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [98 x i8], align 1
@.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_stream = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #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
declare dso_local void @libxsmm_aarch64_instruction_restore_regs(ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_aarch64_instruction_close_stream(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp ult i32 %4, 2001
  br i1 %5, label %6, label %13

6:                                                ; preds = %2
  %7 = load ptr, ptr @stderr, align 8, !tbaa !11
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str) #3
  %9 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %10 = icmp ugt i32 %9, 1
  %11 = load i32, ptr @libxsmm_verbosity, align 4
  %12 = select i1 %10, i32 %11, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef nonnull @.str.1, i32 noundef 162, i32 noundef %12) #4
  br label %43

13:                                               ; preds = %2
  tail call void @libxsmm_aarch64_instruction_restore_regs(ptr noundef nonnull %0, i16 noundef zeroext %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = icmp ugt i32 %15, 1
  br i1 %16, label %17, label %36

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = sub i32 %21, %19
  %23 = icmp ult i32 %22, 4
  br i1 %23, label %24, label %29

24:                                               ; preds = %17
  %25 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %26 = icmp ugt i32 %25, 1
  %27 = load i32, ptr @libxsmm_verbosity, align 4
  %28 = select i1 %26, i32 %27, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90002, ptr noundef nonnull @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef nonnull @.str.1, i32 noundef 175, i32 noundef %28) #4
  br label %43

29:                                               ; preds = %17
  %30 = load ptr, ptr %0, align 8, !tbaa !16
  %31 = lshr i32 %19, 2
  %32 = zext nneg i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  store i32 -698416192, ptr %33, align 4, !tbaa !12
  %34 = load i32, ptr %18, align 4, !tbaa !14
  %35 = add i32 %34, 4
  store i32 %35, ptr %18, align 4, !tbaa !14
  br label %43

36:                                               ; preds = %13
  %37 = load ptr, ptr @stderr, align 8, !tbaa !11
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.3) #3
  %39 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %40 = icmp ugt i32 %39, 1
  %41 = load i32, ptr @libxsmm_verbosity, align 4
  %42 = select i1 %40, i32 %41, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90000, ptr noundef nonnull @__func__.libxsmm_aarch64_instruction_close_stream, ptr noundef nonnull @.str.1, i32 noundef 187, i32 noundef %42) #4
  br label %43

43:                                               ; preds = %24, %29, %36, %6
  ret void
}

attributes #0 = { nofree nounwind "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 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 = { cold nounwind }
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, !10, i64 28}
!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 = !{!7, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 12}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass