; LLVM IR from indjev99/Evolving-Snakes :: sources/randomisation.ll (Z14mutateVariableRddd)

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

@MAX_MUTATION = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14mutateVariableRddd(ptr noundef nonnull align 8 dereferenceable(8) %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %7 = call i32 @rand() #3
  %8 = srem i32 %7, 100
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %25

10:                                               ; preds = %3
  %11 = call i32 @rand() #3
  %12 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !11
  %13 = mul nsw i32 %12, 2
  %14 = add nsw i32 %13, 1
  %15 = srem i32 %11, %14
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %16, 1.000000e+03
  %18 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !11
  %19 = sitofp i32 %18 to double
  %20 = fdiv double %19, 1.000000e+03
  %21 = fsub double %17, %20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = fadd double %23, %21
  store double %24, ptr %22, align 8, !tbaa !9
  br label %49

25:                                               ; preds = %3
  %26 = call i32 @rand() #3
  %27 = srem i32 %26, 20
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %44

29:                                               ; preds = %25
  %30 = call i32 @rand() #3
  %31 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !11
  %32 = mul nsw i32 %31, 2
  %33 = add nsw i32 %32, 1
  %34 = srem i32 %30, %33
  %35 = sitofp i32 %34 to double
  %36 = fdiv double %35, 5.000000e+01
  %37 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !11
  %38 = sitofp i32 %37 to double
  %39 = fdiv double %38, 5.000000e+01
  %40 = fsub double %36, %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fadd double %42, %40
  store double %43, ptr %41, align 8, !tbaa !9
  br label %48

44:                                               ; preds = %25
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load double, ptr %5, align 8, !tbaa !9
  %47 = load double, ptr %6, align 8, !tbaa !9
  call void @_Z17randomiseVariableRddd(ptr noundef nonnull align 8 dereferenceable(8) %45, double noundef %46, double noundef %47)
  br label %48

48:                                               ; preds = %44, %29
  br label %49

49:                                               ; preds = %48, %10
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = fcmp olt double %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %49
  %55 = load double, ptr %5, align 8, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  store double %55, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %54, %49
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load double, ptr %58, align 8, !tbaa !9
  %60 = load double, ptr %6, align 8, !tbaa !9
  %61 = fcmp ogt double %59, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %57
  %63 = load double, ptr %6, align 8, !tbaa !9
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  store double %63, ptr %64, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %62, %57
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17randomiseVariableRddd(ptr noundef nonnull align 8 dereferenceable(8), double noundef, double noundef) #2

attributes #0 = { mustprogress 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 = { 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 #2 = { mustprogress 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 }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

@MAX_MUTATION = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z14mutateVariableRddd(ptr noundef nonnull align 8 dereferenceable(8) %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @rand() #2
  %5 = srem i32 %4, 100
  %.not = icmp eq i32 %5, 0
  %6 = tail call i32 @rand() #2
  br i1 %.not, label %20, label %7

7:                                                ; preds = %3
  %8 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !5
  %9 = shl nsw i32 %8, 1
  %10 = or disjoint i32 %9, 1
  %11 = srem i32 %6, %10
  %12 = insertelement <2 x i32> poison, i32 %11, i64 0
  %13 = insertelement <2 x i32> %12, i32 %8, i64 1
  %14 = sitofp <2 x i32> %13 to <2 x double>
  %15 = fdiv <2 x double> %14, <double 1.000000e+03, double 1.000000e+03>
  %shift = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %16 = fsub <2 x double> %15, %shift
  %17 = extractelement <2 x double> %16, i64 0
  %18 = load double, ptr %0, align 8, !tbaa !9
  %19 = fadd double %18, %17
  store double %19, ptr %0, align 8, !tbaa !9
  br label %37

20:                                               ; preds = %3
  %21 = srem i32 %6, 20
  %.not14 = icmp eq i32 %21, 0
  br i1 %.not14, label %36, label %22

22:                                               ; preds = %20
  %23 = tail call i32 @rand() #2
  %24 = load i32, ptr @MAX_MUTATION, align 4, !tbaa !5
  %25 = shl nsw i32 %24, 1
  %26 = or disjoint i32 %25, 1
  %27 = srem i32 %23, %26
  %28 = insertelement <2 x i32> poison, i32 %27, i64 0
  %29 = insertelement <2 x i32> %28, i32 %24, i64 1
  %30 = sitofp <2 x i32> %29 to <2 x double>
  %31 = fdiv <2 x double> %30, <double 5.000000e+01, double 5.000000e+01>
  %shift15 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %32 = fsub <2 x double> %31, %shift15
  %33 = extractelement <2 x double> %32, i64 0
  %34 = load double, ptr %0, align 8, !tbaa !9
  %35 = fadd double %34, %33
  store double %35, ptr %0, align 8, !tbaa !9
  br label %37

36:                                               ; preds = %20
  tail call void @_Z17randomiseVariableRddd(ptr noundef nonnull align 8 dereferenceable(8) %0, double noundef %1, double noundef %2)
  %.pre = load double, ptr %0, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %22, %36, %7
  %38 = phi double [ %35, %22 ], [ %.pre, %36 ], [ %19, %7 ]
  %39 = fcmp olt double %38, %1
  %40 = select i1 %39, double %1, double %38
  %41 = fcmp ogt double %40, %2
  %42 = or i1 %39, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  %simplifycfg.merge = select i1 %41, double %2, double %40
  store double %simplifycfg.merge, ptr %0, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %37, %43
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17randomiseVariableRddd(ptr noundef nonnull align 8 dereferenceable(8), double noundef, double noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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 = { 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 #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass