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

; 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_meqn_elem = type { ptr, ptr, ptr, ptr, i32, %union.libxsmm_meqn_info, i32, i32, %struct.libxsmm_meqn_tmp_info, i32, i32, i32, %union.libxsmm_meqn_fusion_info }
%union.libxsmm_meqn_info = type { %struct.libxsmm_meqn_arg }
%struct.libxsmm_meqn_arg = type { i32, i32, i32, i32, i32, i32, i32, %struct.libxsmm_matrix_arg_attributes }
%struct.libxsmm_matrix_arg_attributes = type { i32, i32, i32, i32 }
%struct.libxsmm_meqn_tmp_info = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%union.libxsmm_meqn_fusion_info = type { %struct.libxsmm_meqn_xgemm_fusion_info }
%struct.libxsmm_meqn_xgemm_fusion_info = type { i32, i32, i32, i32, i32 }
%struct.libxsmm_matrix_eqn = type { ptr, ptr, i32, i32, i32, i32 }

@libxsmm_matrix_eqns = external dso_local global [4096 x ptr], align 64
@.str.5 = external hidden unnamed_addr constant [73 x i8], align 1
@stderr = external global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [13 x i8], align 1
@libxsmm_matrix_eqns_count = external dso_local global i32, align 64
@libxsmm_matrix_eqns_init = external dso_local global i32, align 64
@.str.36 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_meqn_create = external hidden unnamed_addr constant [42 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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: nounwind uwtable
define dso_local i32 @libxsmm_meqn_create() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %6 = load i32, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  store i32 %6, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %7 = load i32, ptr @libxsmm_matrix_eqns_init, align 64, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %21

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %17, %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 4096
  br i1 %12, label %13, label %20

13:                                               ; preds = %10
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %15
  store ptr null, ptr %16, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !11

20:                                               ; preds = %10
  store i32 0, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  store i32 1, ptr @libxsmm_matrix_eqns_init, align 64, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %21

21:                                               ; preds = %20, %0
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp sge i32 %22, 4096
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.36, i32 noundef 4096) #5
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %81

27:                                               ; preds = %21
  %28 = load i32, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  %30 = call noalias ptr @malloc(i64 noundef 32) #6
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %32
  store ptr %30, ptr %33, align 8, !tbaa !9
  %34 = call noalias ptr @malloc(i64 noundef 184) #6
  store ptr %34, ptr %3, align 8, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = icmp ne ptr null, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %27
  br label %39

38:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.20, ptr noundef @.str.5, i32 noundef 1304, ptr noundef @__PRETTY_FUNCTION__.libxsmm_meqn_create) #7
  unreachable

39:                                               ; preds = %37
  %40 = load ptr, ptr %3, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %40, i32 0, i32 0
  store ptr null, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %42, i32 0, i32 1
  store ptr null, ptr %43, align 8, !tbaa !13
  %44 = load ptr, ptr %3, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %44, i32 0, i32 3
  store ptr null, ptr %45, align 8, !tbaa !13
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %46, i32 0, i32 4
  store i32 0, ptr %47, align 8, !tbaa !13
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %52, i32 0, i32 0
  store ptr %48, ptr %53, align 8, !tbaa !13
  %54 = load ptr, ptr %3, align 8, !tbaa !9
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %58, i32 0, i32 1
  store ptr %54, ptr %59, align 8, !tbaa !13
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %61
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %63, i32 0, i32 2
  store i32 0, ptr %64, align 8, !tbaa !13
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %68, i32 0, i32 3
  store i32 0, ptr %69, align 4, !tbaa !13
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %73, i32 0, i32 4
  store i32 0, ptr %74, align 8, !tbaa !13
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %78, i32 0, i32 4
  store i32 0, ptr %79, align 8, !tbaa !13
  %80 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %80, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %81

81:                                               ; preds = %39, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %82 = load i32, ptr %1, align 4
  ret i32 %82
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { 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 = { 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) }
attributes #7 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}


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

@libxsmm_matrix_eqns = external dso_local local_unnamed_addr global [4096 x ptr], align 64
@.str.5 = external hidden unnamed_addr constant [73 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [13 x i8], align 1
@libxsmm_matrix_eqns_count = external dso_local local_unnamed_addr global i32, align 64
@libxsmm_matrix_eqns_init = external dso_local local_unnamed_addr global i32, align 64
@.str.36 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_meqn_create = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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: nounwind uwtable
define dso_local range(i32 -2147483648, 4096) i32 @libxsmm_meqn_create() local_unnamed_addr #3 {
  %1 = load i32, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  %2 = load i32, ptr @libxsmm_matrix_eqns_init, align 64, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %.preheader.preheader, label %4

.preheader.preheader:                             ; preds = %0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 64 dereferenceable(32768) @libxsmm_matrix_eqns, i8 0, i64 32768, i1 false), !tbaa !9
  store i32 0, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  store i32 1, ptr @libxsmm_matrix_eqns_init, align 64, !tbaa !5
  br label %4

4:                                                ; preds = %.preheader.preheader, %0
  %5 = phi i32 [ 0, %.preheader.preheader ], [ %1, %0 ]
  %6 = icmp sgt i32 %1, 4095
  br i1 %6, label %7, label %10

7:                                                ; preds = %4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.36, i32 noundef 4096) #5
  br label %24

10:                                               ; preds = %4
  %11 = add nsw i32 %5, 1
  store i32 %11, ptr @libxsmm_matrix_eqns_count, align 64, !tbaa !5
  %12 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #6
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %13
  store ptr %12, ptr %14, align 8, !tbaa !9
  %15 = tail call noalias dereferenceable_or_null(184) ptr @malloc(i64 noundef 184) #6
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %16, label %17

16:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.20, ptr noundef nonnull @.str.5, i32 noundef 1304, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_meqn_create) #7
  unreachable

17:                                               ; preds = %10
  %18 = getelementptr inbounds i8, ptr %15, i64 24
  store ptr null, ptr %18, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %15, i64 32
  store i32 0, ptr %19, align 8, !tbaa !11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %15, i8 0, i64 16, i1 false)
  store ptr %15, ptr %12, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %15, ptr %20, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %12, i64 16
  store i32 0, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %12, i64 20
  store i32 0, ptr %22, align 4, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %12, i64 24
  store i32 0, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %17, %7
  %.019 = phi i32 [ -1, %7 ], [ %1, %17 ]
  ret i32 %.019
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { noreturn 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 = { 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { cold nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


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