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

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

; 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: inlinehint nounwind uwtable
declare hidden i32 @tile_map(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @zero_location(ptr 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_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
define dso_local i32 @puzzle_partially_equal(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.index_aux, ptr %12, i32 0, i32 6
  %14 = load i32, ptr %13, align 32, !tbaa !9
  %15 = call i32 @tileset_remove(i32 noundef %14, i32 noundef 0)
  store i32 %15, ptr %10, align 4, !tbaa !12
  br label %16

16:                                               ; preds = %40, %3
  %17 = load i32, ptr %10, align 4, !tbaa !12
  %18 = call i32 @tileset_empty(i32 noundef %17)
  %19 = icmp ne i32 %18, 0
  %20 = xor i1 %19, true
  br i1 %20, label %21, label %43

21:                                               ; preds = %16
  %22 = load i32, ptr %10, align 4, !tbaa !12
  %23 = call i32 @tileset_get_least(i32 noundef %22)
  %24 = zext i32 %23 to i64
  store i64 %24, ptr %9, align 8, !tbaa !13
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.puzzle, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %9, align 8, !tbaa !13
  %28 = getelementptr inbounds [25 x i8], ptr %26, i64 0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !15
  %30 = zext i8 %29 to i32
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.puzzle, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %9, align 8, !tbaa !13
  %34 = getelementptr inbounds [25 x i8], ptr %32, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !15
  %36 = zext i8 %35 to i32
  %37 = icmp ne i32 %30, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

39:                                               ; preds = %21
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %10, align 4, !tbaa !12
  %42 = call i32 @tileset_remove_least(i32 noundef %41)
  store i32 %42, ptr %10, align 4, !tbaa !12
  br label %16, !llvm.loop !16

43:                                               ; preds = %16
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.index_aux, ptr %44, i32 0, i32 6
  %46 = load i32, ptr %45, align 32, !tbaa !9
  %47 = call i32 @tileset_has(i32 noundef %46, i32 noundef 0)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  store i32 1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

50:                                               ; preds = %43
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.index_aux, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = call i32 @tile_map(ptr noundef %54, ptr noundef %55)
  %57 = call i32 @tileset_rank(i32 noundef %56)
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds %struct.index_table, ptr %53, i64 %58
  %60 = getelementptr inbounds %struct.index_table, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds [25 x i8], ptr %60, i64 0, i64 0
  store ptr %61, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i64 @zero_location(ptr noundef %63)
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !15
  %67 = sext i8 %66 to i32
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = call i64 @zero_location(ptr noundef %69)
  %71 = getelementptr inbounds i8, ptr %68, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !15
  %73 = sext i8 %72 to i32
  %74 = icmp eq i32 %67, %73
  %75 = zext i1 %74 to i32
  store i32 %75, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %76

76:                                               ; preds = %50, %49, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %77 = load i32, ptr %4, align 4
  ret i32 %77
}

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 = { 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, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !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"

%struct.index_table = type { [25 x i8], i8, i32 }

; 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 @tile_map(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; 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
define dso_local range(i32 0, 2) i32 @puzzle_partially_equal(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %2, 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 @tileset_empty(i32 noundef %6)
  %.not19 = icmp eq i32 %7, 0
  br i1 %.not19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %14
  %.020 = phi i32 [ %15, %14 ], [ %6, %3 ]
  %8 = tail call i32 @tileset_get_least(i32 noundef %.020)
  %9 = zext i32 %8 to i64
  %10 = getelementptr inbounds [25 x i8], ptr %0, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = getelementptr inbounds [25 x i8], ptr %1, i64 0, i64 %9
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %.not18 = icmp eq i8 %11, %13
  br i1 %.not18, label %14, label %.loopexit

14:                                               ; preds = %.lr.ph
  %15 = tail call i32 @tileset_remove_least(i32 noundef %.020)
  %16 = tail call i32 @tileset_empty(i32 noundef %15)
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %14, %3
  %17 = load i32, ptr %4, align 32, !tbaa !5
  %18 = tail call i32 @tileset_has(i32 noundef %17, i32 noundef 0)
  %.not17 = icmp eq i32 %18, 0
  br i1 %.not17, label %.loopexit, label %19

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %2, i64 72
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = tail call i32 @tile_map(ptr noundef nonnull %2, ptr noundef %0)
  %23 = tail call i32 @tileset_rank(i32 noundef %22)
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.index_table, ptr %21, i64 %24
  %26 = tail call i64 @zero_location(ptr noundef %0)
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = tail call i64 @zero_location(ptr noundef %1)
  %30 = getelementptr inbounds i8, ptr %25, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = icmp eq i8 %28, %31
  %33 = zext i1 %32 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %19
  %.016 = phi i32 [ %33, %19 ], [ 1, %._crit_edge ], [ 0, %.lr.ph ]
  ret i32 %.016
}

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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !10, i64 72}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass