; 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.55 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [54 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: nounwind
declare i32 @fprintf(ptr 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 @rc_matrix_symmetrize(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str.55) #3
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %104

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.rc_matrix_t, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.56) #3
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %104

21:                                               ; preds = %13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rc_matrix_t, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.rc_matrix_t, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = icmp ne i32 %24, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %21
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.57) #3
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %104

32:                                               ; preds = %21
  store i32 0, ptr %4, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %100, %32
  %34 = load i32, ptr %4, align 4, !tbaa !14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.rc_matrix_t, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = sub nsw i32 %37, 1
  %39 = icmp slt i32 %34, %38
  br i1 %39, label %40, label %103

40:                                               ; preds = %33
  %41 = load i32, ptr %4, align 4, !tbaa !14
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !14
  br label %43

43:                                               ; preds = %96, %40
  %44 = load i32, ptr %5, align 4, !tbaa !14
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rc_matrix_t, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = icmp slt i32 %44, %47
  br i1 %48, label %49, label %99

49:                                               ; preds = %43
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.rc_matrix_t, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = load i32, ptr %4, align 4, !tbaa !14
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !16
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.rc_matrix_t, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load i32, ptr %5, align 4, !tbaa !14
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !14
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !16
  %72 = fadd double %60, %71
  %73 = fdiv double %72, 2.000000e+00
  store double %73, ptr %6, align 8, !tbaa !16
  %74 = load double, ptr %6, align 8, !tbaa !16
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rc_matrix_t, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load i32, ptr %4, align 4, !tbaa !14
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds ptr, ptr %77, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = load i32, ptr %5, align 4, !tbaa !14
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds double, ptr %81, i64 %83
  store double %74, ptr %84, align 8, !tbaa !16
  %85 = load double, ptr %6, align 8, !tbaa !16
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.rc_matrix_t, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !15
  %89 = load i32, ptr %5, align 4, !tbaa !14
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds ptr, ptr %88, i64 %90
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = load i32, ptr %4, align 4, !tbaa !14
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds double, ptr %92, i64 %94
  store double %85, ptr %95, align 8, !tbaa !16
  br label %96

96:                                               ; preds = %49
  %97 = load i32, ptr %5, align 4, !tbaa !14
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %5, align 4, !tbaa !14
  br label %43, !llvm.loop !18

99:                                               ; preds = %43
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %4, align 4, !tbaa !14
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %4, align 4, !tbaa !14
  br label %33, !llvm.loop !20

103:                                              ; preds = %33
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %104

104:                                              ; preds = %103, %29, %18, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %105 = load i32, ptr %2, align 4
  ret i32 %105
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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 0}
!13 = !{!10, !11, i64 4}
!14 = !{!11, !11, i64 0}
!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.55 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.56 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [54 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_symmetrize(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit29.sink.split, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 1
  br i1 %.not, label %6, label %.loopexit29.sink.split

6:                                                ; preds = %3
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %.not28 = icmp eq i32 %7, %9
  br i1 %.not28, label %.preheader, label %.loopexit29.sink.split

.preheader:                                       ; preds = %6
  %10 = icmp sgt i32 %7, 1
  br i1 %10, label %.lr.ph32, label %.loopexit29

.lr.ph32:                                         ; preds = %.preheader
  %11 = add nsw i32 %7, -1
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = zext nneg i32 %7 to i64
  %wide.trip.count39 = zext nneg i32 %11 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %14

.loopexit:                                        ; preds = %19, %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %.loopexit29, label %14, !llvm.loop !13

14:                                               ; preds = %.lr.ph32, %.loopexit
  %indvars.iv36 = phi i64 [ 0, %.lr.ph32 ], [ %indvars.iv.next37, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph32 ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %15 = icmp ult i64 %indvars.iv.next37, %13
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %14
  %16 = load ptr, ptr %12, align 8, !tbaa !15
  %17 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv36
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv33 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next34, %19 ]
  %20 = getelementptr inbounds double, ptr %18, i64 %indvars.iv33
  %21 = load double, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds ptr, ptr %16, i64 %indvars.iv33
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = getelementptr inbounds double, ptr %23, i64 %indvars.iv36
  %25 = load double, ptr %24, align 8, !tbaa !17
  %26 = fadd double %21, %25
  %27 = fmul double %26, 5.000000e-01
  store double %27, ptr %20, align 8, !tbaa !17
  store double %27, ptr %24, align 8, !tbaa !17
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %19, !llvm.loop !19

.loopexit29.sink.split:                           ; preds = %6, %3, %1
  %.str.57.sink = phi ptr [ @.str.55, %1 ], [ @.str.56, %3 ], [ @.str.57, %6 ]
  %28 = load ptr, ptr @stderr, align 8, !tbaa !16
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull %.str.57.sink) #2
  br label %.loopexit29

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

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 = { 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 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 8}
!16 = !{!10, !10, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !14}


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