; LLVM IR from clausecker/24puzzle :: moves (generate_moves)

; 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.move = type { i32, i32 }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.generate_moves = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @generate_moves(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  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 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = call i32 @tileset_reduce_eqclass(i32 noundef %10)
  store i32 %11, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %65, %2
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = call i32 @tileset_empty(i32 noundef %13)
  %15 = icmp ne i32 %14, 0
  %16 = xor i1 %15, true
  br i1 %16, label %17, label %68

17:                                               ; preds = %12
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = call i32 @tileset_get_least(i32 noundef %18)
  %20 = zext i32 %19 to i64
  store i64 %20, ptr %7, align 8, !tbaa !11
  %21 = load i64, ptr %7, align 8, !tbaa !11
  %22 = call ptr @get_moves(i64 noundef %21)
  store ptr %22, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %61, %17
  %24 = load i64, ptr %6, align 8, !tbaa !11
  %25 = icmp ult i64 %24, 4
  br i1 %25, label %26, label %64

26:                                               ; preds = %23
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 %31, -1
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  br label %64

34:                                               ; preds = %26
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = call i32 @tileset_has(i32 noundef %35, i32 noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %60, label %43

43:                                               ; preds = %34
  %44 = load i64, ptr %7, align 8, !tbaa !11
  %45 = trunc i64 %44 to i32
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i64, ptr %5, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.move, ptr %46, i64 %47
  %49 = getelementptr inbounds %struct.move, ptr %48, i32 0, i32 0
  store i32 %45, ptr %49, align 4, !tbaa !14
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load i64, ptr %6, align 8, !tbaa !11
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = sext i8 %53 to i32
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load i64, ptr %5, align 8, !tbaa !11
  %57 = add i64 %56, 1
  store i64 %57, ptr %5, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.move, ptr %55, i64 %56
  %59 = getelementptr inbounds %struct.move, ptr %58, i32 0, i32 1
  store i32 %54, ptr %59, align 4, !tbaa !16
  br label %60

60:                                               ; preds = %43, %34
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %6, align 8, !tbaa !11
  %63 = add i64 %62, 1
  store i64 %63, ptr %6, align 8, !tbaa !11
  br label %23, !llvm.loop !17

64:                                               ; preds = %33, %23
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = call i32 @tileset_remove_least(i32 noundef %66)
  store i32 %67, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !19

68:                                               ; preds = %12
  %69 = load i64, ptr %5, align 8, !tbaa !11
  %70 = icmp ule i64 %69, 80
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  br label %73

72:                                               ; preds = %68
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 147, ptr noundef @__PRETTY_FUNCTION__.generate_moves) #5
  unreachable

73:                                               ; preds = %71
  %74 = load i64, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i64 %74
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_reduce_eqclass(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_empty(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_get_least(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_moves(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_has(i32 noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_remove_least(i32 noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

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 = { inlinehint 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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"move", !10, i64 0, !10, i64 4}
!16 = !{!15, !10, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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.move = type { i32, i32 }

@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.generate_moves = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 81) i64 @generate_moves(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @tileset_reduce_eqclass(i32 noundef %1)
  %4 = tail call i32 @tileset_empty(i32 noundef %3)
  %.not26 = icmp eq i32 %4, 0
  br i1 %.not26, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %2, %58
  %.028 = phi i64 [ %.1.lcssa, %58 ], [ 0, %2 ]
  %.02027 = phi i32 [ %59, %58 ], [ %3, %2 ]
  %5 = tail call i32 @tileset_get_least(i32 noundef %.02027)
  %6 = zext i32 %5 to i64
  %7 = tail call ptr @get_moves(i64 noundef %6)
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp eq i8 %8, -1
  br i1 %9, label %58, label %10

10:                                               ; preds = %.lr.ph
  %11 = sext i8 %8 to i32
  %12 = tail call i32 @tileset_has(i32 noundef %1, i32 noundef %11)
  %.not23 = icmp eq i32 %12, 0
  br i1 %.not23, label %13, label %19

13:                                               ; preds = %10
  %14 = getelementptr inbounds %struct.move, ptr %0, i64 %.028
  store i32 %5, ptr %14, align 4, !tbaa !8
  %15 = load i8, ptr %7, align 1, !tbaa !5
  %16 = sext i8 %15 to i32
  %17 = add i64 %.028, 1
  %18 = getelementptr inbounds i8, ptr %14, i64 4
  store i32 %16, ptr %18, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %10, %13
  %.2 = phi i64 [ %.028, %10 ], [ %17, %13 ]
  %20 = getelementptr inbounds i8, ptr %7, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = icmp eq i8 %21, -1
  br i1 %22, label %58, label %23

23:                                               ; preds = %19
  %24 = sext i8 %21 to i32
  %25 = tail call i32 @tileset_has(i32 noundef %1, i32 noundef %24)
  %.not23.1 = icmp eq i32 %25, 0
  br i1 %.not23.1, label %26, label %32

26:                                               ; preds = %23
  %27 = getelementptr inbounds %struct.move, ptr %0, i64 %.2
  store i32 %5, ptr %27, align 4, !tbaa !8
  %28 = load i8, ptr %20, align 1, !tbaa !5
  %29 = sext i8 %28 to i32
  %30 = add i64 %.2, 1
  %31 = getelementptr inbounds i8, ptr %27, i64 4
  store i32 %29, ptr %31, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %26, %23
  %.2.1 = phi i64 [ %.2, %23 ], [ %30, %26 ]
  %33 = getelementptr inbounds i8, ptr %7, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = icmp eq i8 %34, -1
  br i1 %35, label %58, label %36

36:                                               ; preds = %32
  %37 = sext i8 %34 to i32
  %38 = tail call i32 @tileset_has(i32 noundef %1, i32 noundef %37)
  %.not23.2 = icmp eq i32 %38, 0
  br i1 %.not23.2, label %39, label %45

39:                                               ; preds = %36
  %40 = getelementptr inbounds %struct.move, ptr %0, i64 %.2.1
  store i32 %5, ptr %40, align 4, !tbaa !8
  %41 = load i8, ptr %33, align 1, !tbaa !5
  %42 = sext i8 %41 to i32
  %43 = add i64 %.2.1, 1
  %44 = getelementptr inbounds i8, ptr %40, i64 4
  store i32 %42, ptr %44, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %39, %36
  %.2.2 = phi i64 [ %.2.1, %36 ], [ %43, %39 ]
  %46 = getelementptr inbounds i8, ptr %7, i64 3
  %47 = load i8, ptr %46, align 1, !tbaa !5
  %48 = icmp eq i8 %47, -1
  br i1 %48, label %58, label %49

49:                                               ; preds = %45
  %50 = sext i8 %47 to i32
  %51 = tail call i32 @tileset_has(i32 noundef %1, i32 noundef %50)
  %.not23.3 = icmp eq i32 %51, 0
  br i1 %.not23.3, label %52, label %58

52:                                               ; preds = %49
  %53 = getelementptr inbounds %struct.move, ptr %0, i64 %.2.2
  store i32 %5, ptr %53, align 4, !tbaa !8
  %54 = load i8, ptr %46, align 1, !tbaa !5
  %55 = sext i8 %54 to i32
  %56 = add i64 %.2.2, 1
  %57 = getelementptr inbounds i8, ptr %53, i64 4
  store i32 %55, ptr %57, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %49, %52, %45, %32, %19, %.lr.ph
  %.1.lcssa = phi i64 [ %.028, %.lr.ph ], [ %.2, %19 ], [ %.2.1, %32 ], [ %.2.2, %45 ], [ %.2.2, %49 ], [ %56, %52 ]
  %59 = tail call i32 @tileset_remove_least(i32 noundef %.02027)
  %60 = tail call i32 @tileset_empty(i32 noundef %59)
  %.not = icmp eq i32 %60, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %58
  %61 = icmp ult i64 %.1.lcssa, 81
  br i1 %61, label %._crit_edge.thread, label %62

62:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 147, ptr noundef nonnull @__PRETTY_FUNCTION__.generate_moves) #3
  unreachable

._crit_edge.thread:                               ; preds = %2, %._crit_edge
  %.0.lcssa30 = phi i64 [ %.1.lcssa, %._crit_edge ], [ 0, %2 ]
  ret i64 %.0.lcssa30
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_reduce_eqclass(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_empty(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_get_least(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @get_moves(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_has(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_remove_least(i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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


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