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

@stderr = external global ptr, align 8
@.str.43 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [56 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

declare double @__vectorized_mult_accumulate(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @rc_matrix_times_col_vec(ptr noundef byval(%struct.rc_matrix_t) align 8 %0, ptr noundef byval(%struct.rc_vector_t) align 8 %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %8 = getelementptr inbounds %struct.rc_matrix_t, ptr %0, i32 0, i32 3
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp ne i32 %9, 1
  br i1 %10, label %15, label %11

11:                                               ; preds = %3
  %12 = getelementptr inbounds %struct.rc_vector_t, ptr %1, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = icmp ne i32 %13, 1
  br label %15

15:                                               ; preds = %11, %3
  %16 = phi i1 [ true, %3 ], [ %14, %11 ]
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 0)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %15
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.43) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %7, align 4
  br label %84

26:                                               ; preds = %15
  %27 = getelementptr inbounds %struct.rc_matrix_t, ptr %0, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = getelementptr inbounds %struct.rc_vector_t, ptr %1, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = icmp ne i32 %28, %30
  %32 = xor i1 %31, true
  %33 = xor i1 %32, true
  %34 = zext i1 %33 to i32
  %35 = sext i32 %34 to i64
  %36 = call i64 @llvm.expect.i64(i64 %35, i64 0)
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %26
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.44) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %7, align 4
  br label %84

41:                                               ; preds = %26
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.rc_matrix_t, ptr %0, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = call i32 @rc_vector_alloc(ptr noundef %42, i32 noundef %44)
  %46 = icmp ne i32 %45, 0
  %47 = xor i1 %46, true
  %48 = xor i1 %47, true
  %49 = zext i1 %48 to i32
  %50 = sext i32 %49 to i64
  %51 = call i64 @llvm.expect.i64(i64 %50, i64 0)
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %41
  %54 = load ptr, ptr @stderr, align 8, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.45) #5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %7, align 4
  br label %84

56:                                               ; preds = %41
  store i32 0, ptr %6, align 4, !tbaa !17
  br label %57

57:                                               ; preds = %80, %56
  %58 = load i32, ptr %6, align 4, !tbaa !17
  %59 = getelementptr inbounds %struct.rc_matrix_t, ptr %0, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !16
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %62, label %83

62:                                               ; preds = %57
  %63 = getelementptr inbounds %struct.rc_matrix_t, ptr %0, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !18
  %65 = load i32, ptr %6, align 4, !tbaa !17
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rc_vector_t, ptr %1, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !19
  %71 = getelementptr inbounds %struct.rc_vector_t, ptr %1, i32 0, i32 0
  %72 = load i32, ptr %71, align 8, !tbaa !15
  %73 = call double @__vectorized_mult_accumulate(ptr noundef %68, ptr noundef %70, i32 noundef %72)
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.rc_vector_t, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !19
  %77 = load i32, ptr %6, align 4, !tbaa !17
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %76, i64 %78
  store double %73, ptr %79, align 8, !tbaa !20
  br label %80

80:                                               ; preds = %62
  %81 = load i32, ptr %6, align 4, !tbaa !17
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %6, align 4, !tbaa !17
  br label %57, !llvm.loop !22

83:                                               ; preds = %57
  store i32 0, ptr %4, align 4
  store i32 1, ptr %7, align 4
  br label %84

84:                                               ; preds = %83, %53, %38, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %85 = load i32, ptr %4, align 4
  ret i32 %85
}

declare i32 @rc_vector_alloc(ptr noundef, i32 noundef) #3

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 = { "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 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 #5 = { 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 = !{!13, !11, i64 16}
!13 = !{!"rc_vector_t", !11, i64 0, !6, i64 8, !11, i64 16}
!14 = !{!10, !11, i64 4}
!15 = !{!13, !11, i64 0}
!16 = !{!10, !11, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !6, i64 8}
!19 = !{!13, !6, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.43 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [56 x i8], align 1

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

declare double @__vectorized_mult_accumulate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_matrix_times_col_vec(ptr nocapture noundef readonly byval(%struct.rc_matrix_t) align 8 %0, ptr nocapture noundef readonly byval(%struct.rc_vector_t) align 8 %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp ne i32 %5, 1
  %7 = getelementptr inbounds i8, ptr %1, i64 16
  %8 = load i32, ptr %7, align 8
  %9 = icmp ne i32 %8, 1
  %10 = select i1 %6, i1 true, i1 %9, !prof !11
  br i1 %10, label %.loopexit.sink.split, label %11, !prof !11

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = load i32, ptr %1, align 8, !tbaa !13
  %.not = icmp eq i32 %13, %14
  br i1 %.not, label %15, label %.loopexit.sink.split, !prof !15

15:                                               ; preds = %11
  %16 = load i32, ptr %0, align 8, !tbaa !16
  %17 = tail call i32 @rc_vector_alloc(ptr noundef %2, i32 noundef %16) #3
  %.not7 = icmp eq i32 %17, 0
  br i1 %.not7, label %.preheader, label %.loopexit.sink.split, !prof !15

.preheader:                                       ; preds = %15
  %18 = icmp sgt i32 %16, 0
  br i1 %18, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %2, i64 8
  %wide.trip.count = zext nneg i32 %16 to i64
  br label %24

24:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %25 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = tail call double @__vectorized_mult_accumulate(ptr noundef %26, ptr noundef %22, i32 noundef %13) #3
  %28 = load ptr, ptr %23, align 8, !tbaa !18
  %29 = getelementptr inbounds double, ptr %28, i64 %indvars.iv
  store double %27, ptr %29, align 8, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %24, !llvm.loop !22

.loopexit.sink.split:                             ; preds = %15, %11, %3
  %.str.45.sink = phi ptr [ @.str.43, %3 ], [ @.str.44, %11 ], [ @.str.45, %15 ]
  %30 = load ptr, ptr @stderr, align 8, !tbaa !19
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull %.str.45.sink) #4
  br label %.loopexit

.loopexit:                                        ; preds = %24, %.loopexit.sink.split, %.preheader
  %.06 = phi i32 [ 0, %.preheader ], [ -1, %.loopexit.sink.split ], [ 0, %24 ]
  ret i32 %.06
}

declare i32 @rc_vector_alloc(ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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 }
attributes #4 = { 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 1, i32 2000}
!12 = !{!6, !7, i64 4}
!13 = !{!14, !7, i64 0}
!14 = !{!"rc_vector_t", !7, i64 0, !10, i64 8, !7, i64 16}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !10, i64 8}
!18 = !{!14, !10, i64 8}
!19 = !{!10, !10, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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