; LLVM IR from arasgungore/filters-and-fractals :: main (drawBarnsleyFern)

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

%struct.PPMPixel = type { i8, i8, i8 }
%struct.PPMImage = type { i32, i32, ptr }

@GREEN = external dso_local constant %struct.PPMPixel, align 1

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @drawBarnsleyFern(i64 noundef %0, double noundef %1, ptr noundef %2) #3 {
  %4 = alloca i64, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, 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
  store i64 %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %12 = call i64 @time(ptr noundef null) #5
  %13 = trunc i64 %12 to i32
  call void @srand(i32 noundef %13) #5
  br label %14

14:                                               ; preds = %65, %3
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = add i64 %15, -1
  store i64 %16, ptr %4, align 8, !tbaa !5
  %17 = icmp ne i64 %15, 0
  br i1 %17, label %18, label %98

18:                                               ; preds = %14
  %19 = call i32 @rand() #5
  %20 = srem i32 %19, 100
  store i32 %20, ptr %11, align 4, !tbaa !13
  %21 = load i32, ptr %11, align 4, !tbaa !13
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %18
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  %24 = load double, ptr %8, align 8, !tbaa !9
  %25 = fmul double 1.600000e-01, %24
  store double %25, ptr %10, align 8, !tbaa !9
  br label %65

26:                                               ; preds = %18
  %27 = load i32, ptr %11, align 4, !tbaa !13
  %28 = icmp sle i32 %27, 7
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  %30 = load double, ptr %7, align 8, !tbaa !9
  %31 = load double, ptr %8, align 8, !tbaa !9
  %32 = fmul double 2.800000e-01, %31
  %33 = call double @llvm.fmuladd.f64(double -1.500000e-01, double %30, double %32)
  store double %33, ptr %9, align 8, !tbaa !9
  %34 = load double, ptr %7, align 8, !tbaa !9
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = fmul double 2.400000e-01, %35
  %37 = call double @llvm.fmuladd.f64(double 2.600000e-01, double %34, double %36)
  %38 = fadd double %37, 4.400000e-01
  store double %38, ptr %10, align 8, !tbaa !9
  br label %64

39:                                               ; preds = %26
  %40 = load i32, ptr %11, align 4, !tbaa !13
  %41 = icmp sle i32 %40, 15
  br i1 %41, label %42, label %53

42:                                               ; preds = %39
  %43 = load double, ptr %7, align 8, !tbaa !9
  %44 = load double, ptr %8, align 8, !tbaa !9
  %45 = fmul double 2.600000e-01, %44
  %46 = fneg double %45
  %47 = call double @llvm.fmuladd.f64(double 2.000000e-01, double %43, double %46)
  store double %47, ptr %9, align 8, !tbaa !9
  %48 = load double, ptr %7, align 8, !tbaa !9
  %49 = load double, ptr %8, align 8, !tbaa !9
  %50 = fmul double 2.200000e-01, %49
  %51 = call double @llvm.fmuladd.f64(double 2.300000e-01, double %48, double %50)
  %52 = fadd double %51, 1.600000e+00
  store double %52, ptr %10, align 8, !tbaa !9
  br label %63

53:                                               ; preds = %39
  %54 = load double, ptr %7, align 8, !tbaa !9
  %55 = load double, ptr %8, align 8, !tbaa !9
  %56 = fmul double 4.000000e-02, %55
  %57 = call double @llvm.fmuladd.f64(double 8.500000e-01, double %54, double %56)
  store double %57, ptr %9, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = load double, ptr %8, align 8, !tbaa !9
  %60 = fmul double 8.500000e-01, %59
  %61 = call double @llvm.fmuladd.f64(double -4.000000e-02, double %58, double %60)
  %62 = fadd double %61, 1.600000e+00
  store double %62, ptr %10, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %53, %42
  br label %64

64:                                               ; preds = %63, %29
  br label %65

65:                                               ; preds = %64, %23
  %66 = load ptr, ptr %6, align 8, !tbaa !11
  %67 = getelementptr inbounds %struct.PPMImage, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load ptr, ptr %6, align 8, !tbaa !11
  %70 = getelementptr inbounds %struct.PPMImage, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !17
  %72 = load ptr, ptr %6, align 8, !tbaa !11
  %73 = getelementptr inbounds %struct.PPMImage, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !18
  %75 = load double, ptr %5, align 8, !tbaa !9
  %76 = load double, ptr %10, align 8, !tbaa !9
  %77 = fmul double %75, %76
  %78 = call double @llvm.round.f64(double %77)
  %79 = fptosi double %78 to i32
  %80 = sub i32 %74, %79
  %81 = sub i32 %80, 1
  %82 = mul i32 %71, %81
  %83 = load double, ptr %5, align 8, !tbaa !9
  %84 = load double, ptr %9, align 8, !tbaa !9
  %85 = load ptr, ptr %6, align 8, !tbaa !11
  %86 = getelementptr inbounds %struct.PPMImage, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !17
  %88 = uitofp i32 %87 to double
  %89 = fdiv double %88, 2.000000e+00
  %90 = call double @llvm.fmuladd.f64(double %83, double %84, double %89)
  %91 = call double @llvm.round.f64(double %90)
  %92 = fptosi double %91 to i32
  %93 = add i32 %82, %92
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds %struct.PPMPixel, ptr %68, i64 %94
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %95, ptr align 1 @GREEN, i64 3, i1 false), !tbaa.struct !19
  %96 = load double, ptr %9, align 8, !tbaa !9
  store double %96, ptr %7, align 8, !tbaa !9
  %97 = load double, ptr %10, align 8, !tbaa !9
  store double %97, ptr %8, align 8, !tbaa !9
  br label %14, !llvm.loop !21

98:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #4

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #4

; Function Attrs: nounwind
declare i32 @rand() #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !12, i64 8}
!16 = !{!"", !14, i64 0, !14, i64 4, !12, i64 8}
!17 = !{!16, !14, i64 0}
!18 = !{!16, !14, i64 4}
!19 = !{i64 0, i64 1, !20, i64 1, i64 1, !20, i64 2, i64 1, !20}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.PPMPixel = type { i8, i8, i8 }

@GREEN = external dso_local local_unnamed_addr constant %struct.PPMPixel, align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @drawBarnsleyFern(i64 noundef %0, double noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #2 {
  %4 = tail call i64 @time(ptr noundef null) #4
  %5 = trunc i64 %4 to i32
  tail call void @srand(i32 noundef %5) #4
  %.not31 = icmp eq i64 %0, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  br label %8

8:                                                ; preds = %.lr.ph, %37
  %.in = phi i64 [ %0, %.lr.ph ], [ %9, %37 ]
  %.02833 = phi double [ 0.000000e+00, %.lr.ph ], [ %.026, %37 ]
  %.02932 = phi double [ 0.000000e+00, %.lr.ph ], [ %.027, %37 ]
  %9 = add i64 %.in, -1
  %10 = tail call i32 @rand() #4
  %11 = srem i32 %10, 100
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %8
  %14 = fmul double %.02833, 1.600000e-01
  br label %37

15:                                               ; preds = %8
  %16 = icmp slt i32 %11, 8
  br i1 %16, label %17, label %23

17:                                               ; preds = %15
  %18 = fmul double %.02833, 2.800000e-01
  %19 = tail call double @llvm.fmuladd.f64(double %.02932, double -1.500000e-01, double %18)
  %20 = fmul double %.02833, 2.400000e-01
  %21 = tail call double @llvm.fmuladd.f64(double %.02932, double 2.600000e-01, double %20)
  %22 = fadd double %21, 4.400000e-01
  br label %37

23:                                               ; preds = %15
  %24 = icmp ult i32 %11, 16
  br i1 %24, label %25, label %31

25:                                               ; preds = %23
  %26 = fmul double %.02833, -2.600000e-01
  %27 = tail call double @llvm.fmuladd.f64(double %.02932, double 2.000000e-01, double %26)
  %28 = fmul double %.02833, 2.200000e-01
  %29 = tail call double @llvm.fmuladd.f64(double %.02932, double 2.300000e-01, double %28)
  %30 = fadd double %29, 1.600000e+00
  br label %37

31:                                               ; preds = %23
  %32 = fmul double %.02833, 4.000000e-02
  %33 = tail call double @llvm.fmuladd.f64(double %.02932, double 8.500000e-01, double %32)
  %34 = fmul double %.02833, 8.500000e-01
  %35 = tail call double @llvm.fmuladd.f64(double %.02932, double -4.000000e-02, double %34)
  %36 = fadd double %35, 1.600000e+00
  br label %37

37:                                               ; preds = %17, %31, %25, %13
  %.027 = phi double [ 0.000000e+00, %13 ], [ %19, %17 ], [ %27, %25 ], [ %33, %31 ]
  %.026 = phi double [ %14, %13 ], [ %22, %17 ], [ %30, %25 ], [ %36, %31 ]
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %2, align 8, !tbaa !11
  %40 = load i32, ptr %7, align 4, !tbaa !12
  %41 = fmul double %.026, %1
  %42 = tail call double @llvm.round.f64(double %41)
  %43 = fptosi double %42 to i32
  %44 = xor i32 %43, -1
  %45 = add i32 %40, %44
  %46 = mul i32 %45, %39
  %47 = uitofp i32 %39 to double
  %48 = fmul double %47, 5.000000e-01
  %49 = tail call double @llvm.fmuladd.f64(double %1, double %.027, double %48)
  %50 = tail call double @llvm.round.f64(double %49)
  %51 = fptosi double %50 to i32
  %52 = add i32 %46, %51
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct.PPMPixel, ptr %38, i64 %53
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %54, ptr noundef nonnull align 1 dereferenceable(3) @GREEN, i64 3, i1 false), !tbaa.struct !13
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %._crit_edge, label %8, !llvm.loop !15

._crit_edge:                                      ; preds = %37, %3
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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, !10, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{i64 0, i64 1, !14, i64 1, i64 1, !14, i64 2, i64 1, !14}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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