; 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: 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 @MatNd_destroy(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @MatNd_transposeSelf(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._MatNd, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %17

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._MatNd, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._MatNd, ptr %13, i32 0, i32 1
  store i32 %12, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._MatNd, ptr %15, i32 0, i32 2
  store i32 1, ptr %16, align 4, !tbaa !13
  br label %126

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._MatNd, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %30

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._MatNd, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._MatNd, ptr %26, i32 0, i32 2
  store i32 %25, ptr %27, align 4, !tbaa !13
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._MatNd, ptr %28, i32 0, i32 1
  store i32 1, ptr %29, align 8, !tbaa !9
  br label %126

30:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._MatNd, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._MatNd, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = mul i32 %33, %36
  %38 = icmp ugt i32 %37, 1296
  br i1 %38, label %39, label %47

39:                                               ; preds = %30
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MatNd, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._MatNd, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !9
  %46 = call ptr @MatNd_create(i32 noundef %42, i32 noundef %45)
  store ptr %46, ptr %3, align 8, !tbaa !5
  br label %97

47:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._MatNd, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._MatNd, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = mul i32 %50, %53
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %47
  br label %65

57:                                               ; preds = %47
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MatNd, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._MatNd, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !9
  %64 = mul i32 %60, %63
  br label %65

65:                                               ; preds = %57, %56
  %66 = phi i32 [ 1, %56 ], [ %64, %57 ]
  store i32 %66, ptr %4, align 4, !tbaa !14
  %67 = load i32, ptr %4, align 4, !tbaa !14
  %68 = zext i32 %67 to i64
  %69 = mul i64 %68, 8
  %70 = add i64 24, %69
  %71 = alloca i8, i64 %70, align 16
  store ptr %71, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._MatNd, ptr %72, i64 1
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._MatNd, ptr %74, i32 0, i32 0
  store ptr %73, ptr %75, align 8, !tbaa !15
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._MatNd, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._MatNd, ptr %79, i32 0, i32 1
  store i32 %78, ptr %80, align 8, !tbaa !9
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._MatNd, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 8, !tbaa !9
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._MatNd, ptr %84, i32 0, i32 2
  store i32 %83, ptr %85, align 4, !tbaa !13
  %86 = load i32, ptr %4, align 4, !tbaa !14
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._MatNd, ptr %87, i32 0, i32 3
  store i32 %86, ptr %88, align 8, !tbaa !16
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._MatNd, ptr %89, i32 0, i32 4
  store i8 1, ptr %90, align 4, !tbaa !17
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._MatNd, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !15
  %94 = load i32, ptr %4, align 4, !tbaa !14
  %95 = zext i32 %94 to i64
  %96 = mul i64 %95, 8
  call void @llvm.memset.p0.i64(ptr align 8 %93, i8 0, i64 %96, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %97

97:                                               ; preds = %65, %39
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  call void @MatNd_transpose(ptr noundef %98, ptr noundef %99)
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct._MatNd, ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 8, !tbaa !9
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct._MatNd, ptr %103, i32 0, i32 1
  store i32 %102, ptr %104, align 8, !tbaa !9
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct._MatNd, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 4, !tbaa !13
  %108 = load ptr, ptr %2, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct._MatNd, ptr %108, i32 0, i32 2
  store i32 %107, ptr %109, align 4, !tbaa !13
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct._MatNd, ptr %110, i32 0, i32 0
  %112 = load ptr, ptr %111, align 8, !tbaa !15
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct._MatNd, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !15
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct._MatNd, ptr %116, i32 0, i32 1
  %118 = load i32, ptr %117, align 8, !tbaa !9
  %119 = load ptr, ptr %3, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct._MatNd, ptr %119, i32 0, i32 2
  %121 = load i32, ptr %120, align 4, !tbaa !13
  %122 = mul i32 %118, %121
  %123 = zext i32 %122 to i64
  %124 = mul i64 %123, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %112, ptr align 8 %115, i64 %124, i1 false)
  %125 = load ptr, ptr %3, align 8, !tbaa !5
  call void @MatNd_destroy(ptr noundef %125)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %126

126:                                              ; preds = %97, %22, %9
  ret void
}

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

; 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_transpose(ptr noundef, ptr noundef) local_unnamed_addr #0

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

7:                                                ; preds = %1
  store i32 %6, ptr %2, align 8, !tbaa !5
  store i32 1, ptr %5, align 4, !tbaa !12
  br label %36

8:                                                ; preds = %1
  %9 = icmp eq i32 %6, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  store i32 %3, ptr %5, align 4, !tbaa !12
  store i32 1, ptr %2, align 8, !tbaa !5
  br label %36

11:                                               ; preds = %8
  %12 = mul i32 %6, %3
  %13 = icmp ugt i32 %12, 1296
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = tail call ptr @MatNd_create(i32 noundef %6, i32 noundef %3)
  br label %26

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

26:                                               ; preds = %16, %14
  %.0 = phi ptr [ %15, %14 ], [ %20, %16 ]
  call void @MatNd_transpose(ptr noundef %.0, ptr noundef nonnull %0)
  %27 = getelementptr inbounds i8, ptr %.0, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !5
  store i32 %28, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.0, i64 12
  %30 = load i32, ptr %29, align 4, !tbaa !12
  store i32 %30, ptr %5, align 4, !tbaa !12
  %31 = load ptr, ptr %0, align 8, !tbaa !13
  %32 = load ptr, ptr %.0, align 8, !tbaa !13
  %33 = mul i32 %30, %28
  %34 = zext i32 %33 to i64
  %35 = shl nuw nsw i64 %34, 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 8 %32, i64 %35, i1 false)
  call void @MatNd_destroy(ptr noundef nonnull %.0)
  br label %36

36:                                               ; preds = %26, %10, %7
  ret void
}

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

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 8}
!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 12}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !11, i64 20}


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