; LLVM IR from clausecker/24puzzle :: bitpdb (bitpdb_from_pdb)

; 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.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] }
%struct.bitpdb = type { %struct.index_aux, i32, ptr, [16 x i8] }

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.bitpdb_from_pdb = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @bitpdb_allocate(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bitpdb_from_pdb(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.patterndb, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.index_aux, ptr %12, i32 0, i32 6
  %14 = load i32, ptr %13, align 32, !tbaa !9
  %15 = call ptr @bitpdb_allocate(i32 noundef %14)
  store ptr %15, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.patterndb, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %74

22:                                               ; preds = %1
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.patterndb, ptr %23, i32 0, i32 0
  %25 = call i64 @search_space_size(ptr noundef %24)
  store i64 %25, ptr %7, align 8, !tbaa !14
  %26 = load i64, ptr %7, align 8, !tbaa !14
  %27 = urem i64 %26, 8
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %22
  br label %31

30:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 216, ptr noundef @__PRETTY_FUNCTION__.bitpdb_from_pdb) #5
  unreachable

31:                                               ; preds = %29
  store i64 0, ptr %5, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %69, %31
  %33 = load i64, ptr %5, align 8, !tbaa !14
  %34 = load i64, ptr %7, align 8, !tbaa !14
  %35 = udiv i64 %34, 8
  %36 = icmp ult i64 %33, %35
  br i1 %36, label %37, label %72

37:                                               ; preds = %32
  store i8 0, ptr %8, align 1, !tbaa !16
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %38

38:                                               ; preds = %59, %37
  %39 = load i64, ptr %6, align 8, !tbaa !14
  %40 = icmp ult i64 %39, 8
  br i1 %40, label %41, label %62

41:                                               ; preds = %38
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !14
  %44 = mul i64 %43, 8
  %45 = load i64, ptr %6, align 8, !tbaa !14
  %46 = add i64 %44, %45
  %47 = getelementptr inbounds i8, ptr %42, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !16
  %49 = zext i8 %48 to i32
  %50 = ashr i32 %49, 1
  %51 = and i32 %50, 1
  %52 = load i64, ptr %6, align 8, !tbaa !14
  %53 = trunc i64 %52 to i32
  %54 = shl i32 %51, %53
  %55 = load i8, ptr %8, align 1, !tbaa !16
  %56 = zext i8 %55 to i32
  %57 = or i32 %56, %54
  %58 = trunc i32 %57 to i8
  store i8 %58, ptr %8, align 1, !tbaa !16
  br label %59

59:                                               ; preds = %41
  %60 = load i64, ptr %6, align 8, !tbaa !14
  %61 = add i64 %60, 1
  store i64 %61, ptr %6, align 8, !tbaa !14
  br label %38, !llvm.loop !17

62:                                               ; preds = %38
  %63 = load i8, ptr %8, align 1, !tbaa !16
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.bitpdb, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !19
  %67 = load i64, ptr %5, align 8, !tbaa !14
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  store i8 %63, ptr %68, align 1, !tbaa !16
  br label %69

69:                                               ; preds = %62
  %70 = load i64, ptr %5, align 8, !tbaa !14
  %71 = add i64 %70, 1
  store i64 %71, ptr %5, align 8, !tbaa !14
  br label %32, !llvm.loop !21

72:                                               ; preds = %32
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %73, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %74

74:                                               ; preds = %72, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %75 = load ptr, ptr %2, align 8
  ret ptr %75
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !12, i64 64}
!10 = !{!"patterndb", !11, i64 0, !12, i64 96, !6, i64 104}
!11 = !{!"index_aux", !7, i64 0, !7, i64 32, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 72}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 104}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 104}
!20 = !{!"bitpdb", !11, i64 0, !12, i64 96, !6, i64 104}
!21 = distinct !{!21, !18}


; 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"

@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.bitpdb_from_pdb = external hidden unnamed_addr constant [51 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @bitpdb_allocate(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @bitpdb_from_pdb(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 64
  %3 = load i32, ptr %2, align 32, !tbaa !5
  %4 = tail call ptr @bitpdb_allocate(i32 noundef %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = icmp eq ptr %4, null
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %1
  %9 = tail call i64 @search_space_size(ptr noundef nonnull %0)
  %10 = and i64 %9, 7
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.preheader23, label %21

.preheader23:                                     ; preds = %8
  %12 = lshr exact i64 %9, 3
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %.loopexit, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.preheader23
  %13 = getelementptr inbounds i8, ptr %4, i64 104
  %14 = getelementptr i8, ptr %6, i64 1
  %15 = getelementptr i8, ptr %6, i64 2
  %16 = getelementptr i8, ptr %6, i64 3
  %17 = getelementptr i8, ptr %6, i64 4
  %18 = getelementptr i8, ptr %6, i64 5
  %19 = getelementptr i8, ptr %6, i64 6
  %20 = getelementptr i8, ptr %6, i64 7
  br label %.preheader

21:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 216, ptr noundef nonnull @__PRETTY_FUNCTION__.bitpdb_from_pdb) #3
  unreachable

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.02026 = phi i64 [ 0, %.preheader.lr.ph ], [ %63, %.preheader ]
  %22 = shl nuw i64 %.02026, 3
  %23 = getelementptr i8, ptr %6, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = lshr i8 %24, 1
  %26 = and i8 %25, 1
  %27 = getelementptr i8, ptr %14, i64 %22
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = and i8 %28, 2
  %30 = or disjoint i8 %26, %29
  %31 = getelementptr i8, ptr %15, i64 %22
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = shl i8 %32, 1
  %34 = and i8 %33, 4
  %35 = or disjoint i8 %30, %34
  %36 = getelementptr i8, ptr %16, i64 %22
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = shl i8 %37, 2
  %39 = and i8 %38, 8
  %40 = or disjoint i8 %35, %39
  %41 = getelementptr i8, ptr %17, i64 %22
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = shl i8 %42, 3
  %44 = and i8 %43, 16
  %45 = or disjoint i8 %40, %44
  %46 = getelementptr i8, ptr %18, i64 %22
  %47 = load i8, ptr %46, align 1, !tbaa !13
  %48 = shl i8 %47, 4
  %49 = and i8 %48, 32
  %50 = or disjoint i8 %45, %49
  %51 = getelementptr i8, ptr %19, i64 %22
  %52 = load i8, ptr %51, align 1, !tbaa !13
  %53 = shl i8 %52, 5
  %54 = and i8 %53, 64
  %55 = or i8 %50, %54
  %56 = getelementptr i8, ptr %20, i64 %22
  %57 = load i8, ptr %56, align 1, !tbaa !13
  %58 = shl i8 %57, 6
  %59 = and i8 %58, -128
  %60 = or i8 %55, %59
  %61 = load ptr, ptr %13, align 8, !tbaa !14
  %62 = getelementptr inbounds i8, ptr %61, i64 %.02026
  store i8 %60, ptr %62, align 1, !tbaa !13
  %63 = add nuw nsw i64 %.02026, 1
  %exitcond.not = icmp eq i64 %63, %12
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %.preheader, %.preheader23, %1
  ret ptr %4
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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" }
attributes #2 = { noreturn 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 = { noreturn 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, !10, i64 64}
!6 = !{!"patterndb", !7, i64 0, !10, i64 96, !11, i64 104}
!7 = !{!"index_aux", !8, i64 0, !8, i64 32, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !11, i64 72}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 104}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !11, i64 104}
!15 = !{!"bitpdb", !7, i64 0, !10, i64 96, !11, i64 104}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass