; LLVM IR from clausecker/24puzzle :: pdbgen (pdb_generate)

; 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.puzzle = type { [25 x i8], [7 x i8], [25 x i8], [7 x i8] }
%struct.pdbgen_config = type { %struct.parallel_config, i64, i32 }
%struct.parallel_config = type { ptr, i32, ptr }
%struct.index = type { i32, i32, i32 }
%struct.patterndb = type { %struct.index_aux, i32, ptr, [16 x i8] }
%struct.index_aux = type { [32 x i8], [16 x i8], i32, i32, i32, i32, i32, ptr, [16 x i8] }

@solved_puzzle = external constant %struct.puzzle, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @pdb_generate(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.pdbgen_config, align 8
  %6 = alloca %struct.index, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 0
  %9 = getelementptr inbounds %struct.parallel_config, ptr %8, i32 0, i32 0
  store ptr %7, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 0
  %11 = getelementptr inbounds %struct.parallel_config, ptr %10, i32 0, i32 2
  store ptr @generate_cohort, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 2
  store i32 0, ptr %12, align 8, !tbaa !14
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @pdb_clear(ptr noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.patterndb, ptr %14, i32 0, i32 0
  call void @compute_index(ptr noundef %15, ptr noundef %6, ptr noundef @solved_puzzle)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  call void @pdb_update(ptr noundef %16, ptr noundef %6, i32 noundef 0)
  br label %17

17:                                               ; preds = %34, %2
  %18 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 1
  store atomic i64 0, ptr %18 seq_cst, align 8, !tbaa !15
  %19 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !14
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 8, !tbaa !14
  %22 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 0
  call void @pdb_iterate_parallel(ptr noundef %22)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %33

25:                                               ; preds = %17
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = sub nsw i32 %28, 1
  %30 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 1
  %31 = load atomic i64, ptr %30 seq_cst, align 8, !tbaa !15
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str, i32 noundef %29, i64 noundef %31) #5
  br label %33

33:                                               ; preds = %25, %17
  br label %34

34:                                               ; preds = %33
  %35 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 1
  %36 = load atomic i64, ptr %35 seq_cst, align 8, !tbaa !15
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %17, label %38, !llvm.loop !16

38:                                               ; preds = %34
  %39 = getelementptr inbounds %struct.pdbgen_config, ptr %5, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #5
  ret i32 %40
}

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

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

declare void @pdb_clear(ptr noundef) #2

declare void @compute_index(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdb_update(ptr noundef, ptr noundef, i32 noundef) #3

declare void @pdb_iterate_parallel(ptr noundef) #2

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

; 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 = { "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 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 = { 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 #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, !6, i64 0}
!10 = !{!"pdbgen_config", !11, i64 0, !7, i64 24, !12, i64 32}
!11 = !{!"parallel_config", !6, i64 0, !7, i64 8, !6, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !12, i64 32}
!15 = !{!10, !7, i64 24}
!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.puzzle = type { [25 x i8], [7 x i8], [25 x i8], [7 x i8] }
%struct.pdbgen_config = type { %struct.parallel_config, i64, i32 }
%struct.parallel_config = type { ptr, i32, ptr }
%struct.index = type { i32, i32, i32 }

@solved_puzzle = external constant %struct.puzzle, align 8
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @pdb_generate(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.pdbgen_config, align 8
  %4 = alloca %struct.index, align 4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #5
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr @generate_cohort, ptr %5, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %6, align 8, !tbaa !13
  tail call void @pdb_clear(ptr noundef %0) #5
  call void @compute_index(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull @solved_puzzle) #5
  call void @pdb_update(ptr noundef %0, ptr noundef nonnull %4, i32 noundef 0)
  %7 = getelementptr inbounds i8, ptr %3, i64 24
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %2, %.split.us
  store atomic i64 0, ptr %7 seq_cst, align 8, !tbaa !14
  %8 = load i32, ptr %6, align 8, !tbaa !13
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %6, align 8, !tbaa !13
  call void @pdb_iterate_parallel(ptr noundef nonnull %3) #5
  %10 = load atomic i64, ptr %7 seq_cst, align 8, !tbaa !14
  %.not6.us = icmp eq i64 %10, 0
  br i1 %.not6.us, label %.split8.us, label %.split.us, !llvm.loop !15

.split:                                           ; preds = %2, %.split
  store atomic i64 0, ptr %7 seq_cst, align 8, !tbaa !14
  %11 = load i32, ptr %6, align 8, !tbaa !13
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %6, align 8, !tbaa !13
  call void @pdb_iterate_parallel(ptr noundef nonnull %3) #5
  %13 = load i32, ptr %6, align 8, !tbaa !13
  %14 = add nsw i32 %13, -1
  %15 = load atomic i64, ptr %7 seq_cst, align 8, !tbaa !14
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str, i32 noundef %14, i64 noundef %15) #5
  %17 = load atomic i64, ptr %7 seq_cst, align 8, !tbaa !14
  %.not6 = icmp eq i64 %17, 0
  br i1 %.not6, label %.split8.us, label %.split, !llvm.loop !15

.split8.us:                                       ; preds = %.split, %.split.us
  %18 = load i32, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #5
  ret i32 %18
}

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

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

declare void @pdb_clear(ptr noundef) local_unnamed_addr #2

declare void @compute_index(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdb_update(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @pdb_iterate_parallel(ptr noundef) local_unnamed_addr #2

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

; 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 = { "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 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 = { 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 #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, !8, i64 0}
!6 = !{!"pdbgen_config", !7, i64 0, !9, i64 24, !11, i64 32}
!7 = !{!"parallel_config", !8, i64 0, !9, i64 8, !8, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 16}
!13 = !{!6, !11, i64 32}
!14 = !{!6, !9, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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