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

; 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.GameState = type { [9 x i8], i32 }

@.str.9 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [13 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

; Function Attrs: nounwind uwtable
declare dso_local void @init_game(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @display_board(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @check_game_over(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_computer_move(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @learn_from_game(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) #1

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

13:                                               ; preds = %70, %52, %1
  %14 = call i32 @check_game_over(ptr noundef %3, ptr noundef %4)
  %15 = icmp ne i32 %14, 0
  %16 = xor i1 %15, true
  br i1 %16, label %17, label %77

17:                                               ; preds = %13
  call void @display_board(ptr noundef %3)
  %18 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %55

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.12, ptr noundef %8)
  %24 = load i8, ptr %8, align 1, !tbaa !13
  %25 = sext i8 %24 to i32
  %26 = sub nsw i32 %25, 48
  store i32 %26, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %40, label %29

29:                                               ; preds = %21
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 8
  br i1 %31, label %40, label %32

32:                                               ; preds = %29
  %33 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 0
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [9 x i8], ptr %33, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 46
  br i1 %39, label %40, label %42

40:                                               ; preds = %32, %29, %21
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  store i32 2, ptr %9, align 4
  br label %52, !llvm.loop !14

42:                                               ; preds = %32
  %43 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 0
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [9 x i8], ptr %43, i64 0, i64 %45
  store i8 88, ptr %46, align 1, !tbaa !13
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [9 x i32], ptr %5, i64 0, i64 %50
  store i32 %47, ptr %51, align 4, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %52

52:                                               ; preds = %42, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %53 = load i32, ptr %9, align 4
  switch i32 %53, label %97 [
    i32 0, label %54
    i32 2, label %13
  ]

54:                                               ; preds = %52
  br label %70

55:                                               ; preds = %17
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = call i32 @get_computer_move(ptr noundef %3, ptr noundef %57, i32 noundef 1)
  store i32 %58, ptr %10, align 4, !tbaa !9
  %59 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 0
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [9 x i8], ptr %59, i64 0, i64 %61
  store i8 79, ptr %62, align 1, !tbaa !13
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.15, i32 noundef %63)
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %6, align 4, !tbaa !9
  %68 = sext i32 %66 to i64
  %69 = getelementptr inbounds [9 x i32], ptr %5, i64 0, i64 %68
  store i32 %65, ptr %69, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %70

70:                                               ; preds = %55, %54
  %71 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !11
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  %75 = zext i1 %74 to i32
  %76 = getelementptr inbounds %struct.GameState, ptr %3, i32 0, i32 1
  store i32 %75, ptr %76, align 4, !tbaa !11
  br label %13, !llvm.loop !14

77:                                               ; preds = %13
  call void @display_board(ptr noundef %3)
  %78 = load i8, ptr %4, align 1, !tbaa !13
  %79 = sext i8 %78 to i32
  %80 = icmp eq i32 %79, 88
  br i1 %80, label %81, label %83

81:                                               ; preds = %77
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.16)
  br label %92

83:                                               ; preds = %77
  %84 = load i8, ptr %4, align 1, !tbaa !13
  %85 = sext i8 %84 to i32
  %86 = icmp eq i32 %85, 79
  br i1 %86, label %87, label %89

87:                                               ; preds = %83
  %88 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  br label %91

89:                                               ; preds = %83
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.18)
  br label %91

91:                                               ; preds = %89, %87
  br label %92

92:                                               ; preds = %91, %81
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds [9 x i32], ptr %5, i64 0, i64 0
  %95 = load i32, ptr %6, align 4, !tbaa !9
  %96 = load i8, ptr %4, align 1, !tbaa !13
  call void @learn_from_game(ptr noundef %93, ptr noundef %94, i32 noundef %95, i32 noundef 1, i8 noundef signext %96)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  ret void

97:                                               ; preds = %52
  unreachable
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = !{!12, !10, i64 12}
!12 = !{!"", !7, i64 0, !10, i64 12}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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.GameState = type { [9 x i8], i32 }

@.str.9 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [13 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: nounwind uwtable
declare dso_local void @init_game(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @display_board(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @check_game_over(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_computer_move(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @learn_from_game(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @play_game(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.GameState, align 4
  %3 = alloca i8, align 1
  %4 = alloca [9 x i32], align 16
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #3
  call void @init_game(ptr noundef nonnull %2)
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %8 = call i32 @check_game_over(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not2628 = icmp eq i32 %8, 0
  br i1 %.not2628, label %.lr.ph.lr.ph, label %.outer._crit_edge

.lr.ph.lr.ph:                                     ; preds = %1
  %9 = getelementptr inbounds i8, ptr %2, i64 12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %.outer
  %indvars.iv = phi i64 [ 0, %.lr.ph.lr.ph ], [ %indvars.iv.next, %.outer ]
  br label %10

10:                                               ; preds = %.lr.ph, %25
  call void @display_board(ptr noundef nonnull %2)
  %11 = load i32, ptr %9, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %28

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.12, ptr noundef nonnull %5)
  %16 = load i8, ptr %5, align 1, !tbaa !10
  %17 = add i8 %16, -57
  %or.cond = icmp ult i8 %17, -9
  br i1 %or.cond, label %25, label %18

18:                                               ; preds = %13
  %narrow = add nsw i8 %16, -48
  %19 = zext nneg i8 %narrow to i64
  %20 = getelementptr inbounds [9 x i8], ptr %2, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !10
  %.not17 = icmp eq i8 %21, 46
  br i1 %.not17, label %.thread, label %25

.thread:                                          ; preds = %18
  %22 = getelementptr inbounds [9 x i8], ptr %2, i64 0, i64 %19
  %23 = zext nneg i8 %narrow to i32
  store i8 88, ptr %22, align 1, !tbaa !10
  %24 = getelementptr inbounds [9 x i32], ptr %4, i64 0, i64 %indvars.iv
  store i32 %23, ptr %24, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  br label %.outer

25:                                               ; preds = %13, %18
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  %27 = call i32 @check_game_over(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %10, label %.outer._crit_edge.loopexit

28:                                               ; preds = %10
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  %30 = call i32 @get_computer_move(ptr noundef nonnull %2, ptr noundef %0, i32 noundef 1)
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [9 x i8], ptr %2, i64 0, i64 %31
  store i8 79, ptr %32, align 1, !tbaa !10
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15, i32 noundef %30)
  %34 = getelementptr inbounds [9 x i32], ptr %4, i64 0, i64 %indvars.iv
  store i32 %30, ptr %34, align 4, !tbaa !11
  br label %.outer

.outer:                                           ; preds = %.thread, %28
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %.not18 = icmp eq i32 %35, 0
  %36 = zext i1 %.not18 to i32
  store i32 %36, ptr %9, align 4, !tbaa !5
  %37 = call i32 @check_game_over(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not26 = icmp eq i32 %37, 0
  br i1 %.not26, label %.lr.ph, label %.outer._crit_edge.loopexit31, !llvm.loop !12

.outer._crit_edge.loopexit:                       ; preds = %25
  %38 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.outer._crit_edge

.outer._crit_edge.loopexit31:                     ; preds = %.outer
  %39 = trunc nuw i64 %indvars.iv.next to i32
  br label %.outer._crit_edge

.outer._crit_edge:                                ; preds = %.outer._crit_edge.loopexit31, %.outer._crit_edge.loopexit, %1
  %.0.ph.lcssa = phi i32 [ 0, %1 ], [ %38, %.outer._crit_edge.loopexit ], [ %39, %.outer._crit_edge.loopexit31 ]
  call void @display_board(ptr noundef nonnull %2)
  %40 = load i8, ptr %3, align 1, !tbaa !10
  %switch.selectcmp = icmp eq i8 %40, 79
  %switch.select = select i1 %switch.selectcmp, ptr @.str.17, ptr @.str.18
  %switch.selectcmp36 = icmp eq i8 %40, 88
  %switch.select37 = select i1 %switch.selectcmp36, ptr @.str.16, ptr %switch.select
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %switch.select37)
  %42 = load i8, ptr %3, align 1, !tbaa !10
  call void @learn_from_game(ptr noundef %0, ptr noundef nonnull %4, i32 noundef %.0.ph.lcssa, i32 noundef 1, i8 noundef signext %42)
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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, !9, i64 12}
!6 = !{!"", !7, i64 0, !9, i64 12}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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