; 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_op_metadata = type { i32, i32 }
%struct.libxsmm_matrix_eqn = type { ptr, ptr, i32, i32, i32, i32 }
%struct.libxsmm_meqn_unary_op = type { 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: 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_unary_op(i64 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.libxsmm_meqn_op_metadata, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %union.libxsmm_meqn_info, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i64 %0, ptr %6, align 4
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 44, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = getelementptr inbounds %struct.libxsmm_meqn_op_metadata, ptr %6, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %14, ptr %11, align 4, !tbaa !5
  %15 = load i32, ptr %11, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %4
  %21 = load ptr, ptr @stderr, align 8, !tbaa !11
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.32) #3
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %63

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

31:                                               ; preds = %23
  %32 = load ptr, ptr @stderr, align 8, !tbaa !11
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.33) #3
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %63

34:                                               ; preds = %23
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %10, i32 0, i32 0
  store i32 %35, ptr %36, align 4, !tbaa !13
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %10, i32 0, i32 1
  store i32 %37, ptr %38, align 4, !tbaa !13
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 14
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %44

42:                                               ; preds = %34
  %43 = load i32, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42, %41
  %45 = phi i32 [ 1, %41 ], [ %43, %42 ]
  %46 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %10, i32 0, i32 2
  store i32 %45, ptr %46, align 4, !tbaa !13
  %47 = getelementptr inbounds %struct.libxsmm_meqn_op_metadata, ptr %6, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !14
  %49 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %10, i32 0, i32 3
  store i32 %48, ptr %49, align 4, !tbaa !13
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = call ptr @libxsmm_meqn_add_node(ptr noundef %55, i32 noundef 1, ptr noundef byval(%union.libxsmm_meqn_info) align 8 %10)
  %57 = load i32, ptr %11, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.libxsmm_matrix_eqn, ptr %60, i32 0, i32 1
  store ptr %56, ptr %61, align 8, !tbaa !13
  %62 = load i32, ptr %11, align 4, !tbaa !5
  call void @libxsmm_meqn_mov_head(i32 noundef %62)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %63

63:                                               ; preds = %44, %31, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 44, ptr %10) #3
  %64 = load i32, ptr %5, align 4
  ret i32 %64
}

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 = { 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, !6, i64 0}
!10 = !{!"libxsmm_meqn_op_metadata", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !6, i64 4}


; 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_unary_op(i64 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %union.libxsmm_meqn_info, align 8
  %.sroa.0.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.2.0.extract.shift = lshr i64 %0, 32
  %.sroa.2.0.extract.trunc = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %5) #3
  %sext = shl i64 %0, 32
  %6 = ashr exact i64 %sext, 32
  %7 = getelementptr inbounds [4096 x ptr], ptr @libxsmm_matrix_eqns, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

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

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

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

20:                                               ; preds = %13
  store i32 %1, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %3, ptr %21, align 4, !tbaa !9
  %22 = icmp eq i32 %2, 14
  %23 = select i1 %22, i32 1, i32 %2
  %24 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %23, ptr %24, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %.sroa.2.0.extract.trunc, ptr %25, align 4, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %8, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = tail call ptr @libxsmm_meqn_add_node(ptr noundef %27, i32 noundef 1, ptr noundef nonnull byval(%union.libxsmm_meqn_info) align 8 %5)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %28, ptr %30, align 8, !tbaa !9
  tail call void @libxsmm_meqn_mov_head(i32 noundef %.sroa.0.0.extract.trunc)
  br label %31

31:                                               ; preds = %20, %17, %10
  %.0 = phi i32 [ 1, %10 ], [ 2, %17 ], [ 0, %20 ]
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %5) #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,SimplifyCFGPass,TailCallElimPass