; LLVM IR from ADJA/algos :: Other/ExpressionCalc.ll (Z3expv)

; 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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@len = external dso_local global i32, align 4
@p = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z7pr1Signc(i8 noundef signext) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z3expv() #2 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %4 = call noundef double @_Z4termv()
  store double %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %41, %0
  %6 = load i32, ptr @p, align 4, !tbaa !9
  %7 = load i32, ptr @len, align 4, !tbaa !9
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %16

9:                                                ; preds = %5
  %10 = load i32, ptr @p, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %11)
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = call noundef double @_Z7pr1Signc(i8 noundef signext %13)
  %15 = fcmp une double %14, 0.000000e+00
  br label %16

16:                                               ; preds = %9, %5
  %17 = phi i1 [ false, %5 ], [ %15, %9 ]
  br i1 %17, label %18, label %42

18:                                               ; preds = %16
  %19 = load i32, ptr @p, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %20)
  %22 = load i8, ptr %21, align 1, !tbaa !11
  store i8 %22, ptr %3, align 1, !tbaa !11
  %23 = load i32, ptr @p, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @p, align 4, !tbaa !9
  %25 = call noundef double @_Z4termv()
  store double %25, ptr %2, align 8, !tbaa !5
  %26 = load i8, ptr %3, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 45
  br i1 %28, label %29, label %33

29:                                               ; preds = %18
  %30 = load double, ptr %2, align 8, !tbaa !5
  %31 = load double, ptr %1, align 8, !tbaa !5
  %32 = fsub double %31, %30
  store double %32, ptr %1, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %29, %18
  %34 = load i8, ptr %3, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %35, 43
  br i1 %36, label %37, label %41

37:                                               ; preds = %33
  %38 = load double, ptr %2, align 8, !tbaa !5
  %39 = load double, ptr %1, align 8, !tbaa !5
  %40 = fadd double %39, %38
  store double %40, ptr %1, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %37, %33
  br label %5, !llvm.loop !12

42:                                               ; preds = %16
  %43 = load double, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret double %43
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z4termv() #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 = { nocallback nofree nosync 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@len = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z7pr1Signc(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z3expv() local_unnamed_addr #1 {
  %1 = tail call noundef double @_Z4termv()
  %2 = load i32, ptr @p, align 4, !tbaa !5
  %3 = load i32, ptr @len, align 4, !tbaa !5
  %4 = icmp slt i32 %2, %3
  br i1 %4, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0, %11
  %5 = phi i32 [ %23, %11 ], [ %2, %0 ]
  %.07 = phi double [ %.2, %11 ], [ %1, %0 ]
  %6 = sext i32 %5 to i64
  %7 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %6)
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = tail call noundef double @_Z7pr1Signc(i8 noundef signext %8)
  %10 = fcmp une double %9, 0.000000e+00
  br i1 %10, label %11, label %.critedge

11:                                               ; preds = %.lr.ph
  %12 = load i32, ptr @p, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %13)
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = load i32, ptr @p, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @p, align 4, !tbaa !5
  %18 = tail call noundef double @_Z4termv()
  %19 = icmp eq i8 %15, 45
  %20 = fsub double %.07, %18
  %.1 = select i1 %19, double %20, double %.07
  %21 = icmp eq i8 %15, 43
  %22 = fadd double %18, %.1
  %.2 = select i1 %21, double %22, double %.1
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = load i32, ptr @len, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph, %11, %0
  %.0.lcssa = phi double [ %1, %0 ], [ %.2, %11 ], [ %.07, %.lr.ph ]
  ret double %.0.lcssa
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z4termv() local_unnamed_addr #1

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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