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

; 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] }
%struct.index = type { i32, i32, i32 }
%struct.index_table = type { [25 x i8], i8, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @compute_index(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.index_aux, ptr %9, i32 0, i32 6
  %11 = load i32, ptr %10, align 32, !tbaa !9
  %12 = call i32 @tileset_remove(i32 noundef %11, i32 noundef 0)
  store i32 %12, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call i32 @tile_map(ptr noundef %13, ptr noundef %14)
  store i32 %15, ptr %8, align 4, !tbaa !12
  %16 = load i32, ptr %8, align 4, !tbaa !12
  %17 = call i32 @tileset_rank(i32 noundef %16)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.index, ptr %18, i32 0, i32 1
  store i32 %17, ptr %19, align 4, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.index_aux, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.index, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %struct.index_table, ptr %22, i64 %26
  call void @prefetch(ptr noundef %27)
  %28 = load i32, ptr %7, align 4, !tbaa !12
  %29 = load i32, ptr %8, align 4, !tbaa !12
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 @index_permutation(i32 noundef %28, i32 noundef %29, ptr noundef %30)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.index, ptr %32, i32 0, i32 0
  store i32 %31, ptr %33, align 4, !tbaa !16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.index_aux, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 32, !tbaa !9
  %37 = call i32 @tileset_has(i32 noundef %36, i32 noundef 0)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %56

39:                                               ; preds = %3
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.index_aux, ptr %40, i32 0, i32 7
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.index, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.index_table, ptr %42, i64 %46
  %48 = getelementptr inbounds %struct.index_table, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i64 @zero_location(ptr noundef %49)
  %51 = getelementptr inbounds [25 x i8], ptr %48, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !17
  %53 = sext i8 %52 to i32
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.index, ptr %54, i32 0, i32 2
  store i32 %53, ptr %55, align 4, !tbaa !18
  br label %59

56:                                               ; preds = %3
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.index, ptr %57, i32 0, i32 2
  store i32 -1, ptr %58, align 4, !tbaa !18
  br label %59

59:                                               ; preds = %56, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; 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_remove(i32 noundef, i32 noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @index_permutation(i32 noundef, i32 noundef, ptr noundef) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @zero_location(ptr 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, !11, i64 64}
!10 = !{!"index_aux", !7, i64 0, !7, i64 32, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !6, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 4}
!14 = !{!"index", !11, i64 0, !11, i64 4, !11, i64 8}
!15 = !{!10, !6, i64 72}
!16 = !{!14, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !11, i64 8}


; 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.index_table = type { [25 x i8], i8, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @compute_index(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i32, ptr %4, align 32, !tbaa !5
  %6 = tail call i32 @tileset_remove(i32 noundef %5, i32 noundef 0)
  %7 = tail call i32 @tile_map(ptr noundef %0, ptr noundef %2)
  %8 = tail call i32 @tileset_rank(i32 noundef %7)
  %9 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %8, ptr %9, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = zext i32 %8 to i64
  %13 = getelementptr inbounds %struct.index_table, ptr %11, i64 %12
  tail call void @prefetch(ptr noundef %13)
  %14 = tail call i32 @index_permutation(i32 noundef %6, i32 noundef %7, ptr noundef %2)
  store i32 %14, ptr %1, align 4, !tbaa !14
  %15 = load i32, ptr %4, align 32, !tbaa !5
  %16 = tail call i32 @tileset_has(i32 noundef %15, i32 noundef 0)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %26, label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr %10, align 8, !tbaa !13
  %19 = load i32, ptr %9, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %struct.index_table, ptr %18, i64 %20
  %22 = tail call i64 @zero_location(ptr noundef %2)
  %23 = getelementptr inbounds [25 x i8], ptr %21, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !15
  %25 = sext i8 %24 to i32
  br label %26

26:                                               ; preds = %3, %17
  %.sink = phi i32 [ %25, %17 ], [ -1, %3 ]
  %27 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %.sink, ptr %27, align 4
  ret void
}

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

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

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

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

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

; 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 i64 @zero_location(ptr 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, !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 = !{!12, !9, i64 4}
!12 = !{!"index", !9, i64 0, !9, i64 4, !9, i64 8}
!13 = !{!6, !10, i64 72}
!14 = !{!12, !9, i64 0}
!15 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass