; LLVM IR from Ahmed-alkharusi/Interesting-problems- :: mandelbrot set (C++ wtih Python plots)/mandelbrot set/Source.ll (Z5julia7ComplexRKS_RKj)

; 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.Complex = type { double, double }

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

declare void @_ZN7ComplexC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1

; 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 i32 @_Z5julia7ComplexRKS_RKj(double %0, double %1, ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca %class.Complex, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %class.Complex, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca %class.Complex, align 8
  %13 = alloca %class.Complex, align 8
  %14 = alloca double, align 8
  %15 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  store double %0, ptr %15, align 8
  %16 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  store double %1, ptr %16, align 8
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  call void @_ZN7ComplexC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %9, double noundef 0.000000e+00, double noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %53, %4
  %18 = load i64, ptr %10, align 8, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 2, ptr %11, align 4
  br label %56

24:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  %25 = call { double, double } @_ZN7ComplexmlERKS_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %6)
  %26 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %27 = extractvalue { double, double } %25, 0
  store double %27, ptr %26, align 8
  %28 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %29 = extractvalue { double, double } %25, 1
  store double %29, ptr %28, align 8
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call { double, double } @_ZN7ComplexplERKS_(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 8 dereferenceable(16) %30)
  %32 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %33 = extractvalue { double, double } %31, 0
  store double %33, ptr %32, align 8
  %34 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %35 = extractvalue { double, double } %31, 1
  store double %35, ptr %34, align 8
  %36 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(16) %12)
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  %37 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %38 = call noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %39 = call noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %40 = call noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %41 = call noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %42 = fmul double %40, %41
  %43 = call double @llvm.fmuladd.f64(double %38, double %39, double %42)
  store double %43, ptr %14, align 8, !tbaa !13
  %44 = load double, ptr %14, align 8, !tbaa !13
  %45 = fcmp oge double %44, 4.000000e+00
  br i1 %45, label %46, label %49

46:                                               ; preds = %24
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %50

49:                                               ; preds = %24
  store i32 0, ptr %11, align 4
  br label %50

50:                                               ; preds = %49, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %51 = load i32, ptr %11, align 4
  switch i32 %51, label %56 [
    i32 0, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %10, align 8, !tbaa !9
  br label %17, !llvm.loop !15

56:                                               ; preds = %50, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %57 = load i32, ptr %11, align 4
  switch i32 %57, label %59 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %59

59:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  %60 = load i32, ptr %5, align 4
  ret i32 %60
}

declare { double, double } @_ZN7ComplexmlERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

declare { double, double } @_ZN7ComplexplERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1

declare noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16)) #1

declare noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16)) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.Complex = type { double, double }

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

declare void @_ZN7ComplexC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #1

; 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 i32 @_Z5julia7ComplexRKS_RKj(double %0, double %1, ptr noundef nonnull align 8 dereferenceable(16) %2, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %3) local_unnamed_addr #2 {
  %5 = alloca %class.Complex, align 8
  %6 = alloca %class.Complex, align 8
  %7 = alloca %class.Complex, align 8
  %8 = alloca %class.Complex, align 8
  store double %0, ptr %5, align 8
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store double %1, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @_ZN7ComplexC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %6, double noundef 0.000000e+00, double noundef 0.000000e+00)
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %.not14.not = icmp eq i32 %10, 0
  br i1 %.not14.not, label %.split.loop.exit, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  %12 = getelementptr inbounds i8, ptr %7, i64 8
  br label %13

13:                                               ; preds = %.lr.ph, %29
  %.01115 = phi i64 [ 0, %.lr.ph ], [ %30, %29 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #4
  %14 = call { double, double } @_ZN7ComplexmlERKS_(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %5)
  %15 = extractvalue { double, double } %14, 0
  store double %15, ptr %8, align 8
  %16 = extractvalue { double, double } %14, 1
  store double %16, ptr %11, align 8
  %17 = call { double, double } @_ZN7ComplexplERKS_(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(16) %2)
  %18 = extractvalue { double, double } %17, 0
  store double %18, ptr %7, align 8
  %19 = extractvalue { double, double } %17, 1
  store double %19, ptr %12, align 8
  %20 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %7)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %6)
  %22 = call noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %23 = call noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %24 = call noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %25 = call noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %26 = fmul double %24, %25
  %27 = call double @llvm.fmuladd.f64(double %22, double %23, double %26)
  %28 = fcmp ult double %27, 4.000000e+00
  br i1 %28, label %29, label %.split.loop.exit12

29:                                               ; preds = %13
  %30 = add nuw nsw i64 %.01115, 1
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %.not = icmp ult i64 %30, %32
  br i1 %.not, label %13, label %.split.loop.exit, !llvm.loop !9

.split.loop.exit12:                               ; preds = %13
  %33 = trunc nuw i64 %.01115 to i32
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %29, %4, %.split.loop.exit12
  %spec.select = phi i32 [ %33, %.split.loop.exit12 ], [ 0, %4 ], [ 0, %29 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  ret i32 %spec.select
}

declare { double, double } @_ZN7ComplexmlERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

declare { double, double } @_ZN7ComplexplERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZN7ComplexaSERKS_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

declare noundef double @_ZN7Complex2reEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

declare noundef double @_ZN7Complex2imEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass