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

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

; 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) #0

; Function Attrs: nounwind uwtable
declare dso_local void @drawSierpinskiUtil1(double noundef, double noundef, double noundef, ptr noundef, i24) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @drawSierpinski(double noundef %0, double noundef %1, double noundef %2, ptr noundef %3, i24 %4) #1 {
  %6 = alloca %struct.PPMPixel, align 1
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i24, align 4
  %12 = alloca i24, align 4
  %13 = alloca i24, align 4
  %14 = alloca i24, align 4
  store i24 %4, ptr %6, align 1
  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 ptr %3, ptr %10, align 8, !tbaa !9
  %15 = load double, ptr %9, align 8, !tbaa !5
  %16 = fcmp olt double %15, 5.000000e+00
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  br label %95

18:                                               ; preds = %5
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.PPMImage, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = sub nsw i32 0, %21
  %23 = sdiv i32 %22, 2
  %24 = sitofp i32 %23 to double
  %25 = load double, ptr %7, align 8, !tbaa !5
  %26 = fcmp olt double %24, %25
  br i1 %26, label %27, label %58

27:                                               ; preds = %18
  %28 = load double, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.PPMImage, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = udiv i32 %31, 2
  %33 = uitofp i32 %32 to double
  %34 = fcmp olt double %28, %33
  br i1 %34, label %35, label %58

35:                                               ; preds = %27
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.PPMImage, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = sub nsw i32 0, %38
  %40 = sdiv i32 %39, 2
  %41 = sitofp i32 %40 to double
  %42 = load double, ptr %8, align 8, !tbaa !5
  %43 = fcmp olt double %41, %42
  br i1 %43, label %44, label %58

44:                                               ; preds = %35
  %45 = load double, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.PPMImage, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !14
  %49 = udiv i32 %48, 2
  %50 = uitofp i32 %49 to double
  %51 = fcmp olt double %45, %50
  br i1 %51, label %52, label %58

52:                                               ; preds = %44
  %53 = load double, ptr %7, align 8, !tbaa !5
  %54 = load double, ptr %8, align 8, !tbaa !5
  %55 = load double, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 1 %6, i64 3, i1 false)
  %57 = load i24, ptr %11, align 4
  call void @drawSierpinskiUtil1(double noundef %53, double noundef %54, double noundef %55, ptr noundef %56, i24 %57)
  br label %58

58:                                               ; preds = %52, %44, %35, %27, %18
  %59 = load double, ptr %7, align 8, !tbaa !5
  %60 = load double, ptr %8, align 8, !tbaa !5
  %61 = load double, ptr %9, align 8, !tbaa !5
  %62 = fmul double 2.000000e+00, %61
  %63 = fdiv double %62, 3.000000e+00
  %64 = fsub double %60, %63
  %65 = load double, ptr %9, align 8, !tbaa !5
  %66 = fdiv double %65, 2.000000e+00
  %67 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 1 %6, i64 3, i1 false)
  %68 = load i24, ptr %12, align 4
  call void @drawSierpinski(double noundef %59, double noundef %64, double noundef %66, ptr noundef %67, i24 %68)
  %69 = load double, ptr %7, align 8, !tbaa !5
  %70 = load double, ptr %9, align 8, !tbaa !5
  %71 = call double @sqrt(double noundef 3.000000e+00) #3
  %72 = fdiv double %70, %71
  %73 = fsub double %69, %72
  %74 = load double, ptr %8, align 8, !tbaa !5
  %75 = load double, ptr %9, align 8, !tbaa !5
  %76 = fdiv double %75, 3.000000e+00
  %77 = fadd double %74, %76
  %78 = load double, ptr %9, align 8, !tbaa !5
  %79 = fdiv double %78, 2.000000e+00
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 1 %6, i64 3, i1 false)
  %81 = load i24, ptr %13, align 4
  call void @drawSierpinski(double noundef %73, double noundef %77, double noundef %79, ptr noundef %80, i24 %81)
  %82 = load double, ptr %7, align 8, !tbaa !5
  %83 = load double, ptr %9, align 8, !tbaa !5
  %84 = call double @sqrt(double noundef 3.000000e+00) #3
  %85 = fdiv double %83, %84
  %86 = fadd double %82, %85
  %87 = load double, ptr %8, align 8, !tbaa !5
  %88 = load double, ptr %9, align 8, !tbaa !5
  %89 = fdiv double %88, 3.000000e+00
  %90 = fadd double %87, %89
  %91 = load double, ptr %9, align 8, !tbaa !5
  %92 = fdiv double %91, 2.000000e+00
  %93 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 1 %6, i64 3, i1 false)
  %94 = load i24, ptr %14, align 4
  call void @drawSierpinski(double noundef %86, double noundef %90, double noundef %92, ptr noundef %93, i24 %94)
  br label %95

95:                                               ; preds = %58, %17
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4, !10, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}


; 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: nounwind uwtable
declare dso_local void @drawSierpinskiUtil1(double noundef, double noundef, double noundef, ptr noundef, i24) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drawSierpinski(double noundef %0, double noundef %1, double noundef %2, ptr noundef %3, i24 %4) local_unnamed_addr #0 {
  %6 = fcmp olt double %2, 5.000000e+00
  br i1 %6, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %3, i64 4
  %8 = insertelement <2 x double> poison, double %1, i64 0
  %9 = insertelement <2 x double> %8, double %0, i64 1
  br label %10

10:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr4247 = phi double [ %2, %.lr.ph ], [ %36, %tailrecurse ]
  %11 = phi <2 x double> [ %9, %.lr.ph ], [ %42, %tailrecurse ]
  %12 = load i32, ptr %3, align 8, !tbaa !5
  %13 = sdiv i32 %12, -2
  %14 = sitofp i32 %13 to double
  %15 = extractelement <2 x double> %11, i64 1
  %16 = fcmp ogt double %15, %14
  br i1 %16, label %17, label %tailrecurse

17:                                               ; preds = %10
  %18 = lshr i32 %12, 1
  %19 = uitofp nneg i32 %18 to double
  %20 = fcmp olt double %15, %19
  br i1 %20, label %21, label %tailrecurse

21:                                               ; preds = %17
  %22 = load i32, ptr %7, align 4, !tbaa !11
  %23 = sdiv i32 %22, -2
  %24 = sitofp i32 %23 to double
  %25 = extractelement <2 x double> %11, i64 0
  %26 = fcmp ogt double %25, %24
  br i1 %26, label %27, label %tailrecurse

27:                                               ; preds = %21
  %28 = lshr i32 %22, 1
  %29 = uitofp nneg i32 %28 to double
  %30 = fcmp olt double %25, %29
  br i1 %30, label %31, label %tailrecurse

31:                                               ; preds = %27
  tail call void @drawSierpinskiUtil1(double noundef %15, double noundef %25, double noundef %.tr4247, ptr noundef nonnull %3, i24 %4)
  br label %tailrecurse

tailrecurse:                                      ; preds = %31, %27, %21, %17, %10
  %32 = fmul double %.tr4247, 2.000000e+00
  %33 = fdiv double %32, 3.000000e+00
  %34 = extractelement <2 x double> %11, i64 0
  %35 = fsub double %34, %33
  %36 = fmul double %.tr4247, 5.000000e-01
  tail call void @drawSierpinski(double noundef %15, double noundef %35, double noundef %36, ptr noundef nonnull %3, i24 %4)
  %37 = insertelement <2 x double> poison, double %.tr4247, i64 0
  %38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = fdiv <2 x double> %38, <double 3.000000e+00, double 0x3FFBB67AE8584CAA>
  %40 = fsub <2 x double> %11, %39
  %41 = extractelement <2 x double> %40, i64 1
  %42 = fadd <2 x double> %11, %39
  %43 = extractelement <2 x double> %42, i64 0
  tail call void @drawSierpinski(double noundef %41, double noundef %43, double noundef %36, ptr noundef nonnull %3, i24 %4)
  %44 = fcmp olt double %36, 5.000000e+00
  br i1 %44, label %tailrecurse._crit_edge, label %10

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  ret void
}

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

!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, !7, i64 0}
!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 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass