; LLVM IR from tommasocerruti/algolab-2024 :: src/week04/antenna/solution.ll (Z12ceil_to_longRKN4CORE4ExprE)

; 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.CORE::Expr" = type { %"class.CORE::RCImpl.1" }
%"class.CORE::RCImpl.1" = type { ptr }

declare i32 @__gxx_personality_v0(...)

; 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
define dso_local noundef i64 @_Z12ceil_to_longRKN4CORE4ExprE(ptr noundef nonnull align 8 dereferenceable(8) %0) #1 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca %"class.CORE::Expr", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %"class.CORE::Expr", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call noundef double @_ZN4CGAL9to_doubleIN4CORE4ExprEEENS_22Real_embeddable_traitsIT_E9To_double11result_typeERKS4_(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %10 = call double @llvm.ceil.f64(double %9)
  store double %10, ptr %3, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %17, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %12 = load double, ptr %3, align 8, !tbaa !9
  %13 = fsub double %12, 1.000000e+00
  call void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %4, double noundef %13)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = invoke noundef zeroext i1 @_ZN4COREgeERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %14)
          to label %16 unwind label %20

16:                                               ; preds = %11
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br i1 %15, label %17, label %24

17:                                               ; preds = %16
  %18 = load double, ptr %3, align 8, !tbaa !9
  %19 = fsub double %18, 1.000000e+00
  store double %19, ptr %3, align 8, !tbaa !9
  br label %11, !llvm.loop !11

20:                                               ; preds = %11
  %21 = landingpad { ptr, i32 }
          cleanup
  %22 = extractvalue { ptr, i32 } %21, 0
  store ptr %22, ptr %5, align 8
  %23 = extractvalue { ptr, i32 } %21, 1
  store i32 %23, ptr %6, align 4
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %40

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %30, %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %26 = load double, ptr %3, align 8, !tbaa !9
  call void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %7, double noundef %26)
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = invoke noundef zeroext i1 @_ZN4COREltERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %27)
          to label %29 unwind label %33

29:                                               ; preds = %25
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br i1 %28, label %30, label %37

30:                                               ; preds = %29
  %31 = load double, ptr %3, align 8, !tbaa !9
  %32 = fadd double %31, 1.000000e+00
  store double %32, ptr %3, align 8, !tbaa !9
  br label %25, !llvm.loop !13

33:                                               ; preds = %25
  %34 = landingpad { ptr, i32 }
          cleanup
  %35 = extractvalue { ptr, i32 } %34, 0
  store ptr %35, ptr %5, align 8
  %36 = extractvalue { ptr, i32 } %34, 1
  store i32 %36, ptr %6, align 4
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %40

37:                                               ; preds = %29
  %38 = load double, ptr %3, align 8, !tbaa !9
  %39 = fptosi double %38 to i64
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i64 %39

40:                                               ; preds = %33, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %5, align 8
  %43 = load i32, ptr %6, align 4
  %44 = insertvalue { ptr, i32 } poison, ptr %42, 0
  %45 = insertvalue { ptr, i32 } %44, i32 %43, 1
  resume { ptr, i32 } %45
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN4CGAL9to_doubleIN4CORE4ExprEEENS_22Real_embeddable_traitsIT_E9To_double11result_typeERKS4_(ptr noundef nonnull align 8 dereferenceable(8)) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4COREgeERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8), double noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4COREltERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 = { inlinehint 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 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

%"class.CORE::Expr" = type { %"class.CORE::RCImpl.1" }
%"class.CORE::RCImpl.1" = type { ptr }

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z12ceil_to_longRKN4CORE4ExprE(ptr noundef nonnull align 8 dereferenceable(8) %0) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.CORE::Expr", align 8
  %3 = alloca %"class.CORE::Expr", align 8
  %4 = tail call noundef double @_ZN4CGAL9to_doubleIN4CORE4ExprEEENS_22Real_embeddable_traitsIT_E9To_double11result_typeERKS4_(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %5 = tail call double @llvm.ceil.f64(double %4)
  br label %6

6:                                                ; preds = %9, %1
  %.010 = phi double [ %5, %1 ], [ %7, %9 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %7 = fadd double %.010, -1.000000e+00
  call void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %2, double noundef %7)
  %8 = invoke noundef zeroext i1 @_ZN4COREgeERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %0)
          to label %9 unwind label %10

9:                                                ; preds = %6
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br i1 %8, label %6, label %.preheader, !llvm.loop !5

10:                                               ; preds = %6
  %11 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %20

.preheader:                                       ; preds = %9, %14
  %.1 = phi double [ %15, %14 ], [ %.010, %9 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  call void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %3, double noundef %.1)
  %12 = invoke noundef zeroext i1 @_ZN4COREltERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %0)
          to label %13 unwind label %16

13:                                               ; preds = %.preheader
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br i1 %12, label %14, label %18

14:                                               ; preds = %13
  %15 = fadd double %.1, 1.000000e+00
  br label %.preheader, !llvm.loop !7

16:                                               ; preds = %.preheader
  %17 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %20

18:                                               ; preds = %13
  %19 = fptosi double %.1 to i64
  ret i64 %19

20:                                               ; preds = %16, %10
  %.pn = phi { ptr, i32 } [ %17, %16 ], [ %11, %10 ]
  resume { ptr, i32 } %.pn
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4COREgeERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4CORE4ExprC2Ed(ptr noundef nonnull align 8 dereferenceable(8), double noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4CORE4ExprD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4COREltERKNS_4ExprES2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { inlinehint 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 = { mustprogress 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass