; LLVM IR from shupx/swarm_sync_sim :: src/fw_plane_sim/src/px4_lib/geo (geo)

; 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.crosstrack_error_s = type { i8, float, float }

; 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z29get_distance_to_next_waypointdddd(double noundef, double noundef, double noundef, double noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef, double noundef, double noundef, double noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z20get_distance_to_lineP18crosstrack_error_sdddddd(ptr noundef %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, double noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  %18 = alloca i32, align 4
  %19 = alloca float, align 4
  %20 = alloca float, align 4
  %21 = alloca float, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store double %1, ptr %10, align 8, !tbaa !9
  store double %2, ptr %11, align 8, !tbaa !9
  store double %3, ptr %12, align 8, !tbaa !9
  store double %4, ptr %13, align 8, !tbaa !9
  store double %5, ptr %14, align 8, !tbaa !9
  store double %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 -1, ptr %16, align 4, !tbaa !11
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.crosstrack_error_s, ptr %22, i32 0, i32 0
  store i8 0, ptr %23, align 4, !tbaa !13
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.crosstrack_error_s, ptr %24, i32 0, i32 1
  store float 0.000000e+00, ptr %25, align 4, !tbaa !17
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.crosstrack_error_s, ptr %26, i32 0, i32 2
  store float 0.000000e+00, ptr %27, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %28 = load double, ptr %10, align 8, !tbaa !9
  %29 = load double, ptr %11, align 8, !tbaa !9
  %30 = load double, ptr %14, align 8, !tbaa !9
  %31 = load double, ptr %15, align 8, !tbaa !9
  %32 = call noundef float @_Z29get_distance_to_next_waypointdddd(double noundef %28, double noundef %29, double noundef %30, double noundef %31)
  store float %32, ptr %17, align 4, !tbaa !19
  %33 = load float, ptr %17, align 4, !tbaa !19
  %34 = fcmp olt float %33, 0x3FB99999A0000000
  br i1 %34, label %35, label %36

35:                                               ; preds = %7
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %85

36:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %37 = load double, ptr %10, align 8, !tbaa !9
  %38 = load double, ptr %11, align 8, !tbaa !9
  %39 = load double, ptr %14, align 8, !tbaa !9
  %40 = load double, ptr %15, align 8, !tbaa !9
  %41 = call noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef %37, double noundef %38, double noundef %39, double noundef %40)
  store float %41, ptr %19, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %42 = load double, ptr %12, align 8, !tbaa !9
  %43 = load double, ptr %13, align 8, !tbaa !9
  %44 = load double, ptr %14, align 8, !tbaa !9
  %45 = load double, ptr %15, align 8, !tbaa !9
  %46 = call noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef %42, double noundef %43, double noundef %44, double noundef %45)
  store float %46, ptr %20, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %47 = load float, ptr %20, align 4, !tbaa !19
  %48 = load float, ptr %19, align 4, !tbaa !19
  %49 = fsub float %47, %48
  %50 = call noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef %49)
  store float %50, ptr %21, align 4, !tbaa !19
  %51 = load float, ptr %21, align 4, !tbaa !19
  %52 = fcmp ogt float %51, 0x3FF921FB60000000
  br i1 %52, label %56, label %53

53:                                               ; preds = %36
  %54 = load float, ptr %21, align 4, !tbaa !19
  %55 = fcmp olt float %54, 0xBFF921FB60000000
  br i1 %55, label %56, label %60

56:                                               ; preds = %53, %36
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.crosstrack_error_s, ptr %57, i32 0, i32 0
  store i8 1, ptr %58, align 4, !tbaa !13
  store i32 0, ptr %16, align 4, !tbaa !11
  %59 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %59, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %84

60:                                               ; preds = %53
  %61 = load float, ptr %17, align 4, !tbaa !19
  %62 = load float, ptr %21, align 4, !tbaa !19
  %63 = call float @sinf(float noundef %62) #3
  %64 = fmul float %61, %63
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.crosstrack_error_s, ptr %65, i32 0, i32 1
  store float %64, ptr %66, align 4, !tbaa !17
  %67 = load float, ptr %21, align 4, !tbaa !19
  %68 = call float @sinf(float noundef %67) #3
  %69 = fcmp oge float %68, 0.000000e+00
  br i1 %69, label %70, label %76

70:                                               ; preds = %60
  %71 = load float, ptr %20, align 4, !tbaa !19
  %72 = fsub float %71, 0x3FF921FB60000000
  %73 = call noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef %72)
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.crosstrack_error_s, ptr %74, i32 0, i32 2
  store float %73, ptr %75, align 4, !tbaa !18
  br label %82

76:                                               ; preds = %60
  %77 = load float, ptr %20, align 4, !tbaa !19
  %78 = fadd float %77, 0x3FF921FB60000000
  %79 = call noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef %78)
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.crosstrack_error_s, ptr %80, i32 0, i32 2
  store float %79, ptr %81, align 4, !tbaa !18
  br label %82

82:                                               ; preds = %76, %70
  store i32 0, ptr %16, align 4, !tbaa !11
  %83 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %83, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %84

84:                                               ; preds = %82, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  br label %85

85:                                               ; preds = %84, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %86 = load i32, ptr %8, align 4
  ret i32 %86
}

; Function Attrs: nounwind
declare float @sinf(float noundef) #2

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS18crosstrack_error_s", !15, i64 0, !16, i64 4, !16, i64 8}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!14, !16, i64 4}
!18 = !{!14, !16, i64 8}
!19 = !{!16, !16, 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z29get_distance_to_next_waypointdddd(double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1, 1) i32 @_Z20get_distance_to_lineP18crosstrack_error_sdddddd(ptr nocapture noundef writeonly %0, double noundef %1, double noundef %2, double noundef %3, double noundef %4, double noundef %5, double noundef %6) local_unnamed_addr #0 {
  store i8 0, ptr %0, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store <2 x float> zeroinitializer, ptr %8, align 4, !tbaa !11
  %10 = tail call noundef float @_Z29get_distance_to_next_waypointdddd(double noundef %1, double noundef %2, double noundef %5, double noundef %6)
  %11 = fcmp olt float %10, 0x3FB99999A0000000
  br i1 %11, label %26, label %12

12:                                               ; preds = %7
  %13 = tail call noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef %1, double noundef %2, double noundef %5, double noundef %6)
  %14 = tail call noundef float @_Z28get_bearing_to_next_waypointdddd(double noundef %3, double noundef %4, double noundef %5, double noundef %6)
  %15 = fsub float %14, %13
  %16 = tail call noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef %15)
  %17 = tail call float @llvm.fabs.f32(float %16)
  %or.cond = fcmp ogt float %17, 0x3FF921FB60000000
  br i1 %or.cond, label %18, label %19

18:                                               ; preds = %12
  store i8 1, ptr %0, align 4, !tbaa !5
  br label %26

19:                                               ; preds = %12
  %20 = tail call float @sinf(float noundef %16) #3
  %21 = fmul float %10, %20
  store float %21, ptr %8, align 4, !tbaa !12
  %22 = tail call float @sinf(float noundef %16) #3
  %23 = fcmp ult float %22, 0.000000e+00
  %. = select i1 %23, float 0x3FF921FB60000000, float 0xBFF921FB60000000
  %24 = fadd float %14, %.
  %25 = tail call noundef float @_ZN6matrix7wrap_piIfEET_S1_(float noundef %24)
  store float %25, ptr %9, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %18, %19, %7
  %.1 = phi i32 [ -1, %7 ], [ 0, %19 ], [ 0, %18 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sinf(float noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #2

attributes #0 = { mustprogress 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 #1 = { mustprogress nofree nounwind willreturn memory(write) "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 nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"_ZTS18crosstrack_error_s", !7, i64 0, !10, i64 4, !10, i64 8}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass