; LLVM IR from clausecker/24puzzle :: transposition (tileset_morph)

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

@automorphisms = external dso_local constant [8 x [2 x [32 x i8]]], align 64
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.tileset_morph = external hidden unnamed_addr constant [45 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @tileset_morph(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 8
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  br label %10

9:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 245, ptr noundef @__PRETTY_FUNCTION__.tileset_morph) #5
  unreachable

10:                                               ; preds = %8
  br label %11

11:                                               ; preds = %29, %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = call i32 @tileset_empty(i32 noundef %12)
  %14 = icmp ne i32 %13, 0
  %15 = xor i1 %14, true
  br i1 %15, label %16, label %32

16:                                               ; preds = %11
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [8 x [2 x [32 x i8]]], ptr @automorphisms, i64 0, i64 %19
  %21 = getelementptr inbounds [2 x [32 x i8]], ptr %20, i64 0, i64 0
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = call i32 @tileset_get_least(i32 noundef %22)
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = call i32 @tileset_add(i32 noundef %17, i32 noundef %27)
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %16
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call i32 @tileset_remove_least(i32 noundef %30)
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !10

32:                                               ; preds = %11
  %33 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %33
}

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

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

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

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

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

@automorphisms = external dso_local local_unnamed_addr constant [8 x [2 x [32 x i8]]], align 64
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__.tileset_morph = external hidden unnamed_addr constant [45 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tileset_morph(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp ult i32 %1, 8
  br i1 %3, label %.preheader, label %7

.preheader:                                       ; preds = %2
  %4 = tail call i32 @tileset_empty(i32 noundef %0)
  %.not8 = icmp eq i32 %4, 0
  br i1 %.not8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %5 = zext nneg i32 %1 to i64
  %6 = getelementptr inbounds [8 x [2 x [32 x i8]]], ptr @automorphisms, i64 0, i64 %5
  br label %8

7:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 245, ptr noundef nonnull @__PRETTY_FUNCTION__.tileset_morph) #3
  unreachable

8:                                                ; preds = %.lr.ph, %8
  %.010 = phi i32 [ 0, %.lr.ph ], [ %14, %8 ]
  %.079 = phi i32 [ %0, %.lr.ph ], [ %15, %8 ]
  %9 = tail call i32 @tileset_get_least(i32 noundef %.079)
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = zext i8 %12 to i32
  %14 = tail call i32 @tileset_add(i32 noundef %.010, i32 noundef %13)
  %15 = tail call i32 @tileset_remove_least(i32 noundef %.079)
  %16 = tail call i32 @tileset_empty(i32 noundef %15)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %8, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %8, %.preheader
  %.0.lcssa = phi i32 [ 0, %.preheader ], [ %14, %8 ]
  ret i32 %.0.lcssa
}

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

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

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

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

attributes #0 = { 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 #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 = { 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 }

!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"}


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