; LLVM IR from antirez/ttt-rl :: ttt (train_against_random)

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

@.str.19 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @play_random_game(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @train_against_random(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [9 x i32], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 36, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.19, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %77, %2
  %16 = load i32, ptr %11, align 4, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %80

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds [9 x i32], ptr %5, i64 0, i64 0
  %23 = call signext i8 @play_random_game(ptr noundef %21, ptr noundef %22, ptr noundef %6)
  store i8 %23, ptr %12, align 1, !tbaa !11
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %10, align 4, !tbaa !9
  %26 = load i8, ptr %12, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 79
  br i1 %28, label %29, label %32

29:                                               ; preds = %20
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !9
  br label %43

32:                                               ; preds = %20
  %33 = load i8, ptr %12, align 1, !tbaa !11
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 88
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %8, align 4, !tbaa !9
  br label %42

39:                                               ; preds = %32
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %36
  br label %43

43:                                               ; preds = %42, %29
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  %46 = srem i32 %45, 10000
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %76

48:                                               ; preds = %43
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sitofp i32 %52 to float
  %54 = fmul float %53, 1.000000e+02
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = sitofp i32 %55 to float
  %57 = fdiv float %54, %56
  %58 = fpext float %57 to double
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = sitofp i32 %60 to float
  %62 = fmul float %61, 1.000000e+02
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sitofp i32 %63 to float
  %65 = fdiv float %62, %64
  %66 = fpext float %65 to double
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sitofp i32 %68 to float
  %70 = fmul float %69, 1.000000e+02
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = sitofp i32 %71 to float
  %73 = fdiv float %70, %72
  %74 = fpext float %73 to double
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.20, i32 noundef %50, i32 noundef %51, double noundef %58, i32 noundef %59, double noundef %66, i32 noundef %67, double noundef %74)
  store i32 0, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %48, %43
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %11, align 4, !tbaa !9
  br label %15, !llvm.loop !12

80:                                               ; preds = %19
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr %5) #3
  ret void
}

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

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str.19 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @play_random_game(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @train_against_random(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = alloca [9 x i32], align 16
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.19, i32 noundef %1)
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %35, %2
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %3) #3
  ret void

.lr.ph:                                           ; preds = %2, %35
  %.035 = phi i32 [ %.2, %35 ], [ 0, %2 ]
  %.02134 = phi i32 [ %17, %35 ], [ 0, %2 ]
  %.02233 = phi i32 [ %.123, %35 ], [ 0, %2 ]
  %.02432 = phi i32 [ %.226, %35 ], [ 0, %2 ]
  %.02731 = phi i32 [ %.229, %35 ], [ 0, %2 ]
  %8 = call signext i8 @play_random_game(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = add nsw i32 %.02233, 1
  switch i8 %8, label %14 [
    i8 79, label %10
    i8 88, label %12
  ]

10:                                               ; preds = %.lr.ph
  %11 = add nsw i32 %.035, 1
  br label %16

12:                                               ; preds = %.lr.ph
  %13 = add nsw i32 %.02731, 1
  br label %16

14:                                               ; preds = %.lr.ph
  %15 = add nsw i32 %.02432, 1
  br label %16

16:                                               ; preds = %12, %14, %10
  %.128 = phi i32 [ %.02731, %10 ], [ %13, %12 ], [ %.02731, %14 ]
  %.125 = phi i32 [ %.02432, %10 ], [ %.02432, %12 ], [ %15, %14 ]
  %.1 = phi i32 [ %11, %10 ], [ %.035, %12 ], [ %.035, %14 ]
  %17 = add nuw nsw i32 %.02134, 1
  %18 = urem i32 %17, 10000
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %35

20:                                               ; preds = %16
  %21 = sitofp i32 %.1 to float
  %22 = fmul float %21, 1.000000e+02
  %23 = sitofp i32 %9 to float
  %24 = fdiv float %22, %23
  %25 = fpext float %24 to double
  %26 = sitofp i32 %.128 to float
  %27 = fmul float %26, 1.000000e+02
  %28 = fdiv float %27, %23
  %29 = fpext float %28 to double
  %30 = sitofp i32 %.125 to float
  %31 = fmul float %30, 1.000000e+02
  %32 = fdiv float %31, %23
  %33 = fpext float %32 to double
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20, i32 noundef %17, i32 noundef %.1, double noundef %25, i32 noundef %.128, double noundef %29, i32 noundef %.125, double noundef %33)
  br label %35

35:                                               ; preds = %20, %16
  %.229 = phi i32 [ 0, %20 ], [ %.128, %16 ]
  %.226 = phi i32 [ 0, %20 ], [ %.125, %16 ]
  %.123 = phi i32 [ 0, %20 ], [ %9, %16 ]
  %.2 = phi i32 [ 0, %20 ], [ %.1, %16 ]
  %exitcond.not = icmp eq i32 %17, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass