; LLVM IR from clausecker/24puzzle :: test (rankcount)

; 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] }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.index_aux, align 32
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 96, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 2
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str, ptr noundef %17) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %79

19:                                               ; preds = %2
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 @atoi(ptr noundef %22) #7
  store i32 %23, ptr %9, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %29, label %26

26:                                               ; preds = %19
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = icmp sge i32 %27, 25
  br i1 %28, label %29, label %35

29:                                               ; preds = %26, %19
  %30 = load ptr, ptr @stderr, align 8, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds ptr, ptr %31, i64 1
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.1, ptr noundef %33) #6
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %79

35:                                               ; preds = %26
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = call i32 @tileset_least(i32 noundef %37)
  call void @make_index_aux(ptr noundef %6, i32 noundef %38)
  store i64 0, ptr %7, align 8, !tbaa !11
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %58, %35
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.index_aux, ptr %6, i32 0, i32 3
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = zext i32 %42 to i64
  %44 = icmp ult i64 %40, %43
  br i1 %44, label %45, label %61

45:                                               ; preds = %39
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = trunc i64 %46 to i32
  %48 = call i32 @eqclass_count(ptr noundef %6, i32 noundef %47)
  %49 = zext i32 %48 to i64
  %50 = load i64, ptr %7, align 8, !tbaa !11
  %51 = icmp ugt i64 %49, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load i64, ptr %8, align 8, !tbaa !11
  %54 = trunc i64 %53 to i32
  %55 = call i32 @eqclass_count(ptr noundef %6, i32 noundef %54)
  %56 = zext i32 %55 to i64
  store i64 %56, ptr %7, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %52, %45
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %8, align 8, !tbaa !11
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !11
  br label %39, !llvm.loop !15

61:                                               ; preds = %39
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = getelementptr inbounds %struct.index_aux, ptr %6, i32 0, i32 3
  %64 = load i32, ptr %63, align 4, !tbaa !13
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds %struct.index_aux, ptr %6, i32 0, i32 4
  %67 = load i32, ptr %66, align 8, !tbaa !17
  %68 = zext i32 %67 to i64
  %69 = mul i64 %65, %68
  %70 = call i64 @search_space_size(ptr noundef %6)
  %71 = call i32 @eqclass_total(ptr noundef %6)
  %72 = uitofp i32 %71 to double
  %73 = getelementptr inbounds %struct.index_aux, ptr %6, i32 0, i32 3
  %74 = load i32, ptr %73, align 4, !tbaa !13
  %75 = uitofp i32 %74 to double
  %76 = fdiv double %72, %75
  %77 = load i64, ptr %7, align 8, !tbaa !11
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %62, i64 noundef %69, i64 noundef %70, double noundef %76, i64 noundef %77)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %79

79:                                               ; preds = %61, %29, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 96, ptr %6) #6
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #3

declare void @make_index_aux(ptr noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tileset_least(i32 noundef) #5

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

declare i32 @printf(ptr noundef, ...) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @search_space_size(ptr noundef) #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @eqclass_total(ptr noundef) #5

; 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 = { 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 #3 = { inlinehint nounwind willreturn memory(read) 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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 52}
!14 = !{!"index_aux", !7, i64 0, !7, i64 32, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !10, i64 72}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !6, i64 56}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.index_aux, align 32
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %3) #6
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #7
  br label %43

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i32 @atoi(ptr nocapture noundef %10) #8
  %or.cond = icmp ugt i32 %11, 24
  br i1 %or.cond, label %12, label %15

12:                                               ; preds = %8
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.1, ptr noundef nonnull %10) #7
  br label %43

15:                                               ; preds = %8
  %16 = add nuw nsw i32 %11, 1
  %17 = tail call i32 @tileset_least(i32 noundef %16)
  call void @make_index_aux(ptr noundef nonnull %3, i32 noundef %17) #6
  %18 = getelementptr inbounds i8, ptr %3, i64 52
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %27
  %.01521 = phi i64 [ %28, %27 ], [ 0, %15 ]
  %.01620 = phi i64 [ %.1, %27 ], [ 0, %15 ]
  %20 = trunc nuw i64 %.01521 to i32
  %21 = call i32 @eqclass_count(ptr noundef nonnull %3, i32 noundef %20)
  %22 = zext i32 %21 to i64
  %23 = icmp ult i64 %.01620, %22
  br i1 %23, label %24, label %27

24:                                               ; preds = %.lr.ph
  %25 = call i32 @eqclass_count(ptr noundef nonnull %3, i32 noundef %20)
  %26 = zext i32 %25 to i64
  br label %27

27:                                               ; preds = %.lr.ph, %24
  %.1 = phi i64 [ %26, %24 ], [ %.01620, %.lr.ph ]
  %28 = add nuw nsw i64 %.01521, 1
  %29 = load i32, ptr %18, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %27, %15
  %.016.lcssa = phi i64 [ 0, %15 ], [ %.1, %27 ]
  %.lcssa = phi i64 [ 0, %15 ], [ %30, %27 ]
  %32 = getelementptr inbounds i8, ptr %3, i64 56
  %33 = load i32, ptr %32, align 8, !tbaa !14
  %34 = zext i32 %33 to i64
  %35 = mul nuw i64 %.lcssa, %34
  %36 = call i64 @search_space_size(ptr noundef nonnull %3)
  %37 = call i32 @eqclass_total(ptr noundef nonnull %3)
  %38 = uitofp i32 %37 to double
  %39 = load i32, ptr %18, align 4, !tbaa !9
  %40 = uitofp i32 %39 to double
  %41 = fdiv double %38, %40
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %11, i64 noundef %35, i64 noundef %36, double noundef %41, i64 noundef %.016.lcssa)
  br label %43

43:                                               ; preds = %._crit_edge, %12, %4
  %.0 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 0, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %3) #6
  ret i32 %.0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

declare void @make_index_aux(ptr noundef, i32 noundef) local_unnamed_addr #4

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @eqclass_total(ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree 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 #3 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { nounwind willreturn memory(read) }

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


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