; LLVM IR from beagleboard/librobotcontrol :: library/src/math (matrix)

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

@stderr = external global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [57 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; 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 @rc_matrix_zero_out(ptr noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.rc_matrix_t, ptr %7, i32 0, i32 3
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i32 %9, 1
  %11 = xor i1 %10, true
  %12 = xor i1 %11, true
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str.19) #4
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %53

20:                                               ; preds = %1
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %21

21:                                               ; preds = %49, %20
  %22 = load i32, ptr %4, align 4, !tbaa !12
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rc_matrix_t, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp slt i32 %22, %25
  br i1 %26, label %27, label %52

27:                                               ; preds = %21
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %45, %27
  %29 = load i32, ptr %5, align 4, !tbaa !12
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rc_matrix_t, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rc_matrix_t, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load i32, ptr %4, align 4, !tbaa !12
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !12
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %41, i64 %43
  store double 0.000000e+00, ptr %44, align 8, !tbaa !16
  br label %45

45:                                               ; preds = %34
  %46 = load i32, ptr %5, align 4, !tbaa !12
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !12
  br label %28, !llvm.loop !18

48:                                               ; preds = %28
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %4, align 4, !tbaa !12
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !12
  br label %21, !llvm.loop !20

52:                                               ; preds = %21
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %53

53:                                               ; preds = %52, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %54 = load i32, ptr %2, align 4
  ret i32 %54
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind "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 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 #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 16}
!10 = !{!"rc_matrix_t", !11, i64 0, !11, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_matrix_zero_out(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 1
  br i1 %.not, label %.preheader12, label %30, !prof !11

.preheader12:                                     ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !12
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %.preheader12
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader.lr.ph.split.us, label %.loopexit

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = zext nneg i32 %7 to i64
  %12 = shl nuw nsw i64 %11, 3
  %wide.trip.count = zext nneg i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %13 = icmp ult i32 %4, 8
  br i1 %13, label %.loopexit.loopexit.unr-lcssa, label %.preheader.lr.ph.split.us.new

.preheader.lr.ph.split.us.new:                    ; preds = %.preheader.lr.ph.split.us
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.lr.ph.split.us.new
  %indvars.iv = phi i64 [ 0, %.preheader.lr.ph.split.us.new ], [ %indvars.iv.next.7, %.preheader.us ]
  %niter = phi i64 [ 0, %.preheader.lr.ph.split.us.new ], [ %niter.next.7, %.preheader.us ]
  %14 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %15, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %16 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %17, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %18 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %19, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %20 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.2
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %21, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %22 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.3
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %23, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %24 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.4
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %25, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %26 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.5
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %27, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %28 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.next.6
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %29, i8 0, i64 %12, i1 false), !tbaa !16
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.loopexit.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !18

30:                                               ; preds = %1
  %31 = load ptr, ptr @stderr, align 8, !tbaa !15
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.19) #3
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %.preheader.us, %.preheader.lr.ph.split.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %indvars.iv.next.7, %.preheader.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %.loopexit.loopexit.unr-lcssa, %.preheader.us.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.preheader.us.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %33 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv.epil
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  tail call void @llvm.memset.p0.i64(ptr align 8 %34, i8 0, i64 %12, i1 false), !tbaa !16
  %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 %.loopexit, label %.preheader.us.epil, !llvm.loop !20

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.preheader.us.epil, %.preheader.lr.ph, %.preheader12, %30
  %.011 = phi i32 [ -1, %30 ], [ 0, %.preheader12 ], [ 0, %.preheader.lr.ph ], [ 0, %.preheader.us.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  ret i32 %.011
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nofree nounwind "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 = { nofree 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 = { cold 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 16}
!6 = !{!"rc_matrix_t", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !10, i64 8}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}


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