; LLVM IR from modlfo/AudioEngine :: AudioEngine/Source/Server.ll (ZN17ServerConnections3runEv)

; 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.ServerConnections = type { %"class.juce::Thread.base", ptr, ptr }
%"class.juce::Thread.base" = type <{ ptr, %"class.juce::String", ptr, ptr, %"class.juce::CriticalSection", %"class.juce::WaitableEvent", %"class.juce::WaitableEvent", i32, [4 x i8], i64, i32, i8 }>
%"class.juce::String" = type { %"class.juce::CharPointer_UTF8" }
%"class.juce::CharPointer_UTF8" = type { ptr }
%"class.juce::CriticalSection" = 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.juce::WaitableEvent" = type <{ %union.pthread_cond_t, %union.pthread_mutex_t, i8, i8, [6 x i8] }>
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17ServerConnections3runEv(ptr noundef nonnull align 8 dereferenceable(304) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  br label %5

5:                                                ; preds = %28, %1
  %6 = call noundef zeroext i1 @_ZNK4juce6Thread16threadShouldExitEv(ptr noundef nonnull align 8 dereferenceable(285) %4)
  br i1 %6, label %11, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds %class.ServerConnections, ptr %4, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br label %11

11:                                               ; preds = %7, %5
  %12 = phi i1 [ false, %5 ], [ %10, %7 ]
  br i1 %12, label %13, label %29

13:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %14 = getelementptr inbounds %class.ServerConnections, ptr %4, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call noundef ptr @_ZNK4juce15StreamingSocket21waitForNextConnectionEv(ptr noundef nonnull align 8 dereferenceable(64) %15)
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %28

19:                                               ; preds = %13
  %20 = getelementptr inbounds %class.ServerConnections, ptr %4, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = getelementptr inbounds %class.ServerConnections, ptr %4, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call noundef ptr @_ZN4juce10OwnedArrayINS_15StreamingSocketENS_20DummyCriticalSectionEE3addEPS1_(ptr noundef nonnull align 8 dereferenceable(20) %25, ptr noundef %26) #4
  br label %28

28:                                               ; preds = %23, %19, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %5, !llvm.loop !20

29:                                               ; preds = %11
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce6Thread16threadShouldExitEv(ptr noundef nonnull align 8 dereferenceable(285)) #2 align 2

declare noundef ptr @_ZNK4juce15StreamingSocket21waitForNextConnectionEv(ptr noundef nonnull align 8 dereferenceable(64)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce10OwnedArrayINS_15StreamingSocketENS_20DummyCriticalSectionEE3addEPS1_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) #2 align 2

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

!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 288}
!10 = !{!"_ZTS17ServerConnections", !11, i64 0, !6, i64 288, !6, i64 296}
!11 = !{!"_ZTSN4juce6ThreadE", !12, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !15, i64 72, !15, i64 168, !17, i64 264, !18, i64 272, !17, i64 280, !16, i64 284}
!12 = !{!"_ZTSN4juce6StringE", !13, i64 0}
!13 = !{!"_ZTSN4juce16CharPointer_UTF8E", !6, i64 0}
!14 = !{!"_ZTSN4juce15CriticalSectionE", !7, i64 0}
!15 = !{!"_ZTSN4juce13WaitableEventE", !7, i64 0, !7, i64 48, !16, i64 88, !16, i64 89}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!10, !6, i64 296}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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 uwtable
define dso_local void @_ZN17ServerConnections3runEv(ptr noundef nonnull align 8 dereferenceable(304) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 288
  %3 = tail call noundef zeroext i1 @_ZNK4juce6Thread16threadShouldExitEv(ptr noundef nonnull align 8 dereferenceable(285) %0)
  br i1 %3, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 296
  br label %5

5:                                                ; preds = %.lr.ph, %13
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %5
  %8 = tail call noundef ptr @_ZNK4juce15StreamingSocket21waitForNextConnectionEv(ptr noundef nonnull align 8 dereferenceable(64) %6)
  %.not5 = icmp eq ptr %8, null
  br i1 %.not5, label %13, label %9

9:                                                ; preds = %7
  %10 = load ptr, ptr %4, align 8, !tbaa !18
  %.not6 = icmp eq ptr %10, null
  br i1 %.not6, label %13, label %11

11:                                               ; preds = %9
  %12 = tail call noundef ptr @_ZN4juce10OwnedArrayINS_15StreamingSocketENS_20DummyCriticalSectionEE3addEPS1_(ptr noundef nonnull align 8 dereferenceable(20) %10, ptr noundef nonnull %8) #3
  br label %13

13:                                               ; preds = %11, %9, %7
  %14 = tail call noundef zeroext i1 @_ZNK4juce6Thread16threadShouldExitEv(ptr noundef nonnull align 8 dereferenceable(285) %0)
  br i1 %14, label %.critedge, label %5, !llvm.loop !19

.critedge:                                        ; preds = %5, %13, %1
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4juce6Thread16threadShouldExitEv(ptr noundef nonnull align 8 dereferenceable(285)) local_unnamed_addr #1 align 2

declare noundef ptr @_ZNK4juce15StreamingSocket21waitForNextConnectionEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4juce10OwnedArrayINS_15StreamingSocketENS_20DummyCriticalSectionEE3addEPS1_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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 = { "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, !10, i64 288}
!6 = !{!"_ZTS17ServerConnections", !7, i64 0, !10, i64 288, !10, i64 296}
!7 = !{!"_ZTSN4juce6ThreadE", !8, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !14, i64 72, !14, i64 168, !16, i64 264, !17, i64 272, !16, i64 280, !15, i64 284}
!8 = !{!"_ZTSN4juce6StringE", !9, i64 0}
!9 = !{!"_ZTSN4juce16CharPointer_UTF8E", !10, i64 0}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN4juce15CriticalSectionE", !11, i64 0}
!14 = !{!"_ZTSN4juce13WaitableEventE", !11, i64 0, !11, i64 48, !15, i64 88, !15, i64 89}
!15 = !{!"bool", !11, i64 0}
!16 = !{!"int", !11, i64 0}
!17 = !{!"long", !11, i64 0}
!18 = !{!6, !10, i64 296}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass