; LLVM IR from mkazhdan/DMG :: Util/Socket.ll (ZN18SharedMemoryBufferD2Ev)

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

%class.SharedMemoryBuffer = type { ptr, ptr, i32, i32, %struct.Signal, %struct.Signal }
%struct.Signal = type { %"class.boost::mutex", i8, %"class.boost::condition_variable" }
%"class.boost::mutex" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.boost::condition_variable" = type { %union.pthread_mutex_t, %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN18SharedMemoryBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(296) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 0
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %11

7:                                                ; preds = %1
  %8 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  call void @free(ptr noundef %9) #3
  %10 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 0
  store ptr null, ptr %10, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %7, %1
  %12 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 2
  store i32 0, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  %17 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  call void @free(ptr noundef %18) #3
  %19 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 1
  store ptr null, ptr %19, align 8, !tbaa !17
  br label %20

20:                                               ; preds = %16, %11
  %21 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 3
  store i32 0, ptr %21, align 4, !tbaa !18
  %22 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 5
  call void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136) %22) #3
  %23 = getelementptr inbounds %class.SharedMemoryBuffer, ptr %3, i32 0, i32 4
  call void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136) %23) #3
  ret void
}

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

attributes #0 = { inlinehint mustprogress 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 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 = { 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 = { 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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS18SharedMemoryBuffer", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 160}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS6Signal", !13, i64 0, !14, i64 40, !15, i64 48}
!13 = !{!"_ZTSN5boost5mutexE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSN5boost18condition_variableE", !7, i64 0, !7, i64 40}
!16 = !{!10, !11, i64 16}
!17 = !{!10, !6, i64 8}
!18 = !{!10, !11, i64 20}


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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN18SharedMemoryBufferD2Ev(ptr noundef nonnull align 8 dereferenceable(296) %0) unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %4, label %3

3:                                                ; preds = %1
  tail call void @free(ptr noundef nonnull %2) #3
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %3, %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %5, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %.not2 = icmp eq ptr %7, null
  br i1 %.not2, label %9, label %8

8:                                                ; preds = %4
  tail call void @free(ptr noundef nonnull %7) #3
  store ptr null, ptr %6, align 8, !tbaa !16
  br label %9

9:                                                ; preds = %8, %4
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 0, ptr %10, align 4, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %0, i64 160
  tail call void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136) %11) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  tail call void @_ZN6SignalD2Ev(ptr noundef nonnull align 8 dereferenceable(136) %12) #3
  ret void
}

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

attributes #0 = { inlinehint mustprogress 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 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 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 #3 = { 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, !7, i64 0}
!6 = !{!"_ZTS18SharedMemoryBuffer", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS6Signal", !12, i64 0, !13, i64 40, !14, i64 48}
!12 = !{!"_ZTSN5boost5mutexE", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"_ZTSN5boost18condition_variableE", !8, i64 0, !8, i64 40}
!15 = !{!6, !10, i64 16}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !10, i64 20}


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