; LLVM IR from clausecker/24puzzle :: pdb (pdb_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.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] }

; Function Attrs: nounwind uwtable
declare dso_local ptr @pdb_dummy(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: inlinehint nounwind uwtable
declare hidden i64 @search_space_size(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @pdb_mmap(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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) #5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = call ptr @pdb_dummy(i32 noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %15, label %19 [
    i32 0, label %16
    i32 1, label %17
    i32 2, label %18
  ]

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

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

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

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

21:                                               ; preds = %18, %17, %16
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %49

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

41:                                               ; preds = %25
  %42 = call ptr @__errno_location() #6
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %11, align 4, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %44) #5
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = call ptr @__errno_location() #6
  store i32 %45, ptr %46, align 4, !tbaa !5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %49

47:                                               ; preds = %25
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %48, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %49

49:                                               ; preds = %47, %41, %24, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %50 = load ptr, ptr %4, align 8
  ret ptr %50
}

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

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 = { 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 = { 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 }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"patterndb", !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.pdb_mmap = private unnamed_addr constant [3 x i32] [i32 1, i32 3, i32 3], align 4
@switch.table.pdb_mmap.1 = private unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 1], align 4

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

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

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

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

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

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

switch.lookup:                                    ; preds = %3
  %8 = icmp eq ptr %4, null
  br i1 %8, label %20, label %9

9:                                                ; preds = %switch.lookup
  %10 = zext nneg i32 %2 to i64
  %switch.gep16 = getelementptr inbounds [3 x i32], ptr @switch.table.pdb_mmap.1, i64 0, i64 %10
  %switch.load17 = load i32, ptr %switch.gep16, align 4
  %11 = zext nneg i32 %2 to i64
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table.pdb_mmap, i64 0, i64 %11
  %switch.load = load i32, ptr %switch.gep, align 4
  %12 = getelementptr inbounds i8, ptr %4, i64 96
  store i32 1, ptr %12, align 32, !tbaa !9
  %13 = tail call i64 @search_space_size(ptr noundef nonnull %4)
  %14 = tail call ptr @mmap(ptr noundef null, i64 noundef %13, i32 noundef %switch.load, i32 noundef %switch.load17, i32 noundef %1, i64 noundef 0) #6
  %15 = getelementptr inbounds i8, ptr %4, 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 = %9
  %18 = tail call ptr @__errno_location() #5
  %19 = load i32, ptr %18, align 4, !tbaa !5
  tail call void @free(ptr noundef nonnull %4) #6
  store i32 %19, ptr %18, align 4, !tbaa !5
  br label %20

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

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

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 = { 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 #3 = { 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 #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 willreturn memory(none) }
attributes #6 = { 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 = !{!"patterndb", !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,SROAPass,SimplifyCFGPass,TailCallElimPass