; LLVM IR from clausecker/24puzzle :: tileset (tileset_populate_eqclasses)

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

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

12:                                               ; preds = %23, %2
  %13 = load i32, ptr %6, 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 %26

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

23:                                               ; preds = %17
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = call i32 @tileset_remove_least(i32 noundef %24)
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !12

26:                                               ; preds = %12
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %58, %26
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = call i32 @tileset_empty(i32 noundef %28)
  %30 = icmp ne i32 %29, 0
  %31 = xor i1 %30, true
  br i1 %31, label %32, label %61

32:                                               ; preds = %27
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = call i32 @tileset_get_least(i32 noundef %34)
  %36 = call i32 @tileset_flood(i32 noundef %33, i32 noundef %35)
  store i32 %36, ptr %7, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = call i32 @tileset_difference(i32 noundef %37, i32 noundef %38)
  store i32 %39, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %40, ptr %6, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %54, %32
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = call i32 @tileset_empty(i32 noundef %42)
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  br i1 %45, label %46, label %57

46:                                               ; preds = %41
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = call i32 @tileset_get_least(i32 noundef %50)
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  store i8 %48, ptr %53, align 1, !tbaa !11
  br label %54

54:                                               ; preds = %46
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = call i32 @tileset_remove_least(i32 noundef %55)
  store i32 %56, ptr %6, align 4, !tbaa !9
  br label %41, !llvm.loop !14

57:                                               ; preds = %41
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !9
  br label %27, !llvm.loop !15

61:                                               ; preds = %27
  %62 = load i32, ptr %5, align 4, !tbaa !9
  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 4, ptr %5) #3
  ret i32 %62
}

; 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_complement(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 i32 @tileset_remove_least(i32 noundef) #2

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

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

; 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 = { 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"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

; Function Attrs: nounwind uwtable
define dso_local i32 @tileset_populate_eqclasses(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @tileset_complement(i32 noundef %1)
  %4 = tail call i32 @tileset_empty(i32 noundef %1)
  %.not22 = icmp eq i32 %4, 0
  br i1 %.not22, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %2
  %5 = tail call i32 @tileset_empty(i32 noundef %3)
  %.not2027 = icmp eq i32 %5, 0
  br i1 %.not2027, label %.lr.ph30, label %._crit_edge31

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01923 = phi i32 [ %9, %.lr.ph ], [ %1, %2 ]
  %6 = tail call i32 @tileset_get_least(i32 noundef %.01923)
  %7 = zext i32 %6 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 %7
  store i8 -1, ptr %8, align 1, !tbaa !5
  %9 = tail call i32 @tileset_remove_least(i32 noundef %.01923)
  %10 = tail call i32 @tileset_empty(i32 noundef %9)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.lr.ph, label %.preheader, !llvm.loop !8

.lr.ph30:                                         ; preds = %.preheader, %._crit_edge
  %.029 = phi i32 [ %13, %._crit_edge ], [ %3, %.preheader ]
  %.01828 = phi i32 [ %22, %._crit_edge ], [ 0, %.preheader ]
  %11 = tail call i32 @tileset_get_least(i32 noundef %.029)
  %12 = tail call i32 @tileset_flood(i32 noundef %.029, i32 noundef %11)
  %13 = tail call i32 @tileset_difference(i32 noundef %.029, i32 noundef %12)
  %14 = tail call i32 @tileset_empty(i32 noundef %12)
  %.not2124 = icmp eq i32 %14, 0
  br i1 %.not2124, label %.lr.ph26, label %._crit_edge

.lr.ph26:                                         ; preds = %.lr.ph30
  %15 = trunc i32 %.01828 to i8
  br label %16

16:                                               ; preds = %.lr.ph26, %16
  %.125 = phi i32 [ %12, %.lr.ph26 ], [ %20, %16 ]
  %17 = tail call i32 @tileset_get_least(i32 noundef %.125)
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 %18
  store i8 %15, ptr %19, align 1, !tbaa !5
  %20 = tail call i32 @tileset_remove_least(i32 noundef %.125)
  %21 = tail call i32 @tileset_empty(i32 noundef %20)
  %.not21 = icmp eq i32 %21, 0
  br i1 %.not21, label %16, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %16, %.lr.ph30
  %22 = add i32 %.01828, 1
  %23 = tail call i32 @tileset_empty(i32 noundef %13)
  %.not20 = icmp eq i32 %23, 0
  br i1 %.not20, label %.lr.ph30, label %._crit_edge31, !llvm.loop !11

._crit_edge31:                                    ; preds = %._crit_edge, %.preheader
  %.018.lcssa = phi i32 [ 0, %.preheader ], [ %22, %._crit_edge ]
  ret i32 %.018.lcssa
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_complement(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 i32 @tileset_remove_least(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_difference(i32 noundef, i32 noundef) local_unnamed_addr #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 = { 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" }

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = distinct !{!11, !9}


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