; LLVM IR from dmalyuta/FlyARocket_GNC :: la_funcs (transpose)

; 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.MATRIX = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @initMatrix(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8, i64 noundef, i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @transpose(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8 %0, ptr noundef byval(%struct.MATRIX) align 8 %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 1
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 0
  %8 = load i64, ptr %7, align 8, !tbaa !11
  call void @initMatrix(ptr dead_on_unwind writable sret(%struct.MATRIX) align 8 %0, i64 noundef %6, i64 noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %9

9:                                                ; preds = %46, %2
  %10 = load i32, ptr %3, align 4, !tbaa !12
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds %struct.MATRIX, ptr %0, i32 0, i32 0
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i64 %11, %13
  br i1 %14, label %15, label %49

15:                                               ; preds = %9
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %16

16:                                               ; preds = %42, %15
  %17 = load i32, ptr %4, align 4, !tbaa !12
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.MATRIX, ptr %0, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %22, label %45

22:                                               ; preds = %16
  %23 = getelementptr inbounds %struct.MATRIX, ptr %1, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load i32, ptr %3, align 4, !tbaa !12
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds float, ptr %28, i64 %30
  %32 = load float, ptr %31, align 4, !tbaa !16
  %33 = getelementptr inbounds %struct.MATRIX, ptr %0, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %3, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %4, align 4, !tbaa !12
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  store float %32, ptr %41, align 4, !tbaa !16
  br label %42

42:                                               ; preds = %22
  %43 = load i32, ptr %4, align 4, !tbaa !12
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !12
  br label %16, !llvm.loop !18

45:                                               ; preds = %16
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !12
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !12
  br label %9, !llvm.loop !20

49:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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


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

%struct.MATRIX = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @initMatrix(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @transpose(ptr dead_on_unwind noalias writable sret(%struct.MATRIX) align 8 %0, ptr nocapture noundef readonly byval(%struct.MATRIX) align 8 %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = load i64, ptr %1, align 8, !tbaa !11
  tail call void @initMatrix(ptr dead_on_unwind writable sret(%struct.MATRIX) align 8 %0, i64 noundef %4, i64 noundef %5)
  %6 = load i64, ptr %0, align 8, !tbaa !11
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge13, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not14 = icmp eq i64 %8, 0
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8
  br i1 %.not14, label %._crit_edge13, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %8, 3
  %13 = icmp ult i64 %8, 4
  %unroll_iter = and i64 %8, -4
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %14 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv17
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  br i1 %13, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %16 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds float, ptr %17, i64 %indvars.iv17
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = getelementptr inbounds float, ptr %15, i64 %indvars.iv
  store float %19, ptr %20, align 4, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = getelementptr inbounds float, ptr %22, i64 %indvars.iv17
  %24 = load float, ptr %23, align 4, !tbaa !13
  %25 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next
  store float %24, ptr %25, align 4, !tbaa !13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %26 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.1
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds float, ptr %27, i64 %indvars.iv17
  %29 = load float, ptr %28, align 4, !tbaa !13
  %30 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.1
  store float %29, ptr %30, align 4, !tbaa !13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %31 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.2
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds float, ptr %32, i64 %indvars.iv17
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.next.2
  store float %34, ptr %35, align 4, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %36 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.epil
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = getelementptr inbounds float, ptr %37, i64 %indvars.iv17
  %39 = load float, ptr %38, align 4, !tbaa !13
  %40 = getelementptr inbounds float, ptr %15, i64 %indvars.iv.epil
  store float %39, ptr %40, align 4, !tbaa !13
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !17

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %exitcond20.not = icmp eq i64 %indvars.iv.next18, %6
  br i1 %exitcond20.not, label %._crit_edge13, label %.preheader.us, !llvm.loop !19

._crit_edge13:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %2
  ret void
}

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

!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 8}
!6 = !{!"MATRIX", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass