; LLVM IR from TobiasKozel/VAE :: external/portaudio/qa/loopback/src (paqa)

; 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.LoopbackContext_s = type { [8 x %struct.PaQaSineGenerator_s], [8 x %struct.PaQaRecording_s], double, double, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32 }
%struct.PaQaSineGenerator_s = type { double, double, double, double }
%struct.PaQaRecording_s = type { i32, ptr, i32, i32 }
%struct.TestParameters_s = type { %struct.PaStreamParameters, %struct.PaStreamParameters, double, i32, i32, i32, double, double, i64, i32 }
%struct.PaStreamParameters = type { i32, i32, i64, double, ptr }

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

declare i32 @Pa_OpenStream(ptr noundef, ptr noundef, ptr noundef, double noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @RecordAndPlaySinesCallback(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @CopyStreamInfoToLoopbackContext(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @Pa_StartStream(ptr noundef) #1

declare i32 @Pa_StopStream(ptr noundef) #1

declare i32 @Pa_CloseStream(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaQa_WaitForStream(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @PaQa_RunLoopbackHalfDuplex(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.LoopbackContext_s, ptr %10, i32 0, i32 16
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.LoopbackContext_s, ptr %13, i32 0, i32 17
  store volatile i32 0, ptr %14, align 8, !tbaa !14
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TestParameters_s, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TestParameters_s, ptr %17, i32 0, i32 2
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TestParameters_s, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = sext i32 %22 to i64
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TestParameters_s, ptr %24, i32 0, i32 8
  %26 = load i64, ptr %25, align 8, !tbaa !20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i32 @Pa_OpenStream(ptr noundef %4, ptr noundef %16, ptr noundef null, double noundef %19, i64 noundef %23, i64 noundef %26, ptr noundef @RecordAndPlaySinesCallback, ptr noundef %27)
  store i32 %28, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %1
  br label %93

32:                                               ; preds = %1
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TestParameters_s, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TestParameters_s, ptr %35, i32 0, i32 2
  %37 = load double, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TestParameters_s, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 4, !tbaa !19
  %41 = sext i32 %40 to i64
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TestParameters_s, ptr %42, i32 0, i32 8
  %44 = load i64, ptr %43, align 8, !tbaa !20
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @Pa_OpenStream(ptr noundef %5, ptr noundef null, ptr noundef %34, double noundef %37, i64 noundef %41, i64 noundef %44, ptr noundef @RecordAndPlaySinesCallback, ptr noundef %45)
  store i32 %46, ptr %6, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %32
  br label %93

50:                                               ; preds = %32
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  call void @CopyStreamInfoToLoopbackContext(ptr noundef %51, ptr noundef %52, ptr noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = call i32 @Pa_StartStream(ptr noundef %54)
  store i32 %55, ptr %6, align 4, !tbaa !9
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  br label %93

59:                                               ; preds = %50
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call i32 @Pa_StartStream(ptr noundef %60)
  store i32 %61, ptr %6, align 4, !tbaa !9
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  br label %93

65:                                               ; preds = %59
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = call i32 @PaQa_WaitForStream(ptr noundef %66)
  store i32 %67, ptr %7, align 4, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = call i32 @Pa_StopStream(ptr noundef %68)
  store i32 %69, ptr %6, align 4, !tbaa !9
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %65
  br label %93

73:                                               ; preds = %65
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = call i32 @Pa_StopStream(ptr noundef %74)
  store i32 %75, ptr %6, align 4, !tbaa !9
  %76 = load i32, ptr %6, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %73
  br label %93

79:                                               ; preds = %73
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = call i32 @Pa_CloseStream(ptr noundef %80)
  store i32 %81, ptr %6, align 4, !tbaa !9
  %82 = load i32, ptr %6, align 4, !tbaa !9
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %79
  br label %93

85:                                               ; preds = %79
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i32 @Pa_CloseStream(ptr noundef %86)
  store i32 %87, ptr %6, align 4, !tbaa !9
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %85
  br label %93

91:                                               ; preds = %85
  %92 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %92, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %95

93:                                               ; preds = %90, %84, %78, %72, %64, %58, %49, %31
  %94 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %94, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %95

95:                                               ; preds = %93, %91
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %96 = load i32, ptr %2, align 4
  ret i32 %96
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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, !6, i64 512}
!12 = !{!"LoopbackContext_s", !7, i64 0, !7, i64 256, !13, i64 448, !13, i64 456, !10, i64 464, !10, i64 468, !10, i64 472, !10, i64 476, !10, i64 480, !10, i64 484, !10, i64 488, !10, i64 492, !10, i64 496, !10, i64 500, !10, i64 504, !10, i64 508, !6, i64 512, !10, i64 520}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !10, i64 520}
!15 = !{!16, !13, i64 64}
!16 = !{!"TestParameters_s", !17, i64 0, !17, i64 32, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !13, i64 88, !13, i64 96, !18, i64 104, !10, i64 112}
!17 = !{!"PaStreamParameters", !10, i64 0, !10, i64 4, !18, i64 8, !13, i64 16, !6, i64 24}
!18 = !{!"long", !7, i64 0}
!19 = !{!16, !10, i64 76}
!20 = !{!16, !18, i64 104}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @Pa_OpenStream(ptr noundef, ptr noundef, ptr noundef, double noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @RecordAndPlaySinesCallback(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @CopyStreamInfoToLoopbackContext(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @Pa_StartStream(ptr noundef) local_unnamed_addr #1

declare i32 @Pa_StopStream(ptr noundef) local_unnamed_addr #1

declare i32 @Pa_CloseStream(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PaQa_RunLoopbackHalfDuplex(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 512
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 520
  store volatile i32 0, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %5, i64 64
  %8 = load double, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %5, i64 76
  %10 = load i32, ptr %9, align 4, !tbaa !18
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %5, i64 104
  %13 = load i64, ptr %12, align 8, !tbaa !19
  %14 = call i32 @Pa_OpenStream(ptr noundef nonnull %2, ptr noundef %5, ptr noundef null, double noundef %8, i64 noundef %11, i64 noundef %13, ptr noundef nonnull @RecordAndPlaySinesCallback, ptr noundef %0) #3
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %43

15:                                               ; preds = %1
  %16 = getelementptr inbounds i8, ptr %5, i64 32
  %17 = load double, ptr %7, align 8, !tbaa !14
  %18 = load i32, ptr %9, align 4, !tbaa !18
  %19 = sext i32 %18 to i64
  %20 = load i64, ptr %12, align 8, !tbaa !19
  %21 = call i32 @Pa_OpenStream(ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull %16, double noundef %17, i64 noundef %19, i64 noundef %20, ptr noundef nonnull @RecordAndPlaySinesCallback, ptr noundef nonnull %0) #3
  %.not33 = icmp eq i32 %21, 0
  br i1 %.not33, label %22, label %43

22:                                               ; preds = %15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  call void @CopyStreamInfoToLoopbackContext(ptr noundef nonnull %0, ptr noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = call i32 @Pa_StartStream(ptr noundef %25) #3
  %.not34 = icmp eq i32 %26, 0
  br i1 %.not34, label %27, label %43

27:                                               ; preds = %22
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call i32 @Pa_StartStream(ptr noundef %28) #3
  %.not35 = icmp eq i32 %29, 0
  br i1 %.not35, label %30, label %43

30:                                               ; preds = %27
  %31 = call i32 @PaQa_WaitForStream(ptr noundef nonnull %0)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = call i32 @Pa_StopStream(ptr noundef %32) #3
  %.not36 = icmp eq i32 %33, 0
  br i1 %.not36, label %34, label %43

34:                                               ; preds = %30
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @Pa_StopStream(ptr noundef %35) #3
  %.not37 = icmp eq i32 %36, 0
  br i1 %.not37, label %37, label %43

37:                                               ; preds = %34
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call i32 @Pa_CloseStream(ptr noundef %38) #3
  %.not38 = icmp eq i32 %39, 0
  br i1 %.not38, label %40, label %43

40:                                               ; preds = %37
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call i32 @Pa_CloseStream(ptr noundef %41) #3
  %.not39 = icmp eq i32 %42, 0
  %spec.select = select i1 %.not39, i32 %31, i32 %42
  br label %43

43:                                               ; preds = %40, %1, %15, %22, %27, %30, %34, %37
  %.0 = phi i32 [ %14, %1 ], [ %21, %15 ], [ %26, %22 ], [ %29, %27 ], [ %33, %30 ], [ %36, %34 ], [ %39, %37 ], [ %spec.select, %40 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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, !6, i64 512}
!10 = !{!"LoopbackContext_s", !7, i64 0, !7, i64 256, !11, i64 448, !11, i64 456, !12, i64 464, !12, i64 468, !12, i64 472, !12, i64 476, !12, i64 480, !12, i64 484, !12, i64 488, !12, i64 492, !12, i64 496, !12, i64 500, !12, i64 504, !12, i64 508, !6, i64 512, !12, i64 520}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 520}
!14 = !{!15, !11, i64 64}
!15 = !{!"TestParameters_s", !16, i64 0, !16, i64 32, !11, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !11, i64 88, !11, i64 96, !17, i64 104, !12, i64 112}
!16 = !{!"PaStreamParameters", !12, i64 0, !12, i64 4, !17, i64 8, !11, i64 16, !6, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!15, !12, i64 76}
!19 = !{!15, !17, i64 104}


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