; LLVM IR from libxsmm/libxsmm :: src (generator_common)

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

@__func__.libxsmm_append_code_as_string = external hidden unnamed_addr constant [30 x i8], align 1
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@libxsmm_ninit = external global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_append_code_as_string(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 i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %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 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = icmp ugt i32 %17, 1
  br i1 %18, label %19, label %28

19:                                               ; preds = %3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !9
  %22 = icmp ult i32 1, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  br label %26

25:                                               ; preds = %19
  br label %26

26:                                               ; preds = %25, %23
  %27 = phi i32 [ %24, %23 ], [ 1, %25 ]
  call void @libxsmm_handle_error(ptr noundef %20, i32 noundef 90003, ptr noundef @__func__.libxsmm_append_code_as_string, ptr noundef @.str, i32 noundef 49, i32 noundef %27)
  store i32 1, ptr %11, align 4
  br label %111

28:                                               ; preds = %3
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = zext i32 %34 to i64
  store i64 %35, ptr %7, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %31, %28
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %47

39:                                               ; preds = %36
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !17
  %42 = sext i8 %41 to i32
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %39
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  store i64 %46, ptr %8, align 8, !tbaa !11
  br label %50

47:                                               ; preds = %39, %36
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.1) #5
  store i32 1, ptr %11, align 4
  br label %111

50:                                               ; preds = %44
  %51 = load i64, ptr %7, align 8, !tbaa !11
  %52 = load i64, ptr %8, align 8, !tbaa !11
  %53 = add i64 %51, %52
  %54 = add i64 %53, 1
  %55 = mul i64 1, %54
  %56 = call noalias ptr @malloc(i64 noundef %55) #6
  store ptr %56, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %68

59:                                               ; preds = %50
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !9
  %62 = icmp ult i32 1, %61
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  br label %66

65:                                               ; preds = %59
  br label %66

66:                                               ; preds = %65, %63
  %67 = phi i32 [ %64, %63 ], [ 1, %65 ]
  call void @libxsmm_handle_error(ptr noundef %60, i32 noundef 90001, ptr noundef @__func__.libxsmm_append_code_as_string, ptr noundef @.str, i32 noundef 67, i32 noundef %67)
  store i32 1, ptr %11, align 4
  br label %111

68:                                               ; preds = %50
  %69 = load i64, ptr %7, align 8, !tbaa !11
  %70 = icmp ugt i64 %69, 0
  br i1 %70, label %71, label %80

71:                                               ; preds = %68
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load i64, ptr %7, align 8, !tbaa !11
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = add i64 %74, %75
  %77 = trunc i64 %76 to i32
  %78 = load i64, ptr %7, align 8, !tbaa !11
  %79 = trunc i64 %78 to i32
  call void @libxsmm_strncpy(ptr noundef %72, ptr noundef %73, i32 noundef %77, i32 noundef %79)
  br label %83

80:                                               ; preds = %68
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 0
  store i8 0, ptr %82, align 1, !tbaa !17
  br label %83

83:                                               ; preds = %80, %71
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %90

86:                                               ; preds = %83
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = call ptr @strcat(ptr noundef %87, ptr noundef %88) #5
  br label %90

90:                                               ; preds = %86, %83
  %91 = load i64, ptr %7, align 8, !tbaa !11
  %92 = icmp ugt i64 %91, 0
  br i1 %92, label %93, label %95

93:                                               ; preds = %90
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %94) #5
  br label %95

95:                                               ; preds = %93, %90
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %97, i32 0, i32 0
  store ptr %96, ptr %98, align 8, !tbaa !13
  %99 = load i64, ptr %7, align 8, !tbaa !11
  %100 = load i64, ptr %8, align 8, !tbaa !11
  %101 = add i64 %99, %100
  %102 = trunc i64 %101 to i32
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %103, i32 0, i32 2
  store i32 %102, ptr %104, align 4, !tbaa !16
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 4, !tbaa !16
  %108 = add i32 %107, 1
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %109, i32 0, i32 1
  store i32 %108, ptr %110, align 8, !tbaa !18
  store i32 0, ptr %11, align 4
  br label %111

111:                                              ; preds = %95, %66, %47, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %112 = load i32, ptr %11, align 4
  switch i32 %112, label %114 [
    i32 0, label %113
    i32 1, label %113
  ]

113:                                              ; preds = %111, %111
  ret void

114:                                              ; preds = %111
  unreachable
}

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

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @libxsmm_strncpy(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #4

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind allocsize(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 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"libxsmm_generated_code", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 16}
!16 = !{!14, !10, i64 12}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !10, 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"

@__func__.libxsmm_append_code_as_string = external hidden unnamed_addr constant [30 x i8], align 1
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@libxsmm_ninit = external local_unnamed_addr global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_append_code_as_string(ptr noundef %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = icmp ugt i32 %6, 1
  br i1 %7, label %8, label %13

8:                                                ; preds = %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 90003, ptr noundef nonnull @__func__.libxsmm_append_code_as_string, ptr noundef nonnull @.str, i32 noundef 49, i32 noundef %12)
  br label %45

13:                                               ; preds = %3
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %18, label %14

14:                                               ; preds = %13
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = zext i32 %16 to i64
  br label %18

18:                                               ; preds = %14, %13
  %.0 = phi i64 [ %17, %14 ], [ 0, %13 ]
  %.not32 = icmp eq ptr %1, null
  br i1 %.not32, label %27, label %19

19:                                               ; preds = %18
  %20 = load i8, ptr %1, align 1, !tbaa !14
  %.not33 = icmp eq i8 %20, 0
  br i1 %.not33, label %27, label %21

21:                                               ; preds = %19
  %22 = sext i32 %2 to i64
  %23 = add nsw i64 %.0, %22
  %24 = add nsw i64 %23, 1
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #6
  %26 = icmp eq ptr %25, null
  br i1 %26, label %30, label %35

27:                                               ; preds = %19, %18
  %28 = load ptr, ptr @stderr, align 8, !tbaa !15
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.1) #7
  br label %45

30:                                               ; preds = %21
  %31 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %32 = icmp ugt i32 %31, 1
  %33 = load i32, ptr @libxsmm_verbosity, align 4
  %34 = select i1 %32, i32 %33, i32 1
  tail call void @libxsmm_handle_error(ptr noundef nonnull %0, i32 noundef 90001, ptr noundef nonnull @__func__.libxsmm_append_code_as_string, ptr noundef nonnull @.str, i32 noundef 67, i32 noundef %34)
  br label %45

35:                                               ; preds = %21
  %.not34 = icmp eq i64 %.0, 0
  br i1 %.not34, label %.thread, label %37

.thread:                                          ; preds = %35
  store i8 0, ptr %25, align 1, !tbaa !14
  %36 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) %1) #8
  br label %41

37:                                               ; preds = %35
  %38 = trunc i64 %23 to i32
  %39 = trunc nuw i64 %.0 to i32
  tail call void @libxsmm_strncpy(ptr noundef nonnull %25, ptr noundef %4, i32 noundef %38, i32 noundef %39)
  %40 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) %25, ptr noundef nonnull dereferenceable(1) %1) #8
  tail call void @free(ptr noundef %4) #8
  br label %41

41:                                               ; preds = %.thread, %37
  %.pre-phi = phi i32 [ %2, %.thread ], [ %38, %37 ]
  store ptr %25, ptr %0, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %.pre-phi, ptr %42, align 4, !tbaa !13
  %43 = add i32 %.pre-phi, 1
  %44 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %43, ptr %44, align 8, !tbaa !16
  br label %45

45:                                               ; preds = %41, %30, %27, %8
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @libxsmm_strncpy(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

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 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { inlinehint 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { nounwind allocsize(0) }
attributes #7 = { cold nounwind }
attributes #8 = { 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 = !{!6, !10, i64 16}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 12}
!14 = !{!8, !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass