; LLVM IR from TobiasKozel/VAE :: external/portaudio/src/os/unix (pa_unix_util)

; 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.PaUnixThread = type { i64, i32, i32, i32, %struct.PaUnixMutex, %union.pthread_cond_t, i32 }
%struct.PaUnixMutex = 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 }
%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 }

@paUtilErr_ = external hidden global i32, align 4
@.str.14 = external hidden unnamed_addr constant [152 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [165 x i8], align 1

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

declare void @PaUtil_DebugPrint(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaUnixMutex_Lock(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaUnixMutex_Unlock(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @PaUnixThread_NotifyParent(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.PaUnixThread, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 0
  %9 = zext i1 %8 to i32
  %10 = sext i32 %9 to i64
  %11 = call i64 @llvm.expect.i64(i64 %10, i64 0)
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef @.str.14)
  store i32 -9986, ptr %3, align 4, !tbaa !9
  br label %60

14:                                               ; preds = %4
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.PaUnixThread, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %38, label %21

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PaUnixThread, ptr %23, i32 0, i32 4
  %25 = call i32 @PaUnixMutex_Lock(ptr noundef %24)
  store i32 %25, ptr @paUtilErr_, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 0
  %27 = zext i1 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = call i64 @llvm.expect.i64(i64 %28, i64 0)
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %22
  call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef @.str.15)
  %32 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  store i32 %32, ptr %3, align 4, !tbaa !9
  br label %60

33:                                               ; preds = %22
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PaUnixThread, ptr %36, i32 0, i32 3
  store i32 1, ptr %37, align 8, !tbaa !15
  br label %38

38:                                               ; preds = %35, %16
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PaUnixThread, ptr %39, i32 0, i32 1
  store i32 0, ptr %40, align 8, !tbaa !11
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.PaUnixThread, ptr %41, i32 0, i32 5
  %43 = call i32 @pthread_cond_signal(ptr noundef %42) #5
  br label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.PaUnixThread, ptr %45, i32 0, i32 4
  %47 = call i32 @PaUnixMutex_Unlock(ptr noundef %46)
  store i32 %47, ptr @paUtilErr_, align 4, !tbaa !9
  %48 = icmp slt i32 %47, 0
  %49 = zext i1 %48 to i32
  %50 = sext i32 %49 to i64
  %51 = call i64 @llvm.expect.i64(i64 %50, i64 0)
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %44
  call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef @.str.16)
  %54 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  store i32 %54, ptr %3, align 4, !tbaa !9
  br label %60

55:                                               ; preds = %44
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.PaUnixThread, ptr %58, i32 0, i32 3
  store i32 0, ptr %59, align 8, !tbaa !15
  br label %60

60:                                               ; preds = %57, %53, %31, %13
  %61 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %61
}

; Function Attrs: nounwind
declare i32 @pthread_cond_signal(ptr noundef) #4

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !13, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !14, i64 24, !7, i64 64, !10, i64 112}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!12, !10, i64 16}


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

@paUtilErr_ = external hidden local_unnamed_addr global i32, align 4
@.str.14 = external hidden unnamed_addr constant [152 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [165 x i8], align 1

declare void @PaUtil_DebugPrint(ptr noundef, ...) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PaUnixThread_NotifyParent(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %6, !prof !12

5:                                                ; preds = %1
  tail call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef nonnull @.str.14) #3
  br label %25

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %16

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = tail call i32 @PaUnixMutex_Lock(ptr noundef nonnull %10)
  store i32 %11, ptr @paUtilErr_, align 4, !tbaa !14
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %15, !prof !12

13:                                               ; preds = %9
  tail call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef nonnull @.str.15) #3
  %14 = load i32, ptr @paUtilErr_, align 4, !tbaa !14
  br label %25

15:                                               ; preds = %9
  store i32 1, ptr %7, align 8, !tbaa !13
  br label %16

16:                                               ; preds = %15, %6
  store i32 0, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = tail call i32 @pthread_cond_signal(ptr noundef nonnull %17) #3
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = tail call i32 @PaUnixMutex_Unlock(ptr noundef nonnull %19)
  store i32 %20, ptr @paUtilErr_, align 4, !tbaa !14
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %24, !prof !12

22:                                               ; preds = %16
  tail call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef nonnull @.str.16) #3
  %23 = load i32, ptr @paUtilErr_, align 4, !tbaa !14
  br label %25

24:                                               ; preds = %16
  store i32 0, ptr %7, align 8, !tbaa !13
  br label %25

25:                                               ; preds = %24, %22, %13, %5
  %.0 = phi i32 [ -9986, %5 ], [ %23, %22 ], [ 0, %24 ], [ %14, %13 ]
  ret i32 %.0
}

; Function Attrs: nounwind
declare i32 @pthread_cond_signal(ptr noundef) local_unnamed_addr #2

attributes #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 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 24, !8, i64 64, !10, i64 112}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !8, i64 0}
!12 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!13 = !{!6, !10, i64 16}
!14 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass