; LLVM IR from sourceryinstitute/MORFEUS-Source :: src/FV/src/mesh_optimize/OptMS (SMmatrix)

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

@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 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

declare i32 @SMerror(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

; 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
define dso_local i32 @SMtransposeMatrix(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %4
  %18 = call i32 @SMerror(i32 noundef 230, ptr noundef @.str.12, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 56, i32 noundef 0, ptr noundef null)
  store i32 %18, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %57

19:                                               ; preds = %4
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  %23 = call i32 @SMerror(i32 noundef 231, ptr noundef @.str.12, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 56, i32 noundef 0, ptr noundef null)
  store i32 %23, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %57

24:                                               ; preds = %19
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %53, %24
  %26 = load i32, ptr %12, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %56

29:                                               ; preds = %25
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %49, %29
  %31 = load i32, ptr %11, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %52

34:                                               ; preds = %30
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = mul nsw i32 %36, %37
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %35, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %45 to i64
  %48 = getelementptr inbounds double, ptr %44, i64 %47
  store double %43, ptr %48, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %34
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !9
  br label %30, !llvm.loop !13

52:                                               ; preds = %30
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %12, align 4, !tbaa !9
  br label %25, !llvm.loop !15

56:                                               ; preds = %25
  store i32 0, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %57

57:                                               ; preds = %56, %22, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %58 = load i32, ptr %5, align 4
  ret i32 %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [18 x i8], align 1

declare i32 @SMerror(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @SMtransposeMatrix(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %.loopexit.sink.split, label %6

6:                                                ; preds = %4
  %7 = icmp eq ptr %3, null
  br i1 %7, label %.loopexit.sink.split, label %.preheader20

.preheader20:                                     ; preds = %6
  %8 = icmp sgt i32 %2, 0
  %9 = icmp sgt i32 %1, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %.preheader.us.preheader, label %.loopexit

.preheader.us.preheader:                          ; preds = %.preheader20
  %10 = zext nneg i32 %1 to i64
  %wide.trip.count34 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %10, 3
  %11 = icmp ult i32 %1, 4
  %unroll_iter = and i64 %10, 2147483644
  %invariant.gep37 = getelementptr i8, ptr %3, i64 8
  %invariant.gep39 = getelementptr i8, ptr %3, i64 16
  %invariant.gep41 = getelementptr i8, ptr %3, i64 24
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv31 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next32, %._crit_edge.us ]
  %.024.us = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next.lcssa, %._crit_edge.us ]
  %sext = shl i64 %.024.us, 32
  %12 = ashr exact i64 %sext, 32
  %invariant.gep = getelementptr inbounds double, ptr %0, i64 %indvars.iv31
  br i1 %11, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv26 = phi i64 [ %indvars.iv.next27.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.new ], [ %12, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %13 = mul nuw nsw i64 %indvars.iv26, %10
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %13
  %14 = load double, ptr %gep, align 8, !tbaa !5
  %15 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  store double %14, ptr %15, align 8, !tbaa !5
  %indvars.iv.next27 = or disjoint i64 %indvars.iv26, 1
  %16 = mul nuw nsw i64 %indvars.iv.next27, %10
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep, i64 %16
  %17 = load double, ptr %gep.1, align 8, !tbaa !5
  %gep38 = getelementptr double, ptr %invariant.gep37, i64 %indvars.iv
  store double %17, ptr %gep38, align 8, !tbaa !5
  %indvars.iv.next27.1 = or disjoint i64 %indvars.iv26, 2
  %18 = mul nuw nsw i64 %indvars.iv.next27.1, %10
  %gep.2 = getelementptr inbounds double, ptr %invariant.gep, i64 %18
  %19 = load double, ptr %gep.2, align 8, !tbaa !5
  %gep40 = getelementptr double, ptr %invariant.gep39, i64 %indvars.iv
  store double %19, ptr %gep40, align 8, !tbaa !5
  %indvars.iv.next27.2 = or disjoint i64 %indvars.iv26, 3
  %20 = mul nuw nsw i64 %indvars.iv.next27.2, %10
  %gep.3 = getelementptr inbounds double, ptr %invariant.gep, i64 %20
  %21 = load double, ptr %gep.3, align 8, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %gep42 = getelementptr double, ptr %invariant.gep41, i64 %indvars.iv
  store double %21, ptr %gep42, align 8, !tbaa !5
  %indvars.iv.next27.3 = add nuw nsw i64 %indvars.iv26, 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 !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.next.lcssa.ph = phi i64 [ poison, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  %indvars.iv26.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next27.3, %.preheader.us.new ]
  %indvars.iv.unr = phi i64 [ %12, %.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.iv26.epil = phi i64 [ %indvars.iv.next27.epil, %.epil.preheader ], [ %indvars.iv26.unr, %._crit_edge.us.unr-lcssa ]
  %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 ]
  %22 = mul nuw nsw i64 %indvars.iv26.epil, %10
  %gep.epil = getelementptr inbounds double, ptr %invariant.gep, i64 %22
  %23 = load double, ptr %gep.epil, align 8, !tbaa !5
  %indvars.iv.next.epil = add nsw i64 %indvars.iv.epil, 1
  %24 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.epil
  store double %23, ptr %24, align 8, !tbaa !5
  %indvars.iv.next27.epil = add nuw nsw i64 %indvars.iv26.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 !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next.lcssa = phi i64 [ %indvars.iv.next.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %indvars.iv.next.epil, %.epil.preheader ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %.loopexit, label %.preheader.us, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %6, %4
  %.sink = phi i32 [ 230, %4 ], [ 231, %6 ]
  %25 = tail call i32 @SMerror(i32 noundef %.sink, ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 56, i32 noundef 0, ptr noundef null) #2
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %.loopexit.sink.split, %.preheader20
  %.016 = phi i32 [ 0, %.preheader20 ], [ %25, %.loopexit.sink.split ], [ 0, %._crit_edge.us ]
  ret i32 %.016
}

attributes #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 = { 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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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