; LLVM IR from clausecker/24puzzle :: catalogue (catalogue_diff_hvals)

; 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.pdb_catalogue = type { [64 x %struct.heuristic], [64 x i32], [64 x i64], i64, i64 }
%struct.heuristic = type { ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.partial_hvals = type { [64 x i8] }

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

; 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 @heu_hval(ptr noundef, ptr noundef) #1

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

10:                                               ; preds = %39, %4
  %11 = load i64, ptr %9, align 8, !tbaa !11
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.pdb_catalogue, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %16, label %42

16:                                               ; preds = %10
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.pdb_catalogue, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %9, align 8, !tbaa !11
  %20 = getelementptr inbounds [64 x i32], ptr %18, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = call i32 @tileset_has(i32 noundef %21, i32 noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %38

25:                                               ; preds = %16
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.pdb_catalogue, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [64 x %struct.heuristic], ptr %27, i64 0, i64 0
  %29 = load i64, ptr %9, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.heuristic, ptr %28, i64 %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call i32 @heu_hval(ptr noundef %30, ptr noundef %31)
  %33 = trunc i32 %32 to i8
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.partial_hvals, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %9, align 8, !tbaa !11
  %37 = getelementptr inbounds [64 x i8], ptr %35, i64 0, i64 %36
  store i8 %33, ptr %37, align 1, !tbaa !15
  br label %38

38:                                               ; preds = %25, %16
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %9, align 8, !tbaa !11
  %41 = add i64 %40, 1
  store i64 %41, ptr %9, align 8, !tbaa !11
  br label %10, !llvm.loop !16

42:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

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

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 3840}
!14 = !{!"pdb_catalogue", !7, i64 0, !7, i64 3072, !7, i64 3328, !12, i64 3840, !12, i64 3848}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.heuristic = type { ptr, ptr, ptr, ptr, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local void @catalogue_diff_hvals(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %1, i64 3840
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not11 = icmp eq i64 %6, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %7 = getelementptr inbounds i8, ptr %1, i64 3072
  br label %8

8:                                                ; preds = %.lr.ph, %17
  %.010 = phi i64 [ 0, %.lr.ph ], [ %18, %17 ]
  %9 = getelementptr inbounds [64 x i32], ptr %7, i64 0, i64 %.010
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = tail call i32 @tileset_has(i32 noundef %10, i32 noundef %3)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %17, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds %struct.heuristic, ptr %1, i64 %.010
  %14 = tail call i32 @heu_hval(ptr noundef %13, ptr noundef %2)
  %15 = trunc i32 %14 to i8
  %16 = getelementptr inbounds [64 x i8], ptr %0, i64 0, i64 %.010
  store i8 %15, ptr %16, align 1, !tbaa !12
  br label %17

17:                                               ; preds = %8, %12
  %18 = add nuw i64 %.010, 1
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %8, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %17, %4
  ret void
}

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

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 3840}
!6 = !{!"pdb_catalogue", !7, i64 0, !7, i64 3072, !7, i64 3328, !9, i64 3840, !9, i64 3848}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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