; 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
@paUnixMainThread = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [168 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__.PaUnixThread_Terminate = external hidden unnamed_addr constant [63 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: nounwind
declare void @free(ptr noundef) #1

declare i32 @pthread_cancel(i64 noundef) #2

declare i32 @pthread_join(i64 noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare i64 @pthread_self() #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #5

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PaUnixThread_Terminate(ptr noundef %0, i32 noundef %1, ptr noundef %2) #6 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %11, %3
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.PaUnixThread, ptr %15, i32 0, i32 2
  store i32 %14, ptr %16, align 4, !tbaa !11
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %24, label %19

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.PaUnixThread, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = call i32 @pthread_cancel(i64 noundef %22)
  br label %24

24:                                               ; preds = %19, %13
  br label %25

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

35:                                               ; preds = %25
  %36 = call i64 @pthread_self() #9
  %37 = load i64, ptr @paUnixMainThread, align 8, !tbaa !16
  %38 = call i32 @pthread_equal(i64 noundef %36, i64 noundef %37) #9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %45

40:                                               ; preds = %35
  %41 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  %44 = call ptr @strerror(i32 noundef %43) #8
  call void @PaUtil_SetLastHostErrorInfo(i32 noundef 8, i64 noundef %42, ptr noundef %44)
  br label %45

45:                                               ; preds = %40, %35
  call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef @.str.10)
  store i32 -9999, ptr %7, align 4, !tbaa !9
  br label %64

46:                                               ; preds = %25
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %63

51:                                               ; preds = %48
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = icmp ne ptr inttoptr (i64 -1 to ptr), %52
  br i1 %53, label %54, label %63

54:                                               ; preds = %51
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %61

57:                                               ; preds = %54
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %59, ptr %60, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %57, %54
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %62) #8
  br label %63

63:                                               ; preds = %61, %51, %48
  br label %64

64:                                               ; preds = %63, %45
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.PaUnixThread, ptr %65, i32 0, i32 4
  %67 = call i32 @PaUnixMutex_Terminate(ptr noundef %66)
  store i32 %67, ptr @paUtilErr_, align 4, !tbaa !9
  %68 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  %69 = icmp eq i32 0, %68
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  br label %72

71:                                               ; preds = %64
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i32 noundef 467, ptr noundef @__PRETTY_FUNCTION__.PaUnixThread_Terminate) #10
  unreachable

72:                                               ; preds = %70
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.PaUnixThread, ptr %73, i32 0, i32 5
  %75 = call i32 @pthread_cond_destroy(ptr noundef %74) #8
  store i32 %75, ptr @paUtilErr_, align 4, !tbaa !9
  %76 = load i32, ptr @paUtilErr_, align 4, !tbaa !9
  %77 = icmp eq i32 0, %76
  br i1 %77, label %78, label %79

78:                                               ; preds = %72
  br label %80

79:                                               ; preds = %72
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 468, ptr noundef @__PRETTY_FUNCTION__.PaUnixThread_Terminate) #10
  unreachable

80:                                               ; preds = %78
  %81 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  ret i32 %81
}

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare i32 @pthread_equal(i64 noundef, i64 noundef) #7

declare void @PaUtil_SetLastHostErrorInfo(i32 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaUnixMutex_Terminate(ptr noundef) #6

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 willreturn memory(none) "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 = { 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 #5 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #6 = { 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 #7 = { inlinehint nounwind willreturn memory(none) 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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!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, !13, i64 0}
!16 = !{!13, !13, 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"

@paUtilErr_ = external hidden local_unnamed_addr global i32, align 4
@paUnixMainThread = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [168 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__.PaUnixThread_Terminate = external hidden unnamed_addr constant [63 x i8], align 1

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

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

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

declare i32 @pthread_cancel(i64 noundef) local_unnamed_addr #2

declare i32 @pthread_join(i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i64 @pthread_self() local_unnamed_addr #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -9999, 1) i32 @PaUnixThread_Terminate(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #5 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %5, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %1, ptr %7, align 4, !tbaa !9
  %.not15 = icmp eq i32 %1, 0
  br i1 %.not15, label %8, label %11

8:                                                ; preds = %6
  %9 = load i64, ptr %0, align 8, !tbaa !13
  %10 = tail call i32 @pthread_cancel(i64 noundef %9) #8
  br label %11

11:                                               ; preds = %6, %8
  %12 = load i64, ptr %0, align 8, !tbaa !13
  %13 = call i32 @pthread_join(i64 noundef %12, ptr noundef nonnull %4) #8
  store i32 %13, ptr @paUtilErr_, align 4, !tbaa !5
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %22, label %14, !prof !14

14:                                               ; preds = %11
  %15 = tail call i64 @pthread_self() #9
  %16 = load i64, ptr @paUnixMainThread, align 8, !tbaa !15
  %17 = call i32 @pthread_equal(i64 noundef %15, i64 noundef %16) #9
  %.not17 = icmp eq i32 %17, 0
  br i1 %.not17, label %21, label %18

18:                                               ; preds = %14
  %19 = sext i32 %13 to i64
  %20 = call ptr @strerror(i32 noundef %13) #8
  call void @PaUtil_SetLastHostErrorInfo(i32 noundef 8, i64 noundef %19, ptr noundef %20) #8
  br label %21

21:                                               ; preds = %18, %14
  call void (ptr, ...) @PaUtil_DebugPrint(ptr noundef nonnull @.str.10) #8
  br label %28

22:                                               ; preds = %11
  %23 = load ptr, ptr %4, align 8
  %magicptr = ptrtoint ptr %23 to i64
  switch i64 %magicptr, label %24 [
    i64 -1, label %28
    i64 0, label %28
  ]

24:                                               ; preds = %22
  br i1 %.not, label %27, label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %25, %24
  call void @free(ptr noundef %23) #8
  br label %28

28:                                               ; preds = %22, %22, %27, %21
  %.0 = phi i32 [ -9999, %21 ], [ 0, %27 ], [ 0, %22 ], [ 0, %22 ]
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  %30 = call i32 @PaUnixMutex_Terminate(ptr noundef nonnull %29)
  store i32 %30, ptr @paUtilErr_, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i32 noundef 467, ptr noundef nonnull @__PRETTY_FUNCTION__.PaUnixThread_Terminate) #10
  unreachable

33:                                               ; preds = %28
  %34 = getelementptr inbounds i8, ptr %0, i64 64
  %35 = call i32 @pthread_cond_destroy(ptr noundef nonnull %34) #8
  store i32 %35, ptr @paUtilErr_, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 468, ptr noundef nonnull @__PRETTY_FUNCTION__.PaUnixThread_Terminate) #10
  unreachable

38:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare i32 @pthread_equal(i64 noundef, i64 noundef) local_unnamed_addr #6

declare void @PaUtil_SetLastHostErrorInfo(i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #7

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

; Function Attrs: nounwind
declare i32 @pthread_cond_destroy(ptr noundef) local_unnamed_addr #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { 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 #5 = { 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 #6 = { inlinehint mustprogress nofree nosync nounwind willreturn memory(none) 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 12}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !12, i64 24, !7, i64 64, !6, i64 112}
!11 = !{!"long", !7, i64 0}
!12 = !{!"", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!15 = !{!11, !11, i64 0}


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