; LLVM IR from HRI-EU/Rcs :: src/RcsCore (Rcs_MatNd)

; 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._MatNd = type { ptr, i32, i32, i32, i8 }

; 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 uwtable
declare dso_local ptr @MatNd_create(i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_destroy(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_insertColumns(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._MatNd, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._MatNd, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = mul i32 %15, %18
  %20 = icmp ugt i32 %19, 1296
  br i1 %20, label %21, label %29

21:                                               ; preds = %5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._MatNd, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._MatNd, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = call ptr @MatNd_create(i32 noundef %24, i32 noundef %27)
  store ptr %28, ptr %11, align 8, !tbaa !5
  br label %79

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._MatNd, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._MatNd, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = mul i32 %32, %35
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %29
  br label %47

39:                                               ; preds = %29
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MatNd, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._MatNd, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !14
  %46 = mul i32 %42, %45
  br label %47

47:                                               ; preds = %39, %38
  %48 = phi i32 [ 1, %38 ], [ %46, %39 ]
  store i32 %48, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %12, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = mul i64 %50, 8
  %52 = add i64 24, %51
  %53 = alloca i8, i64 %52, align 16
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._MatNd, ptr %54, i64 1
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._MatNd, ptr %56, i32 0, i32 0
  store ptr %55, ptr %57, align 8, !tbaa !15
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MatNd, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._MatNd, ptr %61, i32 0, i32 1
  store i32 %60, ptr %62, align 8, !tbaa !14
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._MatNd, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !14
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._MatNd, ptr %66, i32 0, i32 2
  store i32 %65, ptr %67, align 4, !tbaa !11
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._MatNd, ptr %69, i32 0, i32 3
  store i32 %68, ptr %70, align 8, !tbaa !16
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._MatNd, ptr %71, i32 0, i32 4
  store i8 1, ptr %72, align 4, !tbaa !17
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._MatNd, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !15
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = mul i64 %77, 8
  call void @llvm.memset.p0.i64(ptr align 8 %75, i8 0, i64 %78, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %79

79:                                               ; preds = %47, %21
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  call void @MatNd_transpose(ptr noundef %80, ptr noundef %81)
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @MatNd_transposeSelf(ptr noundef %82)
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = load i32, ptr %10, align 4, !tbaa !9
  call void @MatNd_insertRows(ptr noundef %83, i32 noundef %84, ptr noundef %85, i32 noundef %86, i32 noundef %87)
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  call void @MatNd_transposeSelf(ptr noundef %88)
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  call void @MatNd_destroy(ptr noundef %89)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_transpose(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @MatNd_transposeSelf(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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, !10, i64 12}
!12 = !{!"_MatNd", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !13, i64 20}


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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_insertColumns(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %2, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = mul i32 %9, %7
  %11 = icmp ugt i32 %10, 1296
  br i1 %11, label %12, label %14

12:                                               ; preds = %5
  %13 = tail call ptr @MatNd_create(i32 noundef %7, i32 noundef %9)
  br label %24

14:                                               ; preds = %5
  %spec.select = tail call i32 @llvm.umax.i32(i32 %10, i32 1)
  %15 = shl nuw nsw i32 %spec.select, 3
  %16 = zext nneg i32 %15 to i64
  %17 = add nuw nsw i64 %16, 24
  %18 = alloca i8, i64 %17, align 16
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  store ptr %19, ptr %18, align 16, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  store i32 %7, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %18, i64 12
  store i32 %9, ptr %21, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %18, i64 16
  store i32 %spec.select, ptr %22, align 16, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %18, i64 20
  store i8 1, ptr %23, align 4, !tbaa !15
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %19, i8 0, i64 %16, i1 false)
  br label %24

24:                                               ; preds = %14, %12
  %.0 = phi ptr [ %13, %12 ], [ %18, %14 ]
  call void @MatNd_transpose(ptr noundef %.0, ptr noundef nonnull %2)
  call void @MatNd_transposeSelf(ptr noundef %0)
  call void @MatNd_insertRows(ptr noundef %0, i32 noundef %1, ptr noundef %.0, i32 noundef %3, i32 noundef %4)
  call void @MatNd_transposeSelf(ptr noundef %0)
  call void @MatNd_destroy(ptr noundef %.0)
  ret void
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 12}
!6 = !{!"_MatNd", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !11, i64 20}


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