; LLVM IR from kostya/crystal-benchmarks-game :: fasta (fasta)

; 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.aminoacids = type { i8, double }

; Function Attrs: nounwind uwtable
declare dso_local double @gen_random(double noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @selectRandom(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %11 = call double @gen_random(double noundef 1.000000e+00)
  store double %11, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %12 = load double, ptr %6, align 8, !tbaa !11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.aminoacids, ptr %13, i64 0
  %15 = getelementptr inbounds %struct.aminoacids, ptr %14, i32 0, i32 1
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = fcmp olt double %12, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.aminoacids, ptr %19, i64 0
  %21 = getelementptr inbounds %struct.aminoacids, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 8, !tbaa !15
  store i8 %22, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %56

23:                                               ; preds = %2
  store i32 0, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %9, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %48, %23
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  %30 = icmp sgt i32 %27, %29
  br i1 %30, label %31, label %49

31:                                               ; preds = %26
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add nsw i32 %32, %33
  %35 = sdiv i32 %34, 2
  store i32 %35, ptr %7, align 4, !tbaa !9
  %36 = load double, ptr %6, align 8, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.aminoacids, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.aminoacids, ptr %40, i32 0, i32 1
  %42 = load double, ptr %41, align 8, !tbaa !13
  %43 = fcmp olt double %36, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %31
  %45 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %45, ptr %9, align 4, !tbaa !9
  br label %48

46:                                               ; preds = %31
  %47 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %47, ptr %8, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %46, %44
  br label %26, !llvm.loop !16

49:                                               ; preds = %26
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct.aminoacids, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.aminoacids, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %54, align 8, !tbaa !15
  store i8 %55, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %56

56:                                               ; preds = %49, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %57 = load i8, ptr %3, align 1
  ret i8 %57
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"aminoacids", !7, i64 0, !12, i64 8}
!15 = !{!14, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.aminoacids = type { i8, double }

; Function Attrs: nounwind uwtable
declare dso_local double @gen_random(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @selectRandom(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call double @gen_random(double noundef 1.000000e+00)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fcmp olt double %3, %5
  br i1 %6, label %20, label %7

7:                                                ; preds = %2
  %8 = add nsw i32 %1, -1
  %9 = icmp sgt i32 %1, 2
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.020 = phi i32 [ %..0, %.lr.ph ], [ %8, %7 ]
  %.01519 = phi i32 [ %.015., %.lr.ph ], [ 0, %7 ]
  %10 = add nuw nsw i32 %.020, %.01519
  %11 = lshr i32 %10, 1
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds %struct.aminoacids, ptr %0, i64 %12, i32 1
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fcmp olt double %3, %14
  %.015. = select i1 %15, i32 %.01519, i32 %11
  %..0 = select i1 %15, i32 %11, i32 %.020
  %16 = add nuw nsw i32 %.015., 1
  %17 = icmp sgt i32 %..0, %16
  br i1 %17, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %7
  %.0.lcssa = phi i32 [ %8, %7 ], [ %..0, %.lr.ph ]
  %18 = sext i32 %.0.lcssa to i64
  %19 = getelementptr inbounds %struct.aminoacids, ptr %0, i64 %18
  br label %20

20:                                               ; preds = %2, %._crit_edge
  %.017.in = phi ptr [ %19, %._crit_edge ], [ %0, %2 ]
  %.017 = load i8, ptr %.017.in, align 8, !tbaa !12
  ret i8 %.017
}

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, !9, i64 8}
!6 = !{!"aminoacids", !7, i64 0, !9, i64 8}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"double", !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass