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

%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_arg_metadata = type { i32, i32 }
%struct.libxsmm_meqn_arg_shape = type { 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
@stderr = external global ptr, align 8
@.str.32 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [46 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @libxsmm_meqn_add_node(ptr noundef, i32 noundef, ptr noundef byval(%union.libxsmm_meqn_info) align 8) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_meqn_mov_head(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_meqn_push_back_arg(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca %struct.libxsmm_meqn_arg_metadata, align 4
  %8 = alloca %struct.libxsmm_meqn_arg_shape, align 4
  %9 = alloca %struct.libxsmm_matrix_arg_attributes, align 4
  %10 = alloca %union.libxsmm_meqn_info, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i64 %0, ptr %7, align 4
  %13 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %1, ptr %13, align 4
  %14 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %2, ptr %14, align 4
  %15 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  store i64 %3, ptr %15, align 4
  %16 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  store i64 %4, ptr %16, align 4
  call void @llvm.lifetime.start.p0(i64 44, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %17 = getelementptr inbounds %struct.libxsmm_meqn_arg_metadata, ptr %7, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %11, align 4, !tbaa !10
  %19 = load i32, ptr %11, align 4, !tbaa !10
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %5
  %25 = load ptr, ptr @stderr, align 8, !tbaa !11
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str.32) #4
  store i32 1, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %68

27:                                               ; preds = %5
  %28 = load i32, ptr %11, align 4, !tbaa !10
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %38

35:                                               ; preds = %27
  %36 = load ptr, ptr @stderr, align 8, !tbaa !11
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.33) #4
  store i32 2, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %68

38:                                               ; preds = %27
  %39 = getelementptr inbounds %struct.libxsmm_meqn_arg_shape, ptr %8, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 0
  store i32 %40, ptr %41, align 4, !tbaa !13
  %42 = getelementptr inbounds %struct.libxsmm_meqn_arg_shape, ptr %8, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 1
  store i32 %43, ptr %44, align 4, !tbaa !13
  %45 = getelementptr inbounds %struct.libxsmm_meqn_arg_shape, ptr %8, i32 0, i32 2
  %46 = load i32, ptr %45, align 4, !tbaa !17
  %47 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 2
  store i32 %46, ptr %47, align 4, !tbaa !13
  %48 = getelementptr inbounds %struct.libxsmm_meqn_arg_metadata, ptr %7, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !18
  %50 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 3
  store i32 %49, ptr %50, align 4, !tbaa !13
  %51 = getelementptr inbounds %struct.libxsmm_meqn_arg_shape, ptr %8, i32 0, i32 3
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 5
  store i32 %52, ptr %53, align 4, !tbaa !13
  %54 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %10, i32 0, i32 7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %54, ptr align 4 %9, i64 16, i1 false), !tbaa.struct !20
  %55 = load i32, ptr %11, align 4, !tbaa !10
  %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 !11
  %59 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = call ptr @libxsmm_meqn_add_node(ptr noundef %60, i32 noundef 8, ptr noundef byval(%union.libxsmm_meqn_info) align 8 %10)
  %62 = load i32, ptr %11, align 4, !tbaa !10
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %65, i32 0, i32 1
  store ptr %61, ptr %66, align 8, !tbaa !13
  %67 = load i32, ptr %11, align 4, !tbaa !10
  call void @libxsmm_meqn_mov_head(i32 noundef %67)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %12, align 4
  br label %68

68:                                               ; preds = %38, %35, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 44, ptr %10) #4
  %69 = load i32, ptr %6, align 4
  ret i32 %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 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, !7, i64 0}
!6 = !{!"libxsmm_meqn_arg_metadata", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"libxsmm_meqn_arg_shape", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!16 = !{!15, !7, i64 4}
!17 = !{!15, !7, i64 8}
!18 = !{!6, !7, i64 4}
!19 = !{!15, !7, i64 12}
!20 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 12, i64 4, !10}


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

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

@libxsmm_matrix_eqns = external dso_local local_unnamed_addr global [4096 x ptr], align 64
@stderr = external local_unnamed_addr global ptr, align 8
@.str.32 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [46 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @libxsmm_meqn_add_node(ptr noundef, i32 noundef, ptr noundef byval(%union.libxsmm_meqn_info) align 8) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_meqn_mov_head(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @libxsmm_meqn_push_back_arg(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4) local_unnamed_addr #2 {
  %6 = alloca %union.libxsmm_meqn_info, align 8
  %.sroa.07.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.28.0.extract.shift = lshr i64 %0, 32
  %.sroa.28.0.extract.trunc = trunc nuw i64 %.sroa.28.0.extract.shift to i32
  %.sroa.05.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.26.0.extract.shift = lshr i64 %1, 32
  %.sroa.26.0.extract.trunc = trunc nuw i64 %.sroa.26.0.extract.shift to i32
  %.sroa.3.8.extract.trunc = trunc i64 %2 to i32
  %.sroa.5.8.extract.shift = lshr i64 %2, 32
  %.sroa.5.8.extract.trunc = trunc nuw i64 %.sroa.5.8.extract.shift to i32
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %6) #3
  %sext = shl i64 %0, 32
  %7 = ashr exact i64 %sext, 32
  %8 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %5
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.32) #4
  br label %32

14:                                               ; preds = %5
  %15 = getelementptr inbounds i8, ptr %9, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.33) #4
  br label %32

21:                                               ; preds = %14
  store i32 %.sroa.05.0.extract.trunc, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %.sroa.26.0.extract.trunc, ptr %22, align 4, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %.sroa.3.8.extract.trunc, ptr %23, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %.sroa.28.0.extract.trunc, ptr %24, align 4, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 %.sroa.5.8.extract.trunc, ptr %25, align 4, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %6, i64 28
  store i64 %3, ptr %26, align 4
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 36
  store i64 %4, ptr %.sroa.2.0..sroa_idx, align 4
  %27 = getelementptr inbounds i8, ptr %9, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = tail call ptr @libxsmm_meqn_add_node(ptr noundef %28, i32 noundef 8, ptr noundef nonnull byval(%union.libxsmm_meqn_info) align 8 %6)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 8
  store ptr %29, ptr %31, align 8, !tbaa !9
  tail call void @libxsmm_meqn_mov_head(i32 noundef %.sroa.07.0.extract.trunc)
  br label %32

32:                                               ; preds = %21, %18, %11
  %.0 = phi i32 [ 1, %11 ], [ 2, %18 ], [ 0, %21 ]
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %6) #3
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }
attributes #4 = { cold 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 = !{!7, !7, i64 0}


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