; LLVM IR from indjev99/Evolving-Snakes :: sources/ctrRandomEvolving.ll (ZN17ctrRandomEvolving5thinkEv)

; 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.decision = type { i8, i8, i8, i8, i8, i32 }
%struct.ctrRandomEvolving = type { %struct.controller, double, double, double, double, double }
%struct.controller = type { ptr, [3 x i32], [3 x i8], [1 x i32], [1 x i8], [1 x i32], [1 x i8], i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i32 } @_ZN17ctrRandomEvolving5thinkEv(ptr noundef nonnull align 8 dereferenceable(88) %0) unnamed_addr #0 align 2 {
  %2 = alloca %struct.decision, align 4
  %3 = alloca ptr, align 8
  %4 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = call i32 @rand() #3
  %7 = srem i32 %6, 1000
  %8 = sitofp i32 %7 to double
  %9 = fdiv double %8, 1.000000e+03
  %10 = getelementptr inbounds %struct.ctrRandomEvolving, ptr %5, i32 0, i32 1
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fcmp olt double %9, %11
  %13 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 0
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 4, !tbaa !14
  %15 = call i32 @rand() #3
  %16 = srem i32 %15, 1000
  %17 = sitofp i32 %16 to double
  %18 = fdiv double %17, 1.000000e+03
  %19 = getelementptr inbounds %struct.ctrRandomEvolving, ptr %5, i32 0, i32 2
  %20 = load double, ptr %19, align 8, !tbaa !17
  %21 = fcmp olt double %18, %20
  %22 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 1
  %23 = zext i1 %21 to i8
  store i8 %23, ptr %22, align 1, !tbaa !18
  %24 = call i32 @rand() #3
  %25 = srem i32 %24, 1000
  %26 = sitofp i32 %25 to double
  %27 = fdiv double %26, 1.000000e+03
  %28 = getelementptr inbounds %struct.ctrRandomEvolving, ptr %5, i32 0, i32 3
  %29 = load double, ptr %28, align 8, !tbaa !19
  %30 = fcmp olt double %27, %29
  %31 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 0
  %32 = zext i1 %30 to i8
  store i8 %32, ptr %31, align 4, !tbaa !14
  %33 = call i32 @rand() #3
  %34 = srem i32 %33, 1000
  %35 = sitofp i32 %34 to double
  %36 = fdiv double %35, 1.000000e+03
  %37 = getelementptr inbounds %struct.ctrRandomEvolving, ptr %5, i32 0, i32 4
  %38 = load double, ptr %37, align 8, !tbaa !20
  %39 = fcmp olt double %36, %38
  %40 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 1
  %41 = zext i1 %39 to i8
  store i8 %41, ptr %40, align 1, !tbaa !18
  %42 = getelementptr inbounds %struct.controller, ptr %5, i32 0, i32 7
  %43 = load i32, ptr %42, align 8, !tbaa !21
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %45, label %60

45:                                               ; preds = %1
  %46 = call i32 @rand() #3
  %47 = srem i32 %46, 1000
  %48 = sitofp i32 %47 to double
  %49 = fdiv double %48, 1.000000e+03
  %50 = getelementptr inbounds %struct.ctrRandomEvolving, ptr %5, i32 0, i32 5
  %51 = load double, ptr %50, align 8, !tbaa !22
  %52 = fcmp olt double %49, %51
  %53 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 4
  %54 = zext i1 %52 to i8
  store i8 %54, ptr %53, align 4, !tbaa !23
  %55 = call i32 @rand() #3
  %56 = getelementptr inbounds %struct.controller, ptr %5, i32 0, i32 7
  %57 = load i32, ptr %56, align 8, !tbaa !21
  %58 = srem i32 %55, %57
  %59 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 5
  store i32 %58, ptr %59, align 4, !tbaa !24
  br label %62

60:                                               ; preds = %1
  %61 = getelementptr inbounds %struct.decision, ptr %2, i32 0, i32 4
  store i8 0, ptr %61, align 4, !tbaa !23
  br label %62

62:                                               ; preds = %60, %45
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 4 %2, i64 12, i1 false)
  %63 = load { i64, i32 }, ptr %4, align 8
  ret { i64, i32 } %63
}

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !13, i64 48}
!10 = !{!"_ZTS17ctrRandomEvolving", !11, i64 0, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80}
!11 = !{!"_ZTS10controller", !7, i64 8, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !12, i64 40, !12, i64 44}
!12 = !{!"int", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTS8decision", !16, i64 0, !16, i64 1, !16, i64 2, !16, i64 3, !16, i64 4, !12, i64 8}
!16 = !{!"bool", !7, i64 0}
!17 = !{!10, !13, i64 56}
!18 = !{!15, !16, i64 1}
!19 = !{!10, !13, i64 64}
!20 = !{!10, !13, i64 72}
!21 = !{!11, !12, i64 40}
!22 = !{!10, !13, i64 80}
!23 = !{!15, !16, i64 4}
!24 = !{!15, !12, i64 8}


; 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 nounwind uwtable
define dso_local { i64, i32 } @_ZN17ctrRandomEvolving5thinkEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(88) %0) unnamed_addr #0 align 2 {
  %2 = tail call i32 @rand() #2
  %3 = tail call i32 @rand() #2
  %4 = tail call i32 @rand() #2
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load <2 x double>, ptr %5, align 8
  %8 = tail call i32 @rand() #2
  %9 = load double, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %25

13:                                               ; preds = %1
  %14 = tail call i32 @rand() #2
  %15 = srem i32 %14, 1000
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %16, 1.000000e+03
  %18 = getelementptr inbounds i8, ptr %0, i64 80
  %19 = load double, ptr %18, align 8, !tbaa !13
  %20 = fcmp olt double %17, %19
  %21 = tail call i32 @rand() #2
  %22 = load i32, ptr %10, align 8, !tbaa !12
  %23 = srem i32 %21, %22
  %24 = select i1 %20, i64 4294967296, i64 0
  br label %25

25:                                               ; preds = %1, %13
  %.sroa.52.0 = phi i64 [ %24, %13 ], [ 0, %1 ]
  %.sroa.7.sroa.1.0 = phi i32 [ %23, %13 ], [ undef, %1 ]
  %26 = insertelement <2 x i32> poison, i32 %4, i64 0
  %27 = insertelement <2 x i32> %26, i32 %8, i64 1
  %28 = srem <2 x i32> %27, <i32 1000, i32 1000>
  %29 = sitofp <2 x i32> %28 to <2 x double>
  %30 = fdiv <2 x double> %29, <double 1.000000e+03, double 1.000000e+03>
  %31 = insertelement <2 x double> %7, double %9, i64 1
  %32 = fcmp olt <2 x double> %30, %31
  %33 = extractelement <2 x i1> %32, i64 1
  %.sroa.3.0.insert.shift = select i1 %33, i64 256, i64 0
  %34 = extractelement <2 x i1> %32, i64 0
  %.sroa.01.0.insert.ext = zext i1 %34 to i64
  %.sroa.3.0.insert.insert = or disjoint i64 %.sroa.3.0.insert.shift, %.sroa.01.0.insert.ext
  %.sroa.01.0.insert.insert = or disjoint i64 %.sroa.3.0.insert.insert, %.sroa.52.0
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.01.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.7.sroa.1.0, 1
  ret { i64, i32 } %.fca.1.insert
}

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

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, !11, i64 72}
!6 = !{!"_ZTS17ctrRandomEvolving", !7, i64 0, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80}
!7 = !{!"_ZTS10controller", !8, i64 8, !8, i64 20, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !10, i64 40, !10, i64 44}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!7, !10, i64 40}
!13 = !{!6, !11, i64 80}


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