; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (geodist)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @geodist(double noundef %0, double noundef %1, double noundef %2, double noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.SPoint_, align 8
  %13 = alloca %struct.SPoint_, align 8
  %14 = alloca i32, align 4
  store double %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !5
  store double %2, ptr %9, align 8, !tbaa !5
  store double %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  %15 = load double, ptr %7, align 8, !tbaa !5
  %16 = fcmp olt double %15, -9.000000e+01
  br i1 %16, label %26, label %17

17:                                               ; preds = %5
  %18 = load double, ptr %7, align 8, !tbaa !5
  %19 = fcmp ogt double %18, 9.000000e+01
  br i1 %19, label %26, label %20

20:                                               ; preds = %17
  %21 = load double, ptr %9, align 8, !tbaa !5
  %22 = fcmp olt double %21, -9.000000e+01
  br i1 %22, label %26, label %23

23:                                               ; preds = %20
  %24 = load double, ptr %9, align 8, !tbaa !5
  %25 = fcmp ogt double %24, 9.000000e+01
  br i1 %25, label %26, label %27

26:                                               ; preds = %23, %20, %17, %5
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %70

27:                                               ; preds = %23
  %28 = load double, ptr %8, align 8, !tbaa !5
  %29 = fcmp olt double %28, -1.800000e+02
  br i1 %29, label %39, label %30

30:                                               ; preds = %27
  %31 = load double, ptr %8, align 8, !tbaa !5
  %32 = fcmp ogt double %31, 1.800000e+02
  br i1 %32, label %39, label %33

33:                                               ; preds = %30
  %34 = load double, ptr %10, align 8, !tbaa !5
  %35 = fcmp olt double %34, -1.800000e+02
  br i1 %35, label %39, label %36

36:                                               ; preds = %33
  %37 = load double, ptr %10, align 8, !tbaa !5
  %38 = fcmp ogt double %37, 1.800000e+02
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33, %30, %27
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %70

40:                                               ; preds = %36
  %41 = getelementptr inbounds %struct.SPoint_, ptr %12, i32 0, i32 0
  store double 0x40AAE02147AE147B, ptr %41, align 8, !tbaa !11
  %42 = load double, ptr %8, align 8, !tbaa !5
  %43 = fmul double %42, 2.000000e+00
  %44 = fmul double %43, 3.141590e+00
  %45 = fdiv double %44, 3.600000e+02
  %46 = fmul double -1.000000e+00, %45
  %47 = getelementptr inbounds %struct.SPoint_, ptr %12, i32 0, i32 1
  store double %46, ptr %47, align 8, !tbaa !13
  %48 = load double, ptr %7, align 8, !tbaa !5
  %49 = fmul double -1.000000e+00, %48
  %50 = fmul double %49, 2.000000e+00
  %51 = fmul double %50, 3.141590e+00
  %52 = fdiv double %51, 3.600000e+02
  %53 = fadd double %52, 0x3FF921F9F01B866E
  %54 = getelementptr inbounds %struct.SPoint_, ptr %12, i32 0, i32 2
  store double %53, ptr %54, align 8, !tbaa !14
  %55 = getelementptr inbounds %struct.SPoint_, ptr %13, i32 0, i32 0
  store double 0x40AAE02147AE147B, ptr %55, align 8, !tbaa !11
  %56 = load double, ptr %10, align 8, !tbaa !5
  %57 = fmul double %56, 2.000000e+00
  %58 = fmul double %57, 3.141590e+00
  %59 = fdiv double %58, 3.600000e+02
  %60 = fmul double -1.000000e+00, %59
  %61 = getelementptr inbounds %struct.SPoint_, ptr %13, i32 0, i32 1
  store double %60, ptr %61, align 8, !tbaa !13
  %62 = load double, ptr %9, align 8, !tbaa !5
  %63 = fmul double -1.000000e+00, %62
  %64 = fmul double %63, 2.000000e+00
  %65 = fmul double %64, 3.141590e+00
  %66 = fdiv double %65, 3.600000e+02
  %67 = fadd double %66, 0x3FF921F9F01B866E
  %68 = getelementptr inbounds %struct.SPoint_, ptr %13, i32 0, i32 2
  store double %67, ptr %68, align 8, !tbaa !14
  %69 = load ptr, ptr %11, align 8, !tbaa !9
  call void @arclen(ptr noundef byval(%struct.SPoint_) align 8 %12, ptr noundef byval(%struct.SPoint_) align 8 %13, ptr noundef %69)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %70

70:                                               ; preds = %40, %39, %26
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #3
  %71 = load i32, ptr %6, align 4
  ret i32 %71
}

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

declare void @arclen(ptr noundef byval(%struct.SPoint_) align 8, ptr noundef byval(%struct.SPoint_) align 8, ptr noundef) #2

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

attributes #0 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"SPoint_", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @geodist(double noundef %0, double noundef %1, double noundef %2, double noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.SPoint_, align 8
  %7 = alloca %struct.SPoint_, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #4
  %8 = tail call double @llvm.fabs.f64(double %0)
  %or.cond = fcmp ogt double %8, 9.000000e+01
  %9 = fcmp olt double %2, -9.000000e+01
  %or.cond3 = or i1 %or.cond, %9
  %10 = fcmp ogt double %2, 9.000000e+01
  %or.cond5 = or i1 %10, %or.cond3
  br i1 %or.cond5, label %34, label %11

11:                                               ; preds = %5
  %12 = tail call double @llvm.fabs.f64(double %1)
  %or.cond7 = fcmp ogt double %12, 1.800000e+02
  %13 = fcmp olt double %3, -1.800000e+02
  %or.cond9 = or i1 %or.cond7, %13
  %14 = fcmp ogt double %3, 1.800000e+02
  %or.cond11 = or i1 %14, %or.cond9
  br i1 %or.cond11, label %34, label %15

15:                                               ; preds = %11
  store double 0x40AAE02147AE147B, ptr %6, align 8, !tbaa !5
  %16 = fmul double %1, 2.000000e+00
  %17 = fmul double %16, 3.141590e+00
  %18 = fdiv double %17, -3.600000e+02
  %19 = getelementptr inbounds i8, ptr %6, i64 8
  store double %18, ptr %19, align 8, !tbaa !10
  %20 = fmul double %0, 2.000000e+00
  %21 = fmul double %20, 3.141590e+00
  %22 = fdiv double %21, 3.600000e+02
  %23 = fsub double 0x3FF921F9F01B866E, %22
  %24 = getelementptr inbounds i8, ptr %6, i64 16
  store double %23, ptr %24, align 8, !tbaa !11
  store double 0x40AAE02147AE147B, ptr %7, align 8, !tbaa !5
  %25 = fmul double %3, 2.000000e+00
  %26 = fmul double %25, 3.141590e+00
  %27 = fdiv double %26, -3.600000e+02
  %28 = getelementptr inbounds i8, ptr %7, i64 8
  store double %27, ptr %28, align 8, !tbaa !10
  %29 = fmul double %2, 2.000000e+00
  %30 = fmul double %29, 3.141590e+00
  %31 = fdiv double %30, 3.600000e+02
  %32 = fsub double 0x3FF921F9F01B866E, %31
  %33 = getelementptr inbounds i8, ptr %7, i64 16
  store double %32, ptr %33, align 8, !tbaa !11
  tail call void @arclen(ptr noundef nonnull byval(%struct.SPoint_) align 8 %6, ptr noundef nonnull byval(%struct.SPoint_) align 8 %7, ptr noundef %4) #4
  br label %34

34:                                               ; preds = %11, %5, %15
  %.0 = phi i32 [ 0, %15 ], [ -1, %5 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  ret i32 %.0
}

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

declare void @arclen(ptr noundef byval(%struct.SPoint_) align 8, ptr noundef byval(%struct.SPoint_) align 8, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"SPoint_", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}


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