; LLVM IR from moarseniy/CudaFEMproject :: deprecated/Linal2/src/Linal2.ll (ZN6Matrix9transposeEv)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%class.Matrix = type { i32, i32, i8, i8, ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.26 = external hidden unnamed_addr constant [29 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: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix9transposeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %8 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %9, %11
  br i1 %12, label %13, label %85

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

14:                                               ; preds = %80, %13
  %15 = load i32, ptr %4, align 4, !tbaa !14
  %16 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %83

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %76, %20
  %22 = load i32, ptr %6, align 4, !tbaa !14
  %23 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %21
  %28 = load i32, ptr %4, align 4, !tbaa !14
  %29 = load i32, ptr %6, align 4, !tbaa !14
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %31, label %75

31:                                               ; preds = %27
  %32 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i32, ptr %6, align 4, !tbaa !14
  %35 = load i32, ptr %4, align 4, !tbaa !14
  %36 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = mul nsw i32 %35, %37
  %39 = add nsw i32 %34, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %33, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !16
  store float %42, ptr %3, align 4, !tbaa !16
  %43 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i32, ptr %4, align 4, !tbaa !14
  %46 = load i32, ptr %6, align 4, !tbaa !14
  %47 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !13
  %49 = mul nsw i32 %46, %48
  %50 = add nsw i32 %45, %49
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds float, ptr %44, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !16
  %54 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load i32, ptr %6, align 4, !tbaa !14
  %57 = load i32, ptr %4, align 4, !tbaa !14
  %58 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = mul nsw i32 %57, %59
  %61 = add nsw i32 %56, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %55, i64 %62
  store float %53, ptr %63, align 4, !tbaa !16
  %64 = load float, ptr %3, align 4, !tbaa !16
  %65 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load i32, ptr %4, align 4, !tbaa !14
  %68 = load i32, ptr %6, align 4, !tbaa !14
  %69 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !13
  %71 = mul nsw i32 %68, %70
  %72 = add nsw i32 %67, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds float, ptr %66, i64 %73
  store float %64, ptr %74, align 4, !tbaa !16
  br label %75

75:                                               ; preds = %31, %27
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %6, align 4, !tbaa !14
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %6, align 4, !tbaa !14
  br label %21, !llvm.loop !18

79:                                               ; preds = %26
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %4, align 4, !tbaa !14
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %4, align 4, !tbaa !14
  br label %14, !llvm.loop !20

83:                                               ; preds = %19
  %84 = getelementptr inbounds %class.Matrix, ptr %7, i32 0, i32 3
  store i8 1, ptr %84, align 1, !tbaa !21
  br label %88

85:                                               ; preds = %1
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.26)
  %87 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %86, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %88

88:                                               ; preds = %85, %83
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret ptr %7
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #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 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 9, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!10, !12, i64 9}


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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.26 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN6Matrix9transposeEv(ptr noundef nonnull returned align 8 dereferenceable(24) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %0, align 8, !tbaa !12
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %.preheader17, label %30

.preheader17:                                     ; preds = %1
  %6 = icmp sgt i32 %3, 0
  br i1 %6, label %.preheader.us.preheader, label %._crit_edge20

.preheader.us.preheader:                          ; preds = %.preheader17
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = zext nneg i32 %3 to i64
  %xtraiter = and i64 %8, 1
  %9 = icmp eq i32 %3, 1
  %unroll_iter = and i64 %8, 2147483646
  %lcmp.mod.not = icmp ne i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv23 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next24, %._crit_edge.us ]
  %10 = load ptr, ptr %7, align 8
  %11 = mul nuw nsw i64 %indvars.iv23, %8
  %invariant.gep = getelementptr inbounds float, ptr %10, i64 %11
  %invariant.gep28 = getelementptr inbounds float, ptr %10, i64 %indvars.iv23
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %23
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %23 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %23 ], [ 0, %.preheader.us ]
  %12 = icmp ugt i64 %indvars.iv23, %indvars.iv
  br i1 %12, label %13, label %17

13:                                               ; preds = %.preheader.us.new
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %14 = load float, ptr %gep, align 4, !tbaa !13
  %15 = mul nuw nsw i64 %indvars.iv, %8
  %gep29 = getelementptr inbounds float, ptr %invariant.gep28, i64 %15
  %16 = load float, ptr %gep29, align 4, !tbaa !13
  store float %16, ptr %gep, align 4, !tbaa !13
  store float %14, ptr %gep29, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %13, %.preheader.us.new
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = icmp ugt i64 %indvars.iv23, %indvars.iv.next
  br i1 %18, label %19, label %23

19:                                               ; preds = %17
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  %20 = load float, ptr %gep.1, align 4, !tbaa !13
  %21 = mul nuw nsw i64 %indvars.iv.next, %8
  %gep29.1 = getelementptr inbounds float, ptr %invariant.gep28, i64 %21
  %22 = load float, ptr %gep29.1, align 4, !tbaa !13
  store float %22, ptr %gep.1, align 4, !tbaa !13
  store float %20, ptr %gep29.1, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %19, %17
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %23, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %23 ]
  %24 = icmp ugt i64 %indvars.iv23, %indvars.iv.unr
  %or.cond = select i1 %lcmp.mod.not, i1 %24, i1 false
  br i1 %or.cond, label %25, label %._crit_edge.us

25:                                               ; preds = %._crit_edge.us.unr-lcssa
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.unr
  %26 = load float, ptr %gep.epil, align 4, !tbaa !13
  %27 = mul nuw nsw i64 %indvars.iv.unr, %8
  %gep29.epil = getelementptr inbounds float, ptr %invariant.gep28, i64 %27
  %28 = load float, ptr %gep29.epil, align 4, !tbaa !13
  store float %28, ptr %gep.epil, align 4, !tbaa !13
  store float %26, ptr %gep29.epil, align 4, !tbaa !13
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %25, %._crit_edge.us.unr-lcssa
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %8
  br i1 %exitcond27.not, label %._crit_edge20, label %.preheader.us, !llvm.loop !17

._crit_edge20:                                    ; preds = %._crit_edge.us, %.preheader17
  %29 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 1, ptr %29, align 1, !tbaa !18
  br label %33

30:                                               ; preds = %1
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.26)
  %32 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %31, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %33

33:                                               ; preds = %30, %._crit_edge20
  ret ptr %0
}

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

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


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