; 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.28 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [63 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_matrix_free(ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_matrix_multiply(ptr noundef byval(%struct.rc_matrix_t) align 8, ptr noundef byval(%struct.rc_matrix_t) align 8, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @rc_matrix_right_multiply_inplace(ptr noundef %0, ptr noundef byval(%struct.rc_matrix_t) align 8 %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca %struct.rc_matrix_t, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #6
  call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 24, i1 false)
  %7 = load ptr, ptr %4, 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
  br i1 %10, label %15, label %11

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

15:                                               ; preds = %11, %2
  %16 = phi i1 [ true, %2 ], [ %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.28) #6
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %54

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

39:                                               ; preds = %26
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str.29) #6
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %54

42:                                               ; preds = %26
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = call i32 @rc_matrix_multiply(ptr noundef byval(%struct.rc_matrix_t) align 8 %43, ptr noundef byval(%struct.rc_matrix_t) align 8 %1, ptr noundef %5)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %42
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.30) #6
  %49 = call i32 @rc_matrix_free(ptr noundef %5)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %54

50:                                               ; preds = %42
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call i32 @rc_matrix_free(ptr noundef %51)
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 8 %5, i64 24, i1 false), !tbaa.struct !14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %54

54:                                               ; preds = %50, %46, %39, %23
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

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


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.28 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [63 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_matrix_free(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_matrix_multiply(ptr noundef byval(%struct.rc_matrix_t) align 8, ptr noundef byval(%struct.rc_matrix_t) align 8, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_matrix_right_multiply_inplace(ptr noundef %0, ptr noundef byval(%struct.rc_matrix_t) align 8 %1) local_unnamed_addr #3 {
  %3 = alloca %struct.rc_matrix_t, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %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 %11, label %14, !prof !11

11:                                               ; preds = %2
  %12 = load ptr, ptr @stderr, align 8, !tbaa !12
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.28) #6
  br label %29

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = load i32, ptr %1, align 8, !tbaa !14
  %.not = icmp eq i32 %16, %17
  br i1 %.not, label %21, label %18, !prof !15

18:                                               ; preds = %14
  %19 = load ptr, ptr @stderr, align 8, !tbaa !12
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.29) #6
  br label %29

21:                                               ; preds = %14
  %22 = call i32 @rc_matrix_multiply(ptr noundef nonnull byval(%struct.rc_matrix_t) align 8 %0, ptr noundef nonnull byval(%struct.rc_matrix_t) align 8 %1, ptr noundef nonnull %3)
  %.not5 = icmp eq i32 %22, 0
  br i1 %.not5, label %27, label %23

23:                                               ; preds = %21
  %24 = load ptr, ptr @stderr, align 8, !tbaa !12
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.30) #6
  %26 = call i32 @rc_matrix_free(ptr noundef nonnull %3)
  br label %29

27:                                               ; preds = %21
  %28 = call i32 @rc_matrix_free(ptr noundef nonnull %0)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %3, i64 24, i1 false), !tbaa.struct !16
  br label %29

29:                                               ; preds = %27, %23, %18, %11
  %.0 = phi i32 [ -1, %11 ], [ -1, %18 ], [ -1, %23 ], [ 0, %27 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !7, i64 0}
!15 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!16 = !{i64 0, i64 4, !17, i64 4, i64 4, !17, i64 8, i64 8, !12, i64 16, i64 4, !17}
!17 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass