; LLVM IR from AlgoGenesis/C :: rst/FractalGenerationrst (mandelbrot)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @generateMandelbrot(double noundef %0, double noundef %1, double noundef %2, double noundef %3) #0 {
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca { double, double }, align 8
  %15 = alloca { double, double }, align 8
  %16 = alloca i32, align 4
  %17 = alloca { double, double }, align 8
  store double %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !5
  store double %2, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %121, %4
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 800
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %124

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %116, %22
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 800
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %119

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %28 = load double, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sitofp i32 %29 to double
  %31 = fdiv double %30, 8.000000e+02
  %32 = load double, ptr %6, align 8, !tbaa !5
  %33 = load double, ptr %5, align 8, !tbaa !5
  %34 = fsub double %32, %33
  %35 = call double @llvm.fmuladd.f64(double %31, double %34, double %28)
  store double %35, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %36 = load double, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = sitofp i32 %37 to double
  %39 = fdiv double %38, 8.000000e+02
  %40 = load double, ptr %8, align 8, !tbaa !5
  %41 = load double, ptr %7, align 8, !tbaa !5
  %42 = fsub double %40, %41
  %43 = call double @llvm.fmuladd.f64(double %39, double %42, double %36)
  store double %43, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  %44 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %45 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double 0.000000e+00, ptr %44, align 8
  store double 0.000000e+00, ptr %45, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %46 = load double, ptr %12, align 8, !tbaa !5
  %47 = load double, ptr %13, align 8, !tbaa !5
  %48 = fmul double %47, 0.000000e+00
  %49 = fmul double %47, 1.000000e+00
  %50 = fadd double %46, %48
  %51 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %52 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  store double %50, ptr %51, align 8
  store double %49, ptr %52, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %103, %27
  %54 = load i32, ptr %16, align 4, !tbaa !9
  %55 = icmp slt i32 %54, 1000
  br i1 %55, label %56, label %106

56:                                               ; preds = %53
  %57 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %58 = load double, ptr %57, align 8
  %59 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %60 = load double, ptr %59, align 8
  %61 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %62 = load double, ptr %61, align 8
  %63 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %64 = load double, ptr %63, align 8
  %65 = fmul double %58, %62
  %66 = fmul double %60, %64
  %67 = fmul double %58, %64
  %68 = fmul double %60, %62
  %69 = fsub double %65, %66
  %70 = fadd double %67, %68
  %71 = fcmp uno double %69, %69
  br i1 %71, label %72, label %78, !prof !11

72:                                               ; preds = %56
  %73 = fcmp uno double %70, %70
  br i1 %73, label %74, label %78, !prof !11

74:                                               ; preds = %72
  %75 = call { double, double } @__muldc3(double noundef %58, double noundef %60, double noundef %62, double noundef %64) #5
  %76 = extractvalue { double, double } %75, 0
  %77 = extractvalue { double, double } %75, 1
  br label %78

78:                                               ; preds = %74, %72, %56
  %79 = phi double [ %69, %56 ], [ %69, %72 ], [ %76, %74 ]
  %80 = phi double [ %70, %56 ], [ %70, %72 ], [ %77, %74 ]
  %81 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %82 = load double, ptr %81, align 8
  %83 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %84 = load double, ptr %83, align 8
  %85 = fadd double %79, %82
  %86 = fadd double %80, %84
  %87 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %88 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double %85, ptr %87, align 8
  store double %86, ptr %88, align 8
  %89 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %90 = load double, ptr %89, align 8
  %91 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %92 = load double, ptr %91, align 8
  %93 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 0
  %94 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 1
  store double %90, ptr %93, align 8
  store double %92, ptr %94, align 8
  %95 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 0
  %96 = load double, ptr %95, align 8
  %97 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 1
  %98 = load double, ptr %97, align 8
  %99 = call double @cabs(double noundef %96, double noundef %98) #5
  %100 = fcmp ogt double %99, 2.000000e+00
  br i1 %100, label %101, label %102

101:                                              ; preds = %78
  br label %106

102:                                              ; preds = %78
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %16, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %16, align 4, !tbaa !9
  br label %53, !llvm.loop !12

106:                                              ; preds = %101, %53
  %107 = load i32, ptr %16, align 4, !tbaa !9
  %108 = icmp slt i32 %107, 1000
  br i1 %108, label %109, label %113

109:                                              ; preds = %106
  %110 = load i32, ptr %16, align 4, !tbaa !9
  %111 = srem i32 %110, 256
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %111)
  br label %115

113:                                              ; preds = %106
  %114 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %115

115:                                              ; preds = %113, %109
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %11, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %11, align 4, !tbaa !9
  br label %23, !llvm.loop !14

119:                                              ; preds = %26
  %120 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %121

121:                                              ; preds = %119
  %122 = load i32, ptr %9, align 4, !tbaa !9
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !15

124:                                              ; preds = %21
  ret void
}

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

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

declare { double, double } @__muldc3(double, double, double, double)

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

declare i32 @printf(ptr noundef, ...) #4

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"branch_weights", i32 1, i32 1048575}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @generateMandelbrot(double noundef %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fsub double %1, %0
  %6 = fsub double %3, %2
  br label %.preheader

.preheader:                                       ; preds = %4, %11
  %.030 = phi i32 [ 0, %4 ], [ %13, %11 ]
  %7 = uitofp nneg i32 %.030 to double
  %8 = fdiv double %7, 8.000000e+02
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %5, double %0)
  br label %14

10:                                               ; preds = %11
  ret void

11:                                               ; preds = %46
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %13 = add nuw nsw i32 %.030, 1
  %exitcond33.not = icmp eq i32 %13, 800
  br i1 %exitcond33.not, label %10, label %.preheader, !llvm.loop !5

14:                                               ; preds = %.preheader, %46
  %.02429 = phi i32 [ 0, %.preheader ], [ %47, %46 ]
  %15 = uitofp nneg i32 %.02429 to double
  %16 = fdiv double %15, 8.000000e+02
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %6, double %2)
  %18 = fmul double %17, 0.000000e+00
  %19 = fadd double %9, %18
  br label %20

20:                                               ; preds = %14, %40
  %.02328 = phi i32 [ 0, %14 ], [ %41, %40 ]
  %.sroa.7.027 = phi double [ 0.000000e+00, %14 ], [ %37, %40 ]
  %.sroa.05.026 = phi double [ 0.000000e+00, %14 ], [ %36, %40 ]
  %21 = fmul double %.sroa.05.026, %.sroa.05.026
  %22 = fmul double %.sroa.7.027, %.sroa.7.027
  %23 = fmul double %.sroa.05.026, %.sroa.7.027
  %24 = fsub double %21, %22
  %25 = fadd double %23, %23
  %26 = fcmp uno double %24, 0.000000e+00
  br i1 %26, label %27, label %33, !prof !7

27:                                               ; preds = %20
  %28 = fcmp uno double %25, 0.000000e+00
  br i1 %28, label %29, label %33, !prof !7

29:                                               ; preds = %27
  %30 = tail call { double, double } @__muldc3(double noundef %.sroa.05.026, double noundef %.sroa.7.027, double noundef %.sroa.05.026, double noundef %.sroa.7.027) #3
  %31 = extractvalue { double, double } %30, 0
  %32 = extractvalue { double, double } %30, 1
  br label %33

33:                                               ; preds = %29, %27, %20
  %34 = phi double [ %24, %20 ], [ %24, %27 ], [ %31, %29 ]
  %35 = phi double [ %25, %20 ], [ %25, %27 ], [ %32, %29 ]
  %36 = fadd double %19, %34
  %37 = fadd double %17, %35
  %38 = tail call double @cabs(double noundef %36, double noundef %37) #3
  %39 = fcmp ogt double %38, 2.000000e+00
  br i1 %39, label %42, label %40

40:                                               ; preds = %33
  %41 = add nuw nsw i32 %.02328, 1
  %exitcond.not = icmp eq i32 %41, 1000
  br i1 %exitcond.not, label %.critedge, label %20, !llvm.loop !8

42:                                               ; preds = %33
  %43 = and i32 %.02328, 255
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %43)
  br label %46

.critedge:                                        ; preds = %40
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %46

46:                                               ; preds = %.critedge, %42
  %47 = add nuw nsw i32 %.02429, 1
  %exitcond32.not = icmp eq i32 %47, 800
  br i1 %exitcond32.not, label %11, label %14, !llvm.loop !9
}

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

declare { double, double } @__muldc3(double, double, double, double) local_unnamed_addr

; Function Attrs: nofree nounwind
declare double @cabs(double noundef, double noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"branch_weights", i32 1, i32 1048575}
!8 = distinct !{!8, !6}
!9 = distinct !{!9, !6}


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