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

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

@stderr = external global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19FixedIOClientStream4InitEP11_FileHandleiii(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8
  %12 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %5
  %16 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  call void @free(ptr noundef %17) #4
  %18 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 2
  store ptr null, ptr %18, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %15, %5
  %20 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  call void @free(ptr noundef %25) #4
  %26 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 3
  store ptr null, ptr %26, align 8, !tbaa !17
  br label %27

27:                                               ; preds = %23, %19
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 8
  store ptr %28, ptr %29, align 8, !tbaa !18
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 4
  store i32 %30, ptr %31, align 8, !tbaa !19
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 5
  store i32 %32, ptr %33, align 4, !tbaa !20
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 7
  store i32 %34, ptr %35, align 4, !tbaa !21
  %36 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 7
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %38 = sext i32 %37 to i64
  %39 = call noundef ptr @_Z12AllocPointerIiEPT_m(i64 noundef %38)
  %40 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 2
  store ptr %39, ptr %40, align 8, !tbaa !11
  %41 = getelementptr inbounds %class.FixedIOClientStream, ptr %11, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = icmp ne ptr %42, null
  br i1 %43, label %47, label %44

44:                                               ; preds = %27
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.19) #4
  call void @exit(i32 noundef 0) #5
  unreachable

47:                                               ; preds = %27
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z12AllocPointerIiEPT_m(i64 noundef) #3

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


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [39 x i8], align 1

; 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN19FixedIOClientStream4InitEP11_FileHandleiii(ptr nocapture noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #3 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 136
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %9, label %8

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

9:                                                ; preds = %8, %5
  %10 = getelementptr inbounds i8, ptr %0, i64 144
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not5 = icmp eq ptr %11, null
  br i1 %.not5, label %13, label %12

12:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %11) #4
  store ptr null, ptr %10, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %12, %9
  %14 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr %1, ptr %14, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 152
  store i32 %3, ptr %15, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 156
  store i32 %2, ptr %16, align 4, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %0, i64 164
  store i32 %4, ptr %17, align 4, !tbaa !19
  %18 = sext i32 %4 to i64
  %19 = tail call noundef ptr @_Z12AllocPointerIiEPT_m(i64 noundef %18)
  store ptr %19, ptr %6, align 8, !tbaa !5
  %.not6 = icmp eq ptr %19, null
  br i1 %.not6, label %20, label %23

20:                                               ; preds = %13
  %21 = load ptr, ptr @stderr, align 8, !tbaa !20
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.19) #5
  tail call void @exit(i32 noundef 0) #6
  unreachable

23:                                               ; preds = %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z12AllocPointerIiEPT_m(i64 noundef) local_unnamed_addr #3

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 = { nofree 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 #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 = { 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 #4 = { nounwind }
attributes #5 = { cold nounwind }
attributes #6 = { 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, !14, i64 136}
!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, !14, i64 144}
!16 = !{!6, !14, i64 168}
!17 = !{!6, !13, i64 152}
!18 = !{!6, !13, i64 156}
!19 = !{!6, !13, i64 164}
!20 = !{!14, !14, i64 0}


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