; LLVM IR from Yinxiaoli/iros2015_folding :: src/folding_planner/src/distancefield.ll (Z12compareValueR8SSDFGridR9SSDFPointiiii)

; 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.SSDFPoint = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_Z8getPointR8SSDFGridii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #0

; 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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12compareValueR8SSDFGridR9SSDFPointiiii(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.SSDFPoint, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = add nsw i32 %15, %16
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = add nsw i32 %18, %19
  %21 = call { double, double } @_Z8getPointR8SSDFGridii(ptr noundef nonnull align 8 dereferenceable(16) %14, i32 noundef %17, i32 noundef %20)
  %22 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %23 = extractvalue { double, double } %21, 0
  store double %23, ptr %22, align 8
  %24 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %25 = extractvalue { double, double } %21, 1
  store double %25, ptr %24, align 8
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sitofp i32 %26 to double
  %28 = getelementptr inbounds %struct.SSDFPoint, ptr %13, i32 0, i32 0
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = fadd double %29, %27
  store double %30, ptr %28, align 8, !tbaa !11
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = sitofp i32 %31 to double
  %33 = getelementptr inbounds %struct.SSDFPoint, ptr %13, i32 0, i32 1
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = fadd double %34, %32
  store double %35, ptr %33, align 8, !tbaa !14
  %36 = call noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16) %37)
  %39 = fcmp olt double %36, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %6
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !15
  br label %42

42:                                               ; preds = %40, %6
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

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

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS9SSDFPoint", !13, i64 0, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{i64 0, i64 8, !16, i64 8, i64 8, !16}
!16 = !{!13, !13, 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.SSDFPoint = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { double, double } @_Z8getPointR8SSDFGridii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #0

; 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) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12compareValueR8SSDFGridR9SSDFPointiiii(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca %struct.SSDFPoint, align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  %8 = add nsw i32 %4, %2
  %9 = add nsw i32 %5, %3
  %10 = tail call { double, double } @_Z8getPointR8SSDFGridii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %8, i32 noundef %9)
  %11 = extractvalue { double, double } %10, 0
  %12 = extractvalue { double, double } %10, 1
  %13 = insertelement <2 x i32> poison, i32 %4, i64 0
  %14 = insertelement <2 x i32> %13, i32 %5, i64 1
  %15 = sitofp <2 x i32> %14 to <2 x double>
  %16 = insertelement <2 x double> poison, double %11, i64 0
  %17 = insertelement <2 x double> %16, double %12, i64 1
  %18 = fadd <2 x double> %17, %15
  store <2 x double> %18, ptr %7, align 16, !tbaa !5
  %19 = call noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %20 = call noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %21 = fcmp olt double %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 16 dereferenceable(16) %7, i64 16, i1 false), !tbaa.struct !9
  br label %23

23:                                               ; preds = %22, %6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK9SSDFPoint6distSqEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

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

attributes #0 = { mustprogress 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass