; LLVM IR from gem5/gem5 :: ext/mcpat/cacti/basic_circuit.ll (Z8horowitzddddi)

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

; 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: nounwind
declare double @log(double noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z8horowitzddddi(double noundef %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4) #3 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  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 i32 %4, ptr %11, align 4, !tbaa !9
  %15 = load double, ptr %7, align 8, !tbaa !5
  %16 = fcmp oeq double %15, 0.000000e+00
  br i1 %16, label %17, label %35

17:                                               ; preds = %5
  %18 = load double, ptr %9, align 8, !tbaa !5
  %19 = load double, ptr %10, align 8, !tbaa !5
  %20 = fcmp oeq double %18, %19
  br i1 %20, label %21, label %35

21:                                               ; preds = %17
  %22 = load double, ptr %8, align 8, !tbaa !5
  %23 = load double, ptr %9, align 8, !tbaa !5
  %24 = fcmp olt double %23, 1.000000e+00
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  %26 = load double, ptr %9, align 8, !tbaa !5
  %27 = call double @log(double noundef %26) #4
  %28 = fneg double %27
  br label %32

29:                                               ; preds = %21
  %30 = load double, ptr %9, align 8, !tbaa !5
  %31 = call double @log(double noundef %30) #4
  br label %32

32:                                               ; preds = %29, %25
  %33 = phi double [ %28, %25 ], [ %31, %29 ]
  %34 = fmul double %22, %33
  store double %34, ptr %6, align 8
  br label %92

35:                                               ; preds = %17, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %36 = load double, ptr %7, align 8, !tbaa !5
  %37 = load double, ptr %8, align 8, !tbaa !5
  %38 = fdiv double %36, %37
  store double %38, ptr %12, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %64

41:                                               ; preds = %35
  store double 5.000000e-01, ptr %13, align 8, !tbaa !5
  %42 = load double, ptr %8, align 8, !tbaa !5
  %43 = load double, ptr %9, align 8, !tbaa !5
  %44 = call double @log(double noundef %43) #4
  %45 = load double, ptr %9, align 8, !tbaa !5
  %46 = call double @log(double noundef %45) #4
  %47 = load double, ptr %12, align 8, !tbaa !5
  %48 = fmul double 2.000000e+00, %47
  %49 = load double, ptr %13, align 8, !tbaa !5
  %50 = fmul double %48, %49
  %51 = load double, ptr %9, align 8, !tbaa !5
  %52 = fsub double 1.000000e+00, %51
  %53 = fmul double %50, %52
  %54 = call double @llvm.fmuladd.f64(double %44, double %46, double %53)
  %55 = call double @sqrt(double noundef %54) #4
  %56 = load double, ptr %8, align 8, !tbaa !5
  %57 = load double, ptr %9, align 8, !tbaa !5
  %58 = call double @log(double noundef %57) #4
  %59 = load double, ptr %10, align 8, !tbaa !5
  %60 = call double @log(double noundef %59) #4
  %61 = fsub double %58, %60
  %62 = fmul double %56, %61
  %63 = call double @llvm.fmuladd.f64(double %42, double %55, double %62)
  store double %63, ptr %14, align 8, !tbaa !5
  br label %90

64:                                               ; preds = %35
  store double 4.000000e-01, ptr %13, align 8, !tbaa !5
  %65 = load double, ptr %8, align 8, !tbaa !5
  %66 = load double, ptr %9, align 8, !tbaa !5
  %67 = fsub double 1.000000e+00, %66
  %68 = call double @log(double noundef %67) #4
  %69 = load double, ptr %9, align 8, !tbaa !5
  %70 = fsub double 1.000000e+00, %69
  %71 = call double @log(double noundef %70) #4
  %72 = load double, ptr %12, align 8, !tbaa !5
  %73 = fmul double 2.000000e+00, %72
  %74 = load double, ptr %13, align 8, !tbaa !5
  %75 = fmul double %73, %74
  %76 = load double, ptr %9, align 8, !tbaa !5
  %77 = fmul double %75, %76
  %78 = call double @llvm.fmuladd.f64(double %68, double %71, double %77)
  %79 = call double @sqrt(double noundef %78) #4
  %80 = load double, ptr %8, align 8, !tbaa !5
  %81 = load double, ptr %9, align 8, !tbaa !5
  %82 = fsub double 1.000000e+00, %81
  %83 = call double @log(double noundef %82) #4
  %84 = load double, ptr %10, align 8, !tbaa !5
  %85 = fsub double 1.000000e+00, %84
  %86 = call double @log(double noundef %85) #4
  %87 = fsub double %83, %86
  %88 = fmul double %80, %87
  %89 = call double @llvm.fmuladd.f64(double %65, double %79, double %88)
  store double %89, ptr %14, align 8, !tbaa !5
  br label %90

90:                                               ; preds = %64, %41
  %91 = load double, ptr %14, align 8, !tbaa !5
  store double %91, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %92

92:                                               ; preds = %90, %32
  %93 = load double, ptr %6, align 8
  ret double %93
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !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}


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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write) uwtable
define dso_local noundef double @_Z8horowitzddddi(double noundef %0, double noundef %1, double noundef %2, double noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = fcmp oeq double %0, 0.000000e+00
  %7 = fcmp oeq double %2, %3
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %8, label %14

8:                                                ; preds = %5
  %9 = fcmp olt double %2, 1.000000e+00
  %10 = tail call double @log(double noundef %2) #3
  %11 = fneg double %10
  %12 = select i1 %9, double %11, double %10
  %13 = fmul double %12, %1
  br label %46

14:                                               ; preds = %5
  %15 = fdiv double %0, %1
  %16 = icmp eq i32 %4, 1
  br i1 %16, label %17, label %31

17:                                               ; preds = %14
  %18 = tail call double @log(double noundef %2) #3
  %19 = tail call double @log(double noundef %2) #3
  %20 = fmul double %15, 2.000000e+00
  %21 = fmul double %20, 5.000000e-01
  %22 = fsub double 1.000000e+00, %2
  %23 = fmul double %22, %21
  %24 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %23)
  %25 = tail call double @sqrt(double noundef %24) #3
  %26 = tail call double @log(double noundef %2) #3
  %27 = tail call double @log(double noundef %3) #3
  %28 = fsub double %26, %27
  %29 = fmul double %28, %1
  %30 = tail call double @llvm.fmuladd.f64(double %1, double %25, double %29)
  br label %46

31:                                               ; preds = %14
  %32 = fsub double 1.000000e+00, %2
  %33 = tail call double @log(double noundef %32) #3
  %34 = tail call double @log(double noundef %32) #3
  %35 = fmul double %15, 2.000000e+00
  %36 = fmul double %35, 4.000000e-01
  %37 = fmul double %36, %2
  %38 = tail call double @llvm.fmuladd.f64(double %33, double %34, double %37)
  %39 = tail call double @sqrt(double noundef %38) #3
  %40 = tail call double @log(double noundef %32) #3
  %41 = fsub double 1.000000e+00, %3
  %42 = tail call double @log(double noundef %41) #3
  %43 = fsub double %40, %42
  %44 = fmul double %43, %1
  %45 = tail call double @llvm.fmuladd.f64(double %1, double %39, double %44)
  br label %46

46:                                               ; preds = %17, %31, %8
  %.029 = phi double [ %13, %8 ], [ %30, %17 ], [ %45, %31 ]
  ret double %.029
}

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) 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)"}


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