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

; 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 @fmod(double noundef, double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @convertRGBtoHSV(double noundef %0, double noundef %1, double noundef %2) #3 {
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !5
  %11 = load double, ptr %4, align 8, !tbaa !5
  %12 = fdiv double %11, 2.550000e+02
  store double %12, ptr %4, align 8, !tbaa !5
  %13 = load double, ptr %5, align 8, !tbaa !5
  %14 = fdiv double %13, 2.550000e+02
  store double %14, ptr %5, align 8, !tbaa !5
  %15 = load double, ptr %6, align 8, !tbaa !5
  %16 = fdiv double %15, 2.550000e+02
  store double %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = load double, ptr %5, align 8, !tbaa !5
  %19 = fcmp olt double %17, %18
  br i1 %19, label %20, label %30

20:                                               ; preds = %3
  %21 = load double, ptr %5, align 8, !tbaa !5
  %22 = load double, ptr %6, align 8, !tbaa !5
  %23 = fcmp olt double %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = load double, ptr %6, align 8, !tbaa !5
  br label %28

26:                                               ; preds = %20
  %27 = load double, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi double [ %25, %24 ], [ %27, %26 ]
  br label %40

30:                                               ; preds = %3
  %31 = load double, ptr %4, align 8, !tbaa !5
  %32 = load double, ptr %6, align 8, !tbaa !5
  %33 = fcmp olt double %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = load double, ptr %6, align 8, !tbaa !5
  br label %38

36:                                               ; preds = %30
  %37 = load double, ptr %4, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %36, %34
  %39 = phi double [ %35, %34 ], [ %37, %36 ]
  br label %40

40:                                               ; preds = %38, %28
  %41 = phi double [ %29, %28 ], [ %39, %38 ]
  store double %41, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %42 = load double, ptr %4, align 8, !tbaa !5
  %43 = load double, ptr %5, align 8, !tbaa !5
  %44 = fcmp olt double %42, %43
  br i1 %44, label %45, label %55

45:                                               ; preds = %40
  %46 = load double, ptr %4, align 8, !tbaa !5
  %47 = load double, ptr %6, align 8, !tbaa !5
  %48 = fcmp olt double %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %45
  %50 = load double, ptr %4, align 8, !tbaa !5
  br label %53

51:                                               ; preds = %45
  %52 = load double, ptr %6, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %51, %49
  %54 = phi double [ %50, %49 ], [ %52, %51 ]
  br label %65

55:                                               ; preds = %40
  %56 = load double, ptr %5, align 8, !tbaa !5
  %57 = load double, ptr %6, align 8, !tbaa !5
  %58 = fcmp olt double %56, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %55
  %60 = load double, ptr %5, align 8, !tbaa !5
  br label %63

61:                                               ; preds = %55
  %62 = load double, ptr %6, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %61, %59
  %64 = phi double [ %60, %59 ], [ %62, %61 ]
  br label %65

65:                                               ; preds = %63, %53
  %66 = phi double [ %54, %53 ], [ %64, %63 ]
  store double %66, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %67 = load double, ptr %7, align 8, !tbaa !5
  %68 = load double, ptr %8, align 8, !tbaa !5
  %69 = fsub double %67, %68
  store double %69, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %70 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %70, ptr %10, align 8, !tbaa !9
  %71 = load double, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = getelementptr inbounds double, ptr %72, i64 2
  store double %71, ptr %73, align 8, !tbaa !5
  %74 = load double, ptr %7, align 8, !tbaa !5
  %75 = fcmp une double %74, 0.000000e+00
  br i1 %75, label %76, label %82

76:                                               ; preds = %65
  %77 = load double, ptr %9, align 8, !tbaa !5
  %78 = load double, ptr %7, align 8, !tbaa !5
  %79 = fdiv double %77, %78
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = getelementptr inbounds double, ptr %80, i64 1
  store double %79, ptr %81, align 8, !tbaa !5
  br label %85

82:                                               ; preds = %65
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = getelementptr inbounds double, ptr %83, i64 1
  store double 0.000000e+00, ptr %84, align 8, !tbaa !5
  br label %85

85:                                               ; preds = %82, %76
  %86 = load double, ptr %9, align 8, !tbaa !5
  %87 = fcmp oeq double %86, 0.000000e+00
  br i1 %87, label %88, label %91

88:                                               ; preds = %85
  %89 = load ptr, ptr %10, align 8, !tbaa !9
  %90 = getelementptr inbounds double, ptr %89, i64 0
  store double 0.000000e+00, ptr %90, align 8, !tbaa !5
  br label %131

91:                                               ; preds = %85
  %92 = load double, ptr %7, align 8, !tbaa !5
  %93 = load double, ptr %4, align 8, !tbaa !5
  %94 = fcmp oeq double %92, %93
  br i1 %94, label %95, label %105

95:                                               ; preds = %91
  %96 = load double, ptr %5, align 8, !tbaa !5
  %97 = load double, ptr %6, align 8, !tbaa !5
  %98 = fsub double %96, %97
  %99 = load double, ptr %9, align 8, !tbaa !5
  %100 = fdiv double %98, %99
  %101 = call double @fmod(double noundef %100, double noundef 6.000000e+00) #4
  %102 = fmul double 6.000000e+01, %101
  %103 = load ptr, ptr %10, align 8, !tbaa !9
  %104 = getelementptr inbounds double, ptr %103, i64 0
  store double %102, ptr %104, align 8, !tbaa !5
  br label %130

105:                                              ; preds = %91
  %106 = load double, ptr %7, align 8, !tbaa !5
  %107 = load double, ptr %5, align 8, !tbaa !5
  %108 = fcmp oeq double %106, %107
  br i1 %108, label %109, label %119

109:                                              ; preds = %105
  %110 = load double, ptr %6, align 8, !tbaa !5
  %111 = load double, ptr %4, align 8, !tbaa !5
  %112 = fsub double %110, %111
  %113 = load double, ptr %9, align 8, !tbaa !5
  %114 = fdiv double %112, %113
  %115 = fadd double 2.000000e+00, %114
  %116 = fmul double 6.000000e+01, %115
  %117 = load ptr, ptr %10, align 8, !tbaa !9
  %118 = getelementptr inbounds double, ptr %117, i64 0
  store double %116, ptr %118, align 8, !tbaa !5
  br label %129

119:                                              ; preds = %105
  %120 = load double, ptr %4, align 8, !tbaa !5
  %121 = load double, ptr %5, align 8, !tbaa !5
  %122 = fsub double %120, %121
  %123 = load double, ptr %9, align 8, !tbaa !5
  %124 = fdiv double %122, %123
  %125 = fadd double 4.000000e+00, %124
  %126 = fmul double 6.000000e+01, %125
  %127 = load ptr, ptr %10, align 8, !tbaa !9
  %128 = getelementptr inbounds double, ptr %127, i64 0
  store double %126, ptr %128, align 8, !tbaa !5
  br label %129

129:                                              ; preds = %119, %109
  br label %130

130:                                              ; preds = %129, %95
  br label %131

131:                                              ; preds = %130, %88
  %132 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %132
}

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

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


; 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @fmod(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @convertRGBtoHSV(double noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #2 {
  %4 = insertelement <2 x double> poison, double %0, i64 0
  %5 = insertelement <2 x double> %4, double %1, i64 1
  %6 = fdiv <2 x double> %5, <double 2.550000e+02, double 2.550000e+02>
  %7 = fdiv double %2, 2.550000e+02
  %8 = extractelement <2 x double> %6, i64 0
  %9 = extractelement <2 x double> %6, i64 1
  %10 = fcmp olt double %8, %9
  %11 = insertelement <2 x i1> poison, i1 %10, i64 0
  %12 = shufflevector <2 x i1> %11, <2 x i1> poison, <2 x i32> zeroinitializer
  %13 = shufflevector <2 x double> %6, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %14 = select <2 x i1> %12, <2 x double> %6, <2 x double> %13
  %15 = insertelement <2 x double> poison, double %7, i64 0
  %16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
  %17 = fcmp olt <2 x double> %14, %16
  %18 = insertelement <2 x double> %14, double %7, i64 1
  %19 = insertelement <2 x double> %14, double %7, i64 0
  %20 = select <2 x i1> %17, <2 x double> %18, <2 x double> %19
  %21 = extractelement <2 x double> %20, i64 0
  %22 = extractelement <2 x double> %20, i64 1
  %23 = fsub double %22, %21
  %24 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store double %22, ptr %25, align 8, !tbaa !5
  %26 = fcmp une double %22, 0.000000e+00
  %27 = fdiv double %23, %22
  %.sink = select i1 %26, double %27, double 0.000000e+00
  %28 = getelementptr inbounds i8, ptr %24, i64 8
  store double %.sink, ptr %28, align 8
  %29 = fcmp oeq double %23, 0.000000e+00
  br i1 %29, label %49, label %30

30:                                               ; preds = %3
  %31 = fcmp oeq double %22, %8
  br i1 %31, label %32, label %37

32:                                               ; preds = %30
  %33 = fsub double %9, %7
  %34 = fdiv double %33, %23
  %35 = tail call double @fmod(double noundef %34, double noundef 6.000000e+00) #4
  %36 = fmul double %35, 6.000000e+01
  br label %49

37:                                               ; preds = %30
  %38 = fcmp oeq double %22, %9
  br i1 %38, label %39, label %44

39:                                               ; preds = %37
  %40 = fsub double %7, %8
  %41 = fdiv double %40, %23
  %42 = fadd double %41, 2.000000e+00
  %43 = fmul double %42, 6.000000e+01
  br label %49

44:                                               ; preds = %37
  %45 = fsub double %8, %9
  %46 = fdiv double %45, %23
  %47 = fadd double %46, 4.000000e+00
  %48 = fmul double %47, 6.000000e+01
  br label %49

49:                                               ; preds = %3, %32, %44, %39
  %.sink63 = phi double [ %36, %32 ], [ %48, %44 ], [ %43, %39 ], [ 0.000000e+00, %3 ]
  store double %.sink63, ptr %24, align 8, !tbaa !5
  ret ptr %24
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #2 = { mustprogress nofree nounwind willreturn memory(write, inaccessiblemem: readwrite) 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 allocsize(0) }
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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass