; LLVM IR from clausecker/24puzzle :: index (make_index_aux)

; 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.index_aux = type { [32 x i8], [16 x i8], i32, i32, i32, i32, i32, ptr, [16 x i8] }

@factorials = external dso_local constant [13 x i32], align 16
@combination_count = external constant [26 x i32], align 16

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @make_index_aux(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, 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 4, ptr %5) #5
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = call i32 @tileset_remove(i32 noundef %7, i32 noundef 0)
  store i32 %8, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.index_aux, ptr %10, i32 0, i32 6
  store i32 %9, ptr %11, align 32, !tbaa !13
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = call i32 @tileset_count(i32 noundef %12)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.index_aux, ptr %14, i32 0, i32 2
  store i32 %13, ptr %15, align 16, !tbaa !15
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.index_aux, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 16, !tbaa !15
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [26 x i32], ptr @combination_count, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.index_aux, ptr %22, i32 0, i32 3
  store i32 %21, ptr %23, align 4, !tbaa !16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.index_aux, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 16, !tbaa !15
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [13 x i32], ptr @factorials, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.index_aux, ptr %30, i32 0, i32 4
  store i32 %29, ptr %31, align 8, !tbaa !17
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = call i32 @tileset_parity(i32 noundef %32)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.index_aux, ptr %34, i32 0, i32 5
  store i32 %33, ptr %35, align 4, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.index_aux, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 16, !tbaa !15
  %39 = zext i32 %38 to i64
  call void @tileset_unrank_init(i64 noundef %39)
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %40

40:                                               ; preds = %57, %2
  %41 = load i64, ptr %6, align 8, !tbaa !11
  %42 = icmp ult i64 %41, 32
  br i1 %42, label %43, label %60

43:                                               ; preds = %40
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i64, ptr %6, align 8, !tbaa !11
  %46 = trunc i64 %45 to i32
  %47 = shl i32 1, %46
  %48 = and i32 %44, %47
  %49 = icmp ne i32 %48, 0
  %50 = zext i1 %49 to i64
  %51 = select i1 %49, i32 -1, i32 0
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.index_aux, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %6, align 8, !tbaa !11
  %56 = getelementptr inbounds [32 x i8], ptr %54, i64 0, i64 %55
  store i8 %52, ptr %56, align 1, !tbaa !19
  br label %57

57:                                               ; preds = %43
  %58 = load i64, ptr %6, align 8, !tbaa !11
  %59 = add i64 %58, 1
  store i64 %59, ptr %6, align 8, !tbaa !11
  br label %40, !llvm.loop !20

60:                                               ; preds = %40
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.index_aux, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds [16 x i8], ptr %62, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 32 %63, i8 0, i64 16, i1 false)
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %79, %60
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = call i32 @tileset_empty(i32 noundef %65)
  %67 = icmp ne i32 %66, 0
  %68 = xor i1 %67, true
  br i1 %68, label %69, label %82

69:                                               ; preds = %64
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = call i32 @tileset_get_least(i32 noundef %70)
  %72 = xor i32 %71, -1
  %73 = trunc i32 %72 to i8
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.index_aux, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %6, align 8, !tbaa !11
  %77 = add i64 %76, 1
  store i64 %77, ptr %6, align 8, !tbaa !11
  %78 = getelementptr inbounds [16 x i8], ptr %75, i64 0, i64 %76
  store i8 %73, ptr %78, align 1, !tbaa !19
  br label %79

79:                                               ; preds = %69
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = call i32 @tileset_remove_least(i32 noundef %80)
  store i32 %81, ptr %5, align 4, !tbaa !9
  br label %64, !llvm.loop !22

82:                                               ; preds = %64
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.index_aux, ptr %83, i32 0, i32 6
  %85 = load i32, ptr %84, align 32, !tbaa !13
  %86 = call ptr @make_index_table(i32 noundef %85)
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.index_aux, ptr %87, i32 0, i32 7
  store ptr %86, ptr %88, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

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

declare void @tileset_unrank_init(i64 noundef) #4

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

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @make_index_table(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 64}
!14 = !{!"index_aux", !7, i64 0, !7, i64 32, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72}
!15 = !{!14, !10, i64 48}
!16 = !{!14, !10, i64 52}
!17 = !{!14, !10, i64 56}
!18 = !{!14, !10, i64 60}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = !{!14, !6, i64 72}


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

@factorials = external dso_local local_unnamed_addr constant [13 x i32], align 16
@combination_count = external local_unnamed_addr constant [26 x i32], align 16

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @make_index_aux(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = tail call i32 @tileset_remove(i32 noundef %1, i32 noundef 0)
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %1, ptr %4, align 32, !tbaa !5
  %5 = tail call i32 @tileset_count(i32 noundef %3)
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %5, ptr %6, align 16, !tbaa !11
  %7 = zext i32 %5 to i64
  %8 = getelementptr inbounds [26 x i32], ptr @combination_count, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %9, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds [13 x i32], ptr @factorials, i64 0, i64 %7
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %12, ptr %13, align 8, !tbaa !14
  %14 = tail call i32 @tileset_parity(i32 noundef %3)
  %15 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %14, ptr %15, align 4, !tbaa !15
  %16 = load i32, ptr %6, align 16, !tbaa !11
  %17 = zext i32 %16 to i64
  tail call void @tileset_unrank_init(i64 noundef %17) #4
  %18 = trunc i32 %3 to i8
  %19 = and i8 %18, 1
  %20 = sub nsw i8 0, %19
  store i8 %20, ptr %0, align 1, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 1
  %22 = insertelement <16 x i32> poison, i32 %3, i64 0
  %23 = shufflevector <16 x i32> %22, <16 x i32> poison, <16 x i32> zeroinitializer
  %24 = shl <16 x i32> %23, <i32 30, i32 29, i32 28, i32 27, i32 26, i32 25, i32 24, i32 23, i32 22, i32 21, i32 20, i32 19, i32 18, i32 17, i32 16, i32 15>
  %25 = ashr <16 x i32> %24, <i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31>
  %26 = trunc nsw <16 x i32> %25 to <16 x i8>
  store <16 x i8> %26, ptr %21, align 1, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %0, i64 17
  %28 = insertelement <8 x i32> poison, i32 %3, i64 0
  %29 = shufflevector <8 x i32> %28, <8 x i32> poison, <8 x i32> zeroinitializer
  %30 = shl <8 x i32> %29, <i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7>
  %31 = ashr <8 x i32> %30, <i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31, i32 31>
  %32 = trunc nsw <8 x i32> %31 to <8 x i8>
  store <8 x i8> %32, ptr %27, align 1, !tbaa !16
  %33 = shl i32 %3, 6
  %sext54 = ashr i32 %33, 31
  %34 = trunc nsw i32 %sext54 to i8
  %35 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 %34, ptr %35, align 1, !tbaa !16
  %36 = shl i32 %3, 5
  %sext55 = ashr i32 %36, 31
  %37 = trunc nsw i32 %sext55 to i8
  %38 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 %37, ptr %38, align 1, !tbaa !16
  %39 = shl i32 %3, 4
  %sext56 = ashr i32 %39, 31
  %40 = trunc nsw i32 %sext56 to i8
  %41 = getelementptr inbounds i8, ptr %0, i64 27
  store i8 %40, ptr %41, align 1, !tbaa !16
  %42 = shl i32 %3, 3
  %sext57 = ashr i32 %42, 31
  %43 = trunc nsw i32 %sext57 to i8
  %44 = getelementptr inbounds i8, ptr %0, i64 28
  store i8 %43, ptr %44, align 1, !tbaa !16
  %45 = shl i32 %3, 2
  %sext58 = ashr i32 %45, 31
  %46 = trunc nsw i32 %sext58 to i8
  %47 = getelementptr inbounds i8, ptr %0, i64 29
  store i8 %46, ptr %47, align 1, !tbaa !16
  %48 = shl i32 %3, 1
  %sext59 = ashr i32 %48, 31
  %49 = trunc nsw i32 %sext59 to i8
  %50 = getelementptr inbounds i8, ptr %0, i64 30
  store i8 %49, ptr %50, align 1, !tbaa !16
  %.lobit = ashr i32 %3, 31
  %51 = trunc nsw i32 %.lobit to i8
  %52 = getelementptr inbounds i8, ptr %0, i64 31
  store i8 %51, ptr %52, align 1, !tbaa !16
  %53 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 32 dereferenceable(16) %53, i8 0, i64 16, i1 false)
  %54 = tail call i32 @tileset_empty(i32 noundef %3)
  %.not28 = icmp eq i32 %54, 0
  br i1 %.not28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.130 = phi i64 [ %58, %.lr.ph ], [ 0, %2 ]
  %.02529 = phi i32 [ %60, %.lr.ph ], [ %3, %2 ]
  %55 = tail call i32 @tileset_get_least(i32 noundef %.02529)
  %56 = trunc i32 %55 to i8
  %57 = xor i8 %56, -1
  %58 = add i64 %.130, 1
  %59 = getelementptr inbounds [16 x i8], ptr %53, i64 0, i64 %.130
  store i8 %57, ptr %59, align 1, !tbaa !16
  %60 = tail call i32 @tileset_remove_least(i32 noundef %.02529)
  %61 = tail call i32 @tileset_empty(i32 noundef %60)
  %.not = icmp eq i32 %61, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %2
  %62 = load i32, ptr %4, align 32, !tbaa !5
  %63 = tail call ptr @make_index_table(i32 noundef %62)
  %64 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr %63, ptr %64, align 8, !tbaa !19
  ret void
}

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

declare void @tileset_unrank_init(i64 noundef) local_unnamed_addr #3

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 }

!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 64}
!6 = !{!"index_aux", !7, i64 0, !7, i64 32, !9, i64 48, !9, i64 52, !9, i64 56, !9, i64 60, !9, i64 64, !10, i64 72}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !9, i64 48}
!12 = !{!9, !9, i64 0}
!13 = !{!6, !9, i64 52}
!14 = !{!6, !9, i64 56}
!15 = !{!6, !9, i64 60}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 72}


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