; LLVM IR from ImperialCollegeLondon/pnflow :: src/pnm/pnflow/polygon/polygonDrain.ll (ZNK7Polygon19Pc_pistonType_DrainEd)

; 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"

%class.Polygon = type { %class.VoidElem, i32, %"class.std::vector.16", ptr, ptr, i16, i8, double }
%class.VoidElem = type { %class.ElemModel, double, double, double, double }
%class.ElemModel = type { ptr, double, double, ptr, ptr, double, ptr, i8, i8, i8, i8, i32, double, double, double, double, double, double, double, %"struct.std::pair", %"struct.std::pair" }
%"struct.std::pair" = type { double, double }
%"class.std::vector.16" = type { %"struct.std::_Vector_base.17" }
%"struct.std::_Vector_base.17" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZN9ElemModel2PIE = external constant double, align 8

; 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 double @_ZNK7GNMData7sigmaOWEv(ptr noundef nonnull align 8 dereferenceable(984)) #1 align 2

; Function Attrs: nounwind
declare double @cos(double noundef) #2

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

; Function Attrs: nounwind
declare double @sin(double noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7Polygon19Pc_pistonType_DrainEd(ptr noundef nonnull align 8 dereferenceable(248) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %59, %2
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = getelementptr inbounds %class.Polygon, ptr %8, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %62

15:                                               ; preds = %9
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = load double, ptr @_ZN9ElemModel2PIE, align 8, !tbaa !9
  %18 = fdiv double %17, 2.000000e+00
  %19 = getelementptr inbounds %class.Polygon, ptr %8, i32 0, i32 2
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef %21) #5
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = fsub double %18, %23
  %25 = fcmp olt double %16, %24
  br i1 %25, label %26, label %58

26:                                               ; preds = %15
  %27 = load double, ptr %4, align 8, !tbaa !9
  %28 = call double @cos(double noundef %27) #5
  %29 = load double, ptr %4, align 8, !tbaa !9
  %30 = getelementptr inbounds %class.Polygon, ptr %8, i32 0, i32 2
  %31 = load i32, ptr %6, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #5
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fadd double %29, %34
  %36 = call double @cos(double noundef %35) #5
  %37 = fmul double %28, %36
  %38 = getelementptr inbounds %class.Polygon, ptr %8, i32 0, i32 2
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40) #5
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = call double @sin(double noundef %42) #5
  %44 = fdiv double %37, %43
  %45 = load double, ptr @_ZN9ElemModel2PIE, align 8, !tbaa !9
  %46 = fdiv double %45, 2.000000e+00
  %47 = load double, ptr %4, align 8, !tbaa !9
  %48 = fsub double %46, %47
  %49 = getelementptr inbounds %class.Polygon, ptr %8, i32 0, i32 2
  %50 = load i32, ptr %6, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %49, i64 noundef %51) #5
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = fsub double %48, %53
  %55 = fsub double %44, %54
  %56 = load double, ptr %5, align 8, !tbaa !9
  %57 = fadd double %56, %55
  store double %57, ptr %5, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %26, %15
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %6, align 4, !tbaa !11
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !11
  br label %9, !llvm.loop !24

62:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %63 = getelementptr inbounds %class.VoidElem, ptr %8, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !26
  %65 = fmul double 4.000000e+00, %64
  %66 = load double, ptr %5, align 8, !tbaa !9
  %67 = fmul double %65, %66
  %68 = load double, ptr %4, align 8, !tbaa !9
  %69 = call double @cos(double noundef %68) #5
  %70 = load double, ptr %4, align 8, !tbaa !9
  %71 = call double @cos(double noundef %70) #5
  %72 = fmul double %69, %71
  %73 = fdiv double %67, %72
  %74 = fsub double 1.000000e+00, %73
  %75 = call double @sqrt(double noundef %74) #5
  %76 = fadd double 1.000000e+00, %75
  %77 = load double, ptr @_ZN9ElemModel2PIE, align 8, !tbaa !9
  %78 = getelementptr inbounds %class.VoidElem, ptr %8, i32 0, i32 1
  %79 = load double, ptr %78, align 8, !tbaa !26
  %80 = fmul double %77, %79
  %81 = call double @sqrt(double noundef %80) #5
  %82 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %81, double 1.000000e+00)
  %83 = fdiv double %76, %82
  store double %83, ptr %7, align 8, !tbaa !9
  %84 = getelementptr inbounds %class.ElemModel, ptr %8, i32 0, i32 4
  %85 = load ptr, ptr %84, align 8, !tbaa !27
  %86 = call noundef double @_ZNK7GNMData7sigmaOWEv(ptr noundef nonnull align 8 dereferenceable(984) %85)
  %87 = load double, ptr @_ZN9ElemModel2PIE, align 8, !tbaa !9
  %88 = getelementptr inbounds %class.VoidElem, ptr %8, i32 0, i32 1
  %89 = load double, ptr %88, align 8, !tbaa !26
  %90 = fmul double %87, %89
  %91 = call double @sqrt(double noundef %90) #5
  %92 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %91, double 1.000000e+00)
  %93 = load double, ptr %4, align 8, !tbaa !9
  %94 = call double @cos(double noundef %93) #5
  %95 = fmul double %92, %94
  %96 = load double, ptr %7, align 8, !tbaa !9
  %97 = fmul double %95, %96
  %98 = fmul double %86, %97
  %99 = getelementptr inbounds %class.ElemModel, ptr %8, i32 0, i32 5
  %100 = load double, ptr %99, align 8, !tbaa !28
  %101 = fdiv double %98, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret double %101
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #4 align 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 184}
!14 = !{!"_ZTS7Polygon", !15, i64 0, !12, i64 184, !19, i64 192, !6, i64 216, !6, i64 224, !23, i64 232, !7, i64 234, !10, i64 240}
!15 = !{!"_ZTS8VoidElem", !16, i64 0, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176}
!16 = !{!"_ZTS9ElemModel", !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !17, i64 56, !17, i64 57, !17, i64 58, !17, i64 59, !12, i64 60, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !18, i64 120, !18, i64 136}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSSt4pairIddE", !10, i64 0, !10, i64 8}
!19 = !{!"_ZTSSt6vectorIdSaIdEE", !20, i64 0}
!20 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !22, i64 0}
!22 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!23 = !{!"short", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!15, !10, i64 152}
!27 = !{!16, !6, i64 32}
!28 = !{!16, !10, i64 40}


; 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"

@_ZN9ElemModel2PIE = external local_unnamed_addr constant double, align 8

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7Polygon19Pc_pistonType_DrainEd(ptr noundef nonnull align 8 dereferenceable(248) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 184
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  %.pre = load double, ptr @_ZN9ElemModel2PIE, align 8, !tbaa !21
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %6 = fmul double %.pre, 5.000000e-01
  %7 = getelementptr inbounds i8, ptr %0, i64 192
  %8 = fsub double %6, %1
  br label %39

._crit_edge:                                      ; preds = %60, %2
  %.0.lcssa = phi double [ 0.000000e+00, %2 ], [ %.1, %60 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 152
  %10 = load double, ptr %9, align 8, !tbaa !22
  %11 = fmul double %10, 4.000000e+00
  %12 = fmul double %.0.lcssa, %11
  %13 = tail call double @cos(double noundef %1) #4
  %14 = tail call double @cos(double noundef %1) #4
  %15 = fmul double %13, %14
  %16 = fdiv double %12, %15
  %17 = fsub double 1.000000e+00, %16
  %18 = tail call double @sqrt(double noundef %17) #4
  %19 = fadd double %18, 1.000000e+00
  %20 = load double, ptr %9, align 8, !tbaa !22
  %21 = fmul double %.pre, %20
  %22 = tail call double @sqrt(double noundef %21) #4
  %23 = tail call double @llvm.fmuladd.f64(double %22, double 2.000000e+00, double 1.000000e+00)
  %24 = fdiv double %19, %23
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !23
  %27 = tail call noundef double @_ZNK7GNMData7sigmaOWEv(ptr noundef nonnull align 8 dereferenceable(984) %26)
  %28 = load double, ptr %9, align 8, !tbaa !22
  %29 = fmul double %.pre, %28
  %30 = tail call double @sqrt(double noundef %29) #4
  %31 = tail call double @llvm.fmuladd.f64(double %30, double 2.000000e+00, double 1.000000e+00)
  %32 = tail call double @cos(double noundef %1) #4
  %33 = fmul double %31, %32
  %34 = fmul double %24, %33
  %35 = fmul double %27, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 40
  %37 = load double, ptr %36, align 8, !tbaa !24
  %38 = fdiv double %35, %37
  ret double %38

39:                                               ; preds = %.lr.ph, %60
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %60 ]
  %.019 = phi double [ 0.000000e+00, %.lr.ph ], [ %.1, %60 ]
  %40 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %indvars.iv) #4
  %41 = load double, ptr %40, align 8, !tbaa !21
  %42 = fsub double %6, %41
  %43 = fcmp ogt double %42, %1
  br i1 %43, label %44, label %60

44:                                               ; preds = %39
  %45 = tail call double @cos(double noundef %1) #4
  %46 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %indvars.iv) #4
  %47 = load double, ptr %46, align 8, !tbaa !21
  %48 = fadd double %47, %1
  %49 = tail call double @cos(double noundef %48) #4
  %50 = fmul double %45, %49
  %51 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %indvars.iv) #4
  %52 = load double, ptr %51, align 8, !tbaa !21
  %53 = tail call double @sin(double noundef %52) #4
  %54 = fdiv double %50, %53
  %55 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %indvars.iv) #4
  %56 = load double, ptr %55, align 8, !tbaa !21
  %57 = fsub double %8, %56
  %58 = fsub double %54, %57
  %59 = fadd double %.019, %58
  br label %60

60:                                               ; preds = %39, %44
  %.1 = phi double [ %59, %44 ], [ %.019, %39 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %61 = load i32, ptr %3, align 8, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = icmp slt i64 %indvars.iv.next, %62
  br i1 %63, label %39, label %._crit_edge, !llvm.loop !25
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3 align 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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, !14, i64 184}
!6 = !{!"_ZTS7Polygon", !7, i64 0, !14, i64 184, !16, i64 192, !12, i64 216, !12, i64 224, !20, i64 232, !10, i64 234, !9, i64 240}
!7 = !{!"_ZTS8VoidElem", !8, i64 0, !9, i64 152, !9, i64 160, !9, i64 168, !9, i64 176}
!8 = !{!"_ZTS9ElemModel", !9, i64 8, !9, i64 16, !12, i64 24, !12, i64 32, !9, i64 40, !12, i64 48, !13, i64 56, !13, i64 57, !13, i64 58, !13, i64 59, !14, i64 60, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !15, i64 120, !15, i64 136}
!9 = !{!"double", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"any pointer", !10, i64 0}
!13 = !{!"bool", !10, i64 0}
!14 = !{!"int", !10, i64 0}
!15 = !{!"_ZTSSt4pairIddE", !9, i64 0, !9, i64 8}
!16 = !{!"_ZTSSt6vectorIdSaIdEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!20 = !{!"short", !10, i64 0}
!21 = !{!9, !9, i64 0}
!22 = !{!7, !9, i64 152}
!23 = !{!8, !12, i64 32}
!24 = !{!8, !9, i64 40}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass