; LLVM IR from t-dillon/tdoku :: other/fsss (fsss)

; 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.game = type { [27 x i16], [81 x i16], i32, i32, i32, i32, ptr, ptr }

@fsss_num_guesses = external dso_local global i32, align 4
@__const.fsss_solve.g = external hidden unnamed_addr constant %struct.game, align 8

; Function Attrs: mustprogress uwtable
define dso_local i32 @fsss_solve(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.game, align 8
  %11 = alloca i32, align 4
  %12 = alloca [81 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr null, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  br label %67

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 248, ptr %10) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 @__const.fsss_solve.g, i64 248, i1 false)
  %17 = load i32, ptr %9, align 4, !tbaa !9
  switch i32 %17, label %33 [
    i32 0, label %18
    i32 1, label %29
  ]

18:                                               ; preds = %16
  %19 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = or i32 %20, 2
  store i32 %21, ptr %19, align 8, !tbaa !11
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %28, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = or i32 %26, 1
  store i32 %27, ptr %25, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %24, %18
  br label %34

29:                                               ; preds = %16
  %30 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = or i32 %31, 1
  store i32 %32, ptr %30, align 8, !tbaa !11
  br label %34

33:                                               ; preds = %16
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %66

34:                                               ; preds = %29, %28
  call void @llvm.lifetime.start.p0(i64 81, ptr %12) #5
  %35 = getelementptr inbounds [81 x i8], ptr %12, i64 0, i64 0
  %36 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 6
  store ptr %35, ptr %36, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 7
  store ptr %10, ptr %37, align 8, !tbaa !14
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL4initP4gamePKc(ptr noundef %10, ptr noundef %38)
  store i32 0, ptr @fsss_num_guesses, align 4, !tbaa !9
  %39 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = and i32 %40, 4
  %42 = icmp eq i32 0, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %34
  call void @_ZL7attemptP4game(ptr noundef %10)
  br label %44

44:                                               ; preds = %43, %34
  %45 = load i32, ptr @fsss_num_guesses, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %46, ptr %47, align 8, !tbaa !15
  %48 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !17
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %64

51:                                               ; preds = %44
  %52 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = and i32 %53, 1
  %55 = icmp eq i32 0, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZL9writeBackPK4gamePc(ptr noundef %10, ptr noundef %57)
  br label %58

58:                                               ; preds = %56, %51
  %59 = getelementptr inbounds %struct.game, ptr %10, i32 0, i32 4
  %60 = load i32, ptr %59, align 8, !tbaa !17
  %61 = icmp sgt i32 %60, 1
  br i1 %61, label %62, label %63

62:                                               ; preds = %58
  store i32 2, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %65

63:                                               ; preds = %58
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %65

64:                                               ; preds = %44
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %65

65:                                               ; preds = %64, %63, %62
  call void @llvm.lifetime.end.p0(i64 81, ptr %12) #5
  br label %66

66:                                               ; preds = %65, %33
  call void @llvm.lifetime.end.p0(i64 248, ptr %10) #5
  br label %67

67:                                               ; preds = %66, %15
  %68 = load i32, ptr %5, align 4
  ret i32 %68
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZL4initP4gamePKc(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL7attemptP4game(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL9writeBackPK4gamePc(ptr noundef, ptr noundef) #4

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 216}
!12 = !{!"_ZTS4game", !7, i64 0, !7, i64 54, !10, i64 216, !10, i64 220, !10, i64 224, !10, i64 228, !6, i64 232, !6, i64 240}
!13 = !{!12, !6, i64 232}
!14 = !{!12, !6, i64 240}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!12, !10, i64 224}


; 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.game = type { [27 x i16], [81 x i16], i32, i32, i32, i32, ptr, ptr }

@fsss_num_guesses = external dso_local local_unnamed_addr global i32, align 4
@__const.fsss_solve.g = external hidden unnamed_addr constant %struct.game, align 8

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -1, 3) i32 @fsss_solve(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.game, align 8
  %6 = alloca [81 x i8], align 16
  %7 = icmp eq ptr %0, null
  br i1 %7, label %42, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 248, ptr nonnull %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(248) %5, ptr noundef nonnull align 8 dereferenceable(248) @__const.fsss_solve.g, i64 248, i1 false)
  switch i32 %3, label %41 [
    i32 0, label %9
    i32 1, label %15
  ]

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %5, i64 216
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = or i32 %11, 2
  store i32 %12, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %13, label %19

13:                                               ; preds = %9
  %14 = or i32 %11, 3
  store i32 %14, ptr %10, align 8, !tbaa !5
  br label %19

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %5, i64 216
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = or i32 %17, 1
  store i32 %18, ptr %16, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %9, %13, %15
  call void @llvm.lifetime.start.p0(i64 81, ptr nonnull %6) #5
  %20 = getelementptr inbounds i8, ptr %5, i64 232
  store ptr %6, ptr %20, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %5, i64 240
  store ptr %5, ptr %21, align 8, !tbaa !12
  call void @_ZL4initP4gamePKc(ptr noundef nonnull %5, ptr noundef nonnull %0)
  store i32 0, ptr @fsss_num_guesses, align 4, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %5, i64 216
  %23 = load i32, ptr %22, align 8, !tbaa !5
  %24 = and i32 %23, 4
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %19
  call void @_ZL7attemptP4game(ptr noundef nonnull %5)
  %.pre = load i32, ptr @fsss_num_guesses, align 4, !tbaa !13
  %27 = sext i32 %.pre to i64
  br label %28

28:                                               ; preds = %26, %19
  %29 = phi i64 [ %27, %26 ], [ 0, %19 ]
  store i64 %29, ptr %2, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %5, i64 224
  %31 = load i32, ptr %30, align 8, !tbaa !16
  %.not7 = icmp eq i32 %31, 0
  br i1 %.not7, label %40, label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %22, align 8, !tbaa !5
  %34 = and i32 %33, 1
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  call void @_ZL9writeBackPK4gamePc(ptr noundef nonnull %5, ptr noundef %1)
  %.pre8 = load i32, ptr %30, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %36, %32
  %38 = phi i32 [ %.pre8, %36 ], [ %31, %32 ]
  %39 = icmp sgt i32 %38, 1
  %. = select i1 %39, i32 2, i32 1
  br label %40

40:                                               ; preds = %28, %37
  %.0 = phi i32 [ %., %37 ], [ 0, %28 ]
  call void @llvm.lifetime.end.p0(i64 81, ptr nonnull %6) #5
  br label %41

41:                                               ; preds = %8, %40
  %.1 = phi i32 [ %.0, %40 ], [ -1, %8 ]
  call void @llvm.lifetime.end.p0(i64 248, ptr nonnull %5) #5
  br label %42

42:                                               ; preds = %4, %41
  %.2 = phi i32 [ %.1, %41 ], [ -1, %4 ]
  ret i32 %.2
}

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

; Function Attrs: mustprogress 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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @_ZL4initP4gamePKc(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL7attemptP4game(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL9writeBackPK4gamePc(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 #5 = { 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 216}
!6 = !{!"_ZTS4game", !7, i64 0, !7, i64 54, !9, i64 216, !9, i64 220, !9, i64 224, !9, i64 228, !10, i64 232, !10, i64 240}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !10, i64 232}
!12 = !{!6, !10, i64 240}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!6, !9, i64 224}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass