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

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

@stderr = external global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [48 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @rc_kalman_free(ptr noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.rc_kalman_t, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 232, ptr %4) #6
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 232, i1 false)
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %11

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

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.rc_kalman_t, ptr %12, i32 0, i32 0
  %14 = call i32 @rc_matrix_free(ptr noundef %13)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rc_kalman_t, ptr %15, i32 0, i32 1
  %17 = call i32 @rc_matrix_free(ptr noundef %16)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.rc_kalman_t, ptr %18, i32 0, i32 2
  %20 = call i32 @rc_matrix_free(ptr noundef %19)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.rc_kalman_t, ptr %21, i32 0, i32 3
  %23 = call i32 @rc_matrix_free(ptr noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rc_kalman_t, ptr %24, i32 0, i32 4
  %26 = call i32 @rc_matrix_free(ptr noundef %25)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.rc_kalman_t, ptr %27, i32 0, i32 5
  %29 = call i32 @rc_matrix_free(ptr noundef %28)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rc_kalman_t, ptr %30, i32 0, i32 6
  %32 = call i32 @rc_matrix_free(ptr noundef %31)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rc_kalman_t, ptr %33, i32 0, i32 7
  %35 = call i32 @rc_vector_free(ptr noundef %34)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rc_kalman_t, ptr %36, i32 0, i32 8
  %38 = call i32 @rc_vector_free(ptr noundef %37)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %39, ptr align 8 %4, i64 232, i1 false), !tbaa.struct !9
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %40

40:                                               ; preds = %11, %8
  call void @llvm.lifetime.end.p0(i64 232, ptr %4) #6
  %41 = load i32, ptr %2, align 4
  ret i32 %41
}

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

declare i32 @rc_matrix_free(ptr noundef) #4

declare i32 @rc_vector_free(ptr noundef) #4

; 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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 8, !5, i64 16, i64 4, !10, i64 24, i64 4, !10, i64 28, i64 4, !10, i64 32, i64 8, !5, i64 40, i64 4, !10, i64 48, i64 4, !10, i64 52, i64 4, !10, i64 56, i64 8, !5, i64 64, i64 4, !10, i64 72, i64 4, !10, i64 76, i64 4, !10, i64 80, i64 8, !5, i64 88, i64 4, !10, i64 96, i64 4, !10, i64 100, i64 4, !10, i64 104, i64 8, !5, i64 112, i64 4, !10, i64 120, i64 4, !10, i64 124, i64 4, !10, i64 128, i64 8, !5, i64 136, i64 4, !10, i64 144, i64 4, !10, i64 148, i64 4, !10, i64 152, i64 8, !5, i64 160, i64 4, !10, i64 168, i64 4, !10, i64 176, i64 8, !5, i64 184, i64 4, !10, i64 192, i64 4, !10, i64 200, i64 8, !5, i64 208, i64 4, !10, i64 216, i64 4, !10, i64 224, i64 8, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.10 = external hidden unnamed_addr constant [48 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @rc_kalman_free(ptr noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %6

3:                                                ; preds = %1
  %4 = load ptr, ptr @stderr, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.10) #4
  br label %24

6:                                                ; preds = %1
  %7 = tail call i32 @rc_matrix_free(ptr noundef nonnull %0) #5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = tail call i32 @rc_matrix_free(ptr noundef nonnull %8) #5
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = tail call i32 @rc_matrix_free(ptr noundef nonnull %10) #5
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = tail call i32 @rc_matrix_free(ptr noundef nonnull %12) #5
  %14 = getelementptr inbounds i8, ptr %0, i64 96
  %15 = tail call i32 @rc_matrix_free(ptr noundef nonnull %14) #5
  %16 = getelementptr inbounds i8, ptr %0, i64 120
  %17 = tail call i32 @rc_matrix_free(ptr noundef nonnull %16) #5
  %18 = getelementptr inbounds i8, ptr %0, i64 144
  %19 = tail call i32 @rc_matrix_free(ptr noundef nonnull %18) #5
  %20 = getelementptr inbounds i8, ptr %0, i64 168
  %21 = tail call i32 @rc_vector_free(ptr noundef nonnull %20) #5
  %22 = getelementptr inbounds i8, ptr %0, i64 192
  %23 = tail call i32 @rc_vector_free(ptr noundef nonnull %22) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(232) %0, i8 0, i64 232, i1 false)
  br label %24

24:                                               ; preds = %6, %3
  %.0 = phi i32 [ -1, %3 ], [ 0, %6 ]
  ret i32 %.0
}

declare i32 @rc_matrix_free(ptr noundef) local_unnamed_addr #3

declare i32 @rc_vector_free(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 #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 = { "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 = { cold nounwind }
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"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass