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

; 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 @_Z7pr3Signc(i8 noundef signext) #0

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

; Function Attrs: 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 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 @_Z6intermv() #1 {
  %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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  %4 = call noundef double @_Z6factorv()
  store double %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %72, %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 @_Z7pr3Signc(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 %73

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 @_Z6factorv()
  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, 94
  br i1 %28, label %29, label %52

29:                                               ; preds = %18
  %30 = load double, ptr %2, align 8, !tbaa !5
  %31 = fcmp olt double %30, 1.000000e+00
  br i1 %31, label %32, label %47

32:                                               ; preds = %29
  %33 = load double, ptr %2, align 8, !tbaa !5
  %34 = fcmp ogt double %33, -1.000000e+00
  br i1 %34, label %35, label %47

35:                                               ; preds = %32
  %36 = load double, ptr %2, align 8, !tbaa !5
  %37 = fcmp une double %36, 0.000000e+00
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load double, ptr %1, align 8, !tbaa !5
  %40 = fcmp olt double %39, 0.000000e+00
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  %42 = load double, ptr %1, align 8, !tbaa !5
  %43 = fneg double %42
  %44 = load double, ptr %2, align 8, !tbaa !5
  %45 = call double @pow(double noundef %43, double noundef %44) #4
  %46 = fneg double %45
  store double %46, ptr %1, align 8, !tbaa !5
  br label %51

47:                                               ; preds = %38, %35, %32, %29
  %48 = load double, ptr %1, align 8, !tbaa !5
  %49 = load double, ptr %2, align 8, !tbaa !5
  %50 = call double @pow(double noundef %48, double noundef %49) #4
  store double %50, ptr %1, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %47, %41
  br label %52

52:                                               ; preds = %51, %18
  %53 = load i8, ptr %3, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = icmp eq i32 %54, 35
  br i1 %55, label %56, label %72

56:                                               ; preds = %52
  %57 = load double, ptr %2, align 8, !tbaa !5
  %58 = fcmp olt double %57, 0.000000e+00
  br i1 %58, label %59, label %66

59:                                               ; preds = %56
  %60 = load double, ptr %2, align 8, !tbaa !5
  %61 = fneg double %60
  %62 = load double, ptr %1, align 8, !tbaa !5
  %63 = fdiv double 1.000000e+00, %62
  %64 = call double @pow(double noundef %61, double noundef %63) #4
  %65 = fneg double %64
  store double %65, ptr %1, align 8, !tbaa !5
  br label %71

66:                                               ; preds = %56
  %67 = load double, ptr %2, align 8, !tbaa !5
  %68 = load double, ptr %1, align 8, !tbaa !5
  %69 = fdiv double 1.000000e+00, %68
  %70 = call double @pow(double noundef %67, double noundef %69) #4
  store double %70, ptr %1, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %66, %59
  br label %72

72:                                               ; preds = %71, %52
  br label %5, !llvm.loop !12

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

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

; Function Attrs: 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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"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 @_Z7pr3Signc(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z6factorv() local_unnamed_addr #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) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z6intermv() local_unnamed_addr #1 {
  %1 = tail call noundef double @_Z6factorv()
  %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, %.thread
  %5 = phi i32 [ %39, %.thread ], [ %2, %0 ]
  %.023 = phi double [ %.2, %.thread ], [ %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 @_Z7pr3Signc(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 @_Z6factorv()
  switch i8 %15, label %.thread [
    i8 94, label %19
    i8 35, label %29
  ]

19:                                               ; preds = %11
  %20 = tail call double @llvm.fabs.f64(double %18)
  %or.cond = fcmp olt double %20, 1.000000e+00
  %21 = fcmp une double %18, 0.000000e+00
  %or.cond3 = and i1 %21, %or.cond
  %22 = fcmp olt double %.023, 0.000000e+00
  %or.cond5 = select i1 %or.cond3, i1 %22, i1 false
  br i1 %or.cond5, label %23, label %27

23:                                               ; preds = %19
  %24 = fneg double %.023
  %25 = tail call double @pow(double noundef %24, double noundef %18) #4
  %26 = fneg double %25
  br label %.thread

27:                                               ; preds = %19
  %28 = tail call double @pow(double noundef %.023, double noundef %18) #4
  br label %.thread

29:                                               ; preds = %11
  %30 = fcmp olt double %18, 0.000000e+00
  br i1 %30, label %31, label %36

31:                                               ; preds = %29
  %32 = fneg double %18
  %33 = fdiv double 1.000000e+00, %.023
  %34 = tail call double @pow(double noundef %32, double noundef %33) #4
  %35 = fneg double %34
  br label %.thread

36:                                               ; preds = %29
  %37 = fdiv double 1.000000e+00, %.023
  %38 = tail call double @pow(double noundef %18, double noundef %37) #4
  br label %.thread

.thread:                                          ; preds = %11, %27, %23, %31, %36
  %.2 = phi double [ %35, %31 ], [ %38, %36 ], [ %28, %27 ], [ %26, %23 ], [ %.023, %11 ]
  %39 = load i32, ptr @p, align 4, !tbaa !5
  %40 = load i32, ptr @len, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %.lr.ph, label %.critedge, !llvm.loop !10

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 = { 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 = { 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 #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, !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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass