; LLVM IR from SOHNE/Dura2D :: src/math/d2MatMN.ll (ZNK7d2MatMN9TransposeEv)

; 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.d2MatMN = type { i32, i32, ptr }
%struct.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; 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: mustprogress uwtable
define dso_local void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  %12 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !12
  call void @_ZN7d2MatMNC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %13, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %16

16:                                               ; preds = %55, %2
  %17 = load i32, ptr %6, align 4, !tbaa !13
  %18 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %58

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %47, %22
  %24 = load i32, ptr %8, align 4, !tbaa !13
  %25 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %54

29:                                               ; preds = %23
  %30 = getelementptr inbounds %struct.d2MatMN, ptr %11, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr %6, align 4, !tbaa !13
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.d2VecN, ptr %31, i64 %33
  %35 = load i32, ptr %8, align 4, !tbaa !13
  %36 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %34, i32 noundef %35)
          to label %37 unwind label %50

37:                                               ; preds = %29
  %38 = load float, ptr %36, align 4, !tbaa !15
  %39 = getelementptr inbounds %struct.d2MatMN, ptr %0, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i32, ptr %8, align 4, !tbaa !13
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.d2VecN, ptr %40, i64 %42
  %44 = load i32, ptr %6, align 4, !tbaa !13
  %45 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %43, i32 noundef %44)
          to label %46 unwind label %50

46:                                               ; preds = %37
  store float %38, ptr %45, align 4, !tbaa !15
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %8, align 4, !tbaa !13
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !13
  br label %23, !llvm.loop !17

50:                                               ; preds = %37, %29
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %9, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  br label %62

54:                                               ; preds = %28
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %6, align 4, !tbaa !13
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !13
  br label %16, !llvm.loop !19

58:                                               ; preds = %21
  store i1 true, ptr %5, align 1
  store i32 1, ptr %7, align 4
  %59 = load i1, ptr %5, align 1
  br i1 %59, label %61, label %60

60:                                               ; preds = %58
  call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #3
  br label %61

61:                                               ; preds = %60, %58
  ret void

62:                                               ; preds = %50
  %63 = load ptr, ptr %9, align 8
  %64 = load i32, ptr %10, align 4
  %65 = insertvalue { ptr, i32 } poison, ptr %63, 0
  %66 = insertvalue { ptr, i32 } %65, i32 %64, 1
  resume { ptr, i32 } %66
}

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2

declare void @_ZN7d2MatMNC1Eii(ptr, i32, i32)

declare void @_ZN7d2MatMND1Ev(ptr)

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


; 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.d2MatMN = type { i32, i32, ptr }
%struct.d2VecN = type { i32, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7d2MatMN9TransposeEv(ptr dead_on_unwind noalias writable sret(%struct.d2MatMN) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %1, align 8, !tbaa !11
  tail call void @_ZN7d2MatMNC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %4, i32 noundef %5)
  %6 = load i32, ptr %1, align 8, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge14

.preheader.lr.ph:                                 ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader, label %._crit_edge14

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %12 = phi i32 [ %16, %._crit_edge ], [ %6, %.preheader.lr.ph ]
  %13 = phi i32 [ %17, %._crit_edge ], [ %10, %.preheader.lr.ph ]
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %15 = trunc nuw nsw i64 %indvars.iv17 to i32
  br label %20

._crit_edge.loopexit:                             ; preds = %30
  %.pre = load i32, ptr %1, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %16 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.preheader ]
  %17 = phi i32 [ %31, %._crit_edge.loopexit ], [ %13, %.preheader ]
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %18 = sext i32 %16 to i64
  %19 = icmp slt i64 %indvars.iv.next18, %18
  br i1 %19, label %.preheader, label %._crit_edge14, !llvm.loop !12

20:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %21 = load ptr, ptr %8, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct.d2VecN, ptr %21, i64 %indvars.iv17
  %23 = trunc nuw nsw i64 %indvars.iv to i32
  %24 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %22, i32 noundef %23)
          to label %25 unwind label %34

25:                                               ; preds = %20
  %26 = load float, ptr %24, align 4, !tbaa !16
  %27 = load ptr, ptr %9, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct.d2VecN, ptr %27, i64 %indvars.iv
  %29 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16) %28, i32 noundef %15)
          to label %30 unwind label %34

30:                                               ; preds = %25
  store float %26, ptr %29, align 4, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %20, label %._crit_edge.loopexit, !llvm.loop !18

34:                                               ; preds = %25, %20
  %35 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN7d2MatMND1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #2
  resume { ptr, i32 } %35

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

declare noundef nonnull align 4 dereferenceable(4) ptr @_ZN6d2VecNixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1

declare void @_ZN7d2MatMNC1Eii(ptr, i32, i32) local_unnamed_addr

declare void @_ZN7d2MatMND1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress 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 = { "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 }

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


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