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

; 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.bitpdb = 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] }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bitpdb_mmap(i32 noundef %0, i32 noundef %1, i32 noundef %2) #6 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %13 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %13, label %17 [
    i32 0, label %14
    i32 1, label %15
    i32 2, label %16
  ]

14:                                               ; preds = %3
  store i32 1, ptr %9, align 4, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %19

15:                                               ; preds = %3
  store i32 3, ptr %9, align 4, !tbaa !5
  store i32 2, ptr %10, align 4, !tbaa !5
  br label %19

16:                                               ; preds = %3
  store i32 3, ptr %9, align 4, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %19

17:                                               ; preds = %3
  %18 = call ptr @__errno_location() #8
  store i32 22, ptr %18, align 4, !tbaa !5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %51

19:                                               ; preds = %16, %15, %14
  %20 = call noalias ptr @malloc(i64 noundef 128) #9
  store ptr %20, ptr %8, align 8, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %51

24:                                               ; preds = %19
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.bitpdb, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %5, align 4, !tbaa !5
  call void @make_index_aux(ptr noundef %26, i32 noundef %27)
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.bitpdb, ptr %28, i32 0, i32 1
  store i32 1, ptr %29, align 32, !tbaa !11
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.bitpdb, ptr %30, i32 0, i32 0
  %32 = call i64 @bitpdb_size(ptr noundef %31)
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = call ptr @mmap(ptr noundef null, i64 noundef %32, i32 noundef %33, i32 noundef %34, i32 noundef %35, i64 noundef 0) #7
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.bitpdb, ptr %37, i32 0, i32 2
  store ptr %36, ptr %38, align 8, !tbaa !14
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.bitpdb, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = icmp eq ptr %41, inttoptr (i64 -1 to ptr)
  br i1 %42, label %43, label %49

43:                                               ; preds = %24
  %44 = call ptr @__errno_location() #8
  %45 = load i32, ptr %44, align 4, !tbaa !5
  store i32 %45, ptr %11, align 4, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %46) #7
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = call ptr @__errno_location() #8
  store i32 %47, ptr %48, align 4, !tbaa !5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %51

49:                                               ; preds = %24
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %50, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %51

51:                                               ; preds = %49, %43, %23, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %52 = load ptr, ptr %4, align 8
  ret ptr %52
}

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { "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 willreturn memory(none) "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 "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 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { nounwind allocsize(0) }

!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, !6, i64 96}
!12 = !{!"bitpdb", !13, i64 0, !6, i64 96, !10, i64 104}
!13 = !{!"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}
!14 = !{!12, !10, i64 104}


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

@switch.table.bitpdb_mmap = private unnamed_addr constant [3 x i32] [i32 1, i32 3, i32 3], align 4
@switch.table.bitpdb_mmap.1 = private unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 1], align 4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @bitpdb_mmap(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #5 {
  %4 = icmp ult i32 %2, 3
  br i1 %4, label %switch.lookup, label %5

5:                                                ; preds = %3
  %6 = tail call ptr @__errno_location() #7
  store i32 22, ptr %6, align 4, !tbaa !5
  br label %20

switch.lookup:                                    ; preds = %3
  %7 = zext nneg i32 %2 to i64
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table.bitpdb_mmap, i64 0, i64 %7
  %switch.load = load i32, ptr %switch.gep, align 4
  %8 = zext nneg i32 %2 to i64
  %switch.gep17 = getelementptr inbounds [3 x i32], ptr @switch.table.bitpdb_mmap.1, i64 0, i64 %8
  %switch.load18 = load i32, ptr %switch.gep17, align 4
  %9 = tail call noalias dereferenceable_or_null(128) ptr @malloc(i64 noundef 128) #8
  %10 = icmp eq ptr %9, null
  br i1 %10, label %20, label %11

11:                                               ; preds = %switch.lookup
  tail call void @make_index_aux(ptr noundef nonnull %9, i32 noundef %0) #9
  %12 = getelementptr inbounds i8, ptr %9, i64 96
  store i32 1, ptr %12, align 32, !tbaa !9
  %13 = tail call i64 @bitpdb_size(ptr noundef nonnull %9)
  %14 = tail call ptr @mmap(ptr noundef null, i64 noundef %13, i32 noundef %switch.load, i32 noundef %switch.load18, i32 noundef %1, i64 noundef 0) #9
  %15 = getelementptr inbounds i8, ptr %9, i64 104
  store ptr %14, ptr %15, align 8, !tbaa !13
  %16 = icmp eq ptr %14, inttoptr (i64 -1 to ptr)
  br i1 %16, label %17, label %20

17:                                               ; preds = %11
  %18 = tail call ptr @__errno_location() #7
  %19 = load i32, ptr %18, align 4, !tbaa !5
  tail call void @free(ptr noundef nonnull %9) #9
  store i32 %19, ptr %18, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %11, %switch.lookup, %17, %5
  %.0 = phi ptr [ null, %5 ], [ null, %17 ], [ null, %switch.lookup ], [ %9, %11 ]
  ret ptr %.0
}

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #6

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 "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 #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 96}
!10 = !{!"bitpdb", !11, i64 0, !6, i64 96, !12, i64 104}
!11 = !{!"index_aux", !7, i64 0, !7, i64 32, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !12, i64 72}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 104}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass