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

; 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 uwtable
define dso_local ptr @convertHSVtoRGB(double noundef %0, double noundef %1, double noundef %2) #2 {
  %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
  %11 = alloca i16, align 2
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %12 = load double, ptr %6, align 8, !tbaa !5
  %13 = load double, ptr %5, align 8, !tbaa !5
  %14 = fmul double %12, %13
  store double %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %15 = load double, ptr %7, align 8, !tbaa !5
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = fdiv double %16, 6.000000e+01
  %18 = call double @fmod(double noundef %17, double noundef 2.000000e+00) #5
  %19 = fsub double %18, 1.000000e+00
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = fsub double 1.000000e+00, %20
  %22 = fmul double %15, %21
  store double %22, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %23 = load double, ptr %6, align 8, !tbaa !5
  %24 = load double, ptr %7, align 8, !tbaa !5
  %25 = fsub double %23, %24
  store double %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %26 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %26, ptr %10, align 8, !tbaa !9
  %27 = load double, ptr %4, align 8, !tbaa !5
  %28 = fcmp olt double %27, 6.000000e+01
  br i1 %28, label %29, label %38

29:                                               ; preds = %3
  %30 = load double, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds double, ptr %31, i64 0
  store double %30, ptr %32, align 8, !tbaa !5
  %33 = load double, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !9
  %35 = getelementptr inbounds double, ptr %34, i64 1
  store double %33, ptr %35, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds double, ptr %36, i64 2
  store double 0.000000e+00, ptr %37, align 8, !tbaa !5
  br label %99

38:                                               ; preds = %3
  %39 = load double, ptr %4, align 8, !tbaa !5
  %40 = fcmp olt double %39, 1.200000e+02
  br i1 %40, label %41, label %50

41:                                               ; preds = %38
  %42 = load double, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %10, align 8, !tbaa !9
  %44 = getelementptr inbounds double, ptr %43, i64 0
  store double %42, ptr %44, align 8, !tbaa !5
  %45 = load double, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = getelementptr inbounds double, ptr %46, i64 1
  store double %45, ptr %47, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds double, ptr %48, i64 2
  store double 0.000000e+00, ptr %49, align 8, !tbaa !5
  br label %98

50:                                               ; preds = %38
  %51 = load double, ptr %4, align 8, !tbaa !5
  %52 = fcmp olt double %51, 1.800000e+02
  br i1 %52, label %53, label %62

53:                                               ; preds = %50
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = getelementptr inbounds double, ptr %54, i64 0
  store double 0.000000e+00, ptr %55, align 8, !tbaa !5
  %56 = load double, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !9
  %58 = getelementptr inbounds double, ptr %57, i64 1
  store double %56, ptr %58, align 8, !tbaa !5
  %59 = load double, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  %61 = getelementptr inbounds double, ptr %60, i64 2
  store double %59, ptr %61, align 8, !tbaa !5
  br label %97

62:                                               ; preds = %50
  %63 = load double, ptr %4, align 8, !tbaa !5
  %64 = fcmp olt double %63, 2.400000e+02
  br i1 %64, label %65, label %74

65:                                               ; preds = %62
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  %67 = getelementptr inbounds double, ptr %66, i64 0
  store double 0.000000e+00, ptr %67, align 8, !tbaa !5
  %68 = load double, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = getelementptr inbounds double, ptr %69, i64 1
  store double %68, ptr %70, align 8, !tbaa !5
  %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
  br label %96

74:                                               ; preds = %62
  %75 = load double, ptr %4, align 8, !tbaa !5
  %76 = fcmp olt double %75, 3.000000e+02
  br i1 %76, label %77, label %86

77:                                               ; preds = %74
  %78 = load double, ptr %8, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = getelementptr inbounds double, ptr %79, i64 0
  store double %78, ptr %80, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  %82 = getelementptr inbounds double, ptr %81, i64 1
  store double 0.000000e+00, ptr %82, align 8, !tbaa !5
  %83 = load double, ptr %7, align 8, !tbaa !5
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = getelementptr inbounds double, ptr %84, i64 2
  store double %83, ptr %85, align 8, !tbaa !5
  br label %95

86:                                               ; preds = %74
  %87 = load double, ptr %7, align 8, !tbaa !5
  %88 = load ptr, ptr %10, align 8, !tbaa !9
  %89 = getelementptr inbounds double, ptr %88, i64 0
  store double %87, ptr %89, align 8, !tbaa !5
  %90 = load ptr, ptr %10, align 8, !tbaa !9
  %91 = getelementptr inbounds double, ptr %90, i64 1
  store double 0.000000e+00, ptr %91, align 8, !tbaa !5
  %92 = load double, ptr %8, align 8, !tbaa !5
  %93 = load ptr, ptr %10, align 8, !tbaa !9
  %94 = getelementptr inbounds double, ptr %93, i64 2
  store double %92, ptr %94, align 8, !tbaa !5
  br label %95

95:                                               ; preds = %86, %77
  br label %96

96:                                               ; preds = %95, %65
  br label %97

97:                                               ; preds = %96, %53
  br label %98

98:                                               ; preds = %97, %41
  br label %99

99:                                               ; preds = %98, %29
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #5
  store i16 0, ptr %11, align 2, !tbaa !11
  br label %100

100:                                              ; preds = %117, %99
  %101 = load i16, ptr %11, align 2, !tbaa !11
  %102 = zext i16 %101 to i32
  %103 = icmp slt i32 %102, 3
  br i1 %103, label %104, label %120

104:                                              ; preds = %100
  %105 = load ptr, ptr %10, align 8, !tbaa !9
  %106 = load i16, ptr %11, align 2, !tbaa !11
  %107 = zext i16 %106 to i64
  %108 = getelementptr inbounds double, ptr %105, i64 %107
  %109 = load double, ptr %108, align 8, !tbaa !5
  %110 = load double, ptr %9, align 8, !tbaa !5
  %111 = fadd double %109, %110
  %112 = fmul double %111, 2.550000e+02
  %113 = load ptr, ptr %10, align 8, !tbaa !9
  %114 = load i16, ptr %11, align 2, !tbaa !11
  %115 = zext i16 %114 to i64
  %116 = getelementptr inbounds double, ptr %113, i64 %115
  store double %112, ptr %116, align 8, !tbaa !5
  br label %117

117:                                              ; preds = %104
  %118 = load i16, ptr %11, align 2, !tbaa !11
  %119 = add i16 %118, 1
  store i16 %119, ptr %11, align 2, !tbaa !11
  br label %100, !llvm.loop !13

120:                                              ; preds = %100
  %121 = load ptr, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, 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 ptr %121
}

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

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

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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { 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}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; 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, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @convertHSVtoRGB(double noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #1 {
  %4 = fmul double %1, %2
  %5 = fdiv double %0, 6.000000e+01
  %6 = tail call double @fmod(double noundef %5, double noundef 2.000000e+00) #4
  %7 = fadd double %6, -1.000000e+00
  %8 = tail call double @llvm.fabs.f64(double %7)
  %9 = fsub double 1.000000e+00, %8
  %10 = fmul double %4, %9
  %11 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  %12 = fcmp olt double %0, 6.000000e+01
  br i1 %12, label %22, label %13

13:                                               ; preds = %3
  %14 = fcmp olt double %0, 1.200000e+02
  br i1 %14, label %22, label %15

15:                                               ; preds = %13
  %16 = fcmp olt double %0, 1.800000e+02
  br i1 %16, label %22, label %17

17:                                               ; preds = %15
  %18 = fcmp olt double %0, 2.400000e+02
  br i1 %18, label %22, label %19

19:                                               ; preds = %17
  %20 = fcmp olt double %0, 3.000000e+02
  br i1 %20, label %22, label %21

21:                                               ; preds = %19
  store double %4, ptr %11, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %19, %17, %15, %13, %3, %21
  %23 = phi double [ %10, %21 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %13 ], [ %10, %15 ], [ %4, %17 ], [ %4, %19 ]
  %24 = phi double [ 0.000000e+00, %21 ], [ %10, %3 ], [ %4, %13 ], [ %4, %15 ], [ %10, %17 ], [ 0.000000e+00, %19 ]
  %25 = phi double [ %4, %21 ], [ %4, %3 ], [ %10, %13 ], [ 0.000000e+00, %15 ], [ 0.000000e+00, %17 ], [ %10, %19 ]
  %26 = fsub double %2, %4
  %27 = fadd double %26, %25
  %28 = fmul double %27, 2.550000e+02
  store double %28, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %11, i64 8
  %30 = fadd double %26, %24
  %31 = fmul double %30, 2.550000e+02
  store double %31, ptr %29, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %11, i64 16
  %33 = fadd double %26, %23
  %34 = fmul double %33, 2.550000e+02
  store double %34, ptr %32, align 8, !tbaa !5
  ret ptr %11
}

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

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

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, 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass