; LLVM IR from mkazhdan/DMG :: Util/MultiStreamIO.ll (ZN19FixedIOClientStream5UnsetEv)

; 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.FixedIOClientStream = type { %class.IOClient, i32, ptr, ptr, i32, i32, i32, i32, ptr, i8, i32, i32, i32 }
%class.IOClient = type { ptr, %"class.boost::recursive_timed_mutex", ptr }
%"class.boost::recursive_timed_mutex" = type <{ %union.pthread_mutex_t, %union.pthread_cond_t, i8, [7 x i8], i64, i32, [4 x i8] }>
%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 }
%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: nounwind
declare void @free(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN19FixedIOClientStream5UnsetEv(ptr noundef nonnull align 8 dereferenceable(192) %0) #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.FixedIOClientStream, ptr %3, i32 0, i32 9
  store i8 0, ptr %4, align 8, !tbaa !9
  %5 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 6
  store i32 0, ptr %5, align 8, !tbaa !16
  %6 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 1
  store i32 0, ptr %6, align 8, !tbaa !17
  %7 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !18
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %1
  %11 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  call void @free(ptr noundef %12) #2
  %13 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 3
  store ptr null, ptr %13, align 8, !tbaa !18
  br label %14

14:                                               ; preds = %10, %1
  %15 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 10
  store i32 0, ptr %15, align 4, !tbaa !19
  %16 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 12
  store i32 0, ptr %16, align 4, !tbaa !20
  %17 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 6
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 11
  store i32 %18, ptr %19, align 8, !tbaa !21
  %20 = getelementptr inbounds %class.FixedIOClientStream, ptr %3, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  %22 = getelementptr inbounds i32, ptr %21, i64 0
  store i32 0, ptr %22, align 4, !tbaa !23
  ret void
}

attributes #0 = { 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 #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 }

!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, !13, i64 176}
!10 = !{!"_ZTS19FixedIOClientStream", !11, i64 0, !15, i64 128, !6, i64 136, !6, i64 144, !15, i64 152, !15, i64 156, !15, i64 160, !15, i64 164, !6, i64 168, !13, i64 176, !15, i64 180, !15, i64 184, !15, i64 188}
!11 = !{!"_ZTS8IOClient", !12, i64 8, !6, i64 120}
!12 = !{!"_ZTSN5boost21recursive_timed_mutexE", !7, i64 0, !7, i64 40, !13, i64 88, !14, i64 96, !15, i64 104}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !15, i64 160}
!17 = !{!10, !15, i64 128}
!18 = !{!10, !6, i64 144}
!19 = !{!10, !15, i64 180}
!20 = !{!10, !15, i64 188}
!21 = !{!10, !15, i64 184}
!22 = !{!10, !6, i64 136}
!23 = !{!15, !15, i64 0}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @_ZN19FixedIOClientStream5UnsetEv(ptr nocapture noundef nonnull align 8 dereferenceable(192) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 176
  store i8 0, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 0, ptr %3, align 8, !tbaa !15
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 0, ptr %4, align 8, !tbaa !16
  %5 = getelementptr inbounds i8, ptr %0, i64 144
  %6 = load ptr, ptr %5, align 8, !tbaa !17
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %1
  tail call void @free(ptr noundef nonnull %6) #2
  store ptr null, ptr %5, align 8, !tbaa !17
  %.pre = load i32, ptr %3, align 8, !tbaa !15
  br label %8

8:                                                ; preds = %7, %1
  %9 = phi i32 [ %.pre, %7 ], [ 0, %1 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 180
  store i32 0, ptr %10, align 4, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %0, i64 188
  store i32 0, ptr %11, align 4, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %0, i64 184
  store i32 %9, ptr %12, align 8, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  store i32 0, ptr %14, align 4, !tbaa !22
  ret void
}

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn 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 }

!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, !11, i64 176}
!6 = !{!"_ZTS19FixedIOClientStream", !7, i64 0, !13, i64 128, !14, i64 136, !14, i64 144, !13, i64 152, !13, i64 156, !13, i64 160, !13, i64 164, !14, i64 168, !11, i64 176, !13, i64 180, !13, i64 184, !13, i64 188}
!7 = !{!"_ZTS8IOClient", !8, i64 8, !14, i64 120}
!8 = !{!"_ZTSN5boost21recursive_timed_mutexE", !9, i64 0, !9, i64 40, !11, i64 88, !12, i64 96, !13, i64 104}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!6, !13, i64 160}
!16 = !{!6, !13, i64 128}
!17 = !{!6, !14, i64 144}
!18 = !{!6, !13, i64 180}
!19 = !{!6, !13, i64 188}
!20 = !{!6, !13, i64 184}
!21 = !{!6, !14, i64 136}
!22 = !{!13, !13, i64 0}


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