; 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

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_RunInputOnly(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = 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 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  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 8, ptr %7) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.LoopbackContext_s, ptr %9, i32 0, i32 16
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LoopbackContext_s, ptr %12, i32 0, i32 17
  store volatile i32 0, ptr %13, align 8, !tbaa !14
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TestParameters_s, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TestParameters_s, ptr %16, i32 0, i32 2
  %18 = load double, ptr %17, align 8, !tbaa !15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TestParameters_s, ptr %19, i32 0, i32 4
  %21 = load i32, ptr %20, align 4, !tbaa !19
  %22 = sext i32 %21 to i64
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i32 @Pa_OpenStream(ptr noundef %4, ptr noundef %15, ptr noundef null, double noundef %18, i64 noundef %22, i64 noundef 1, ptr noundef @RecordAndPlaySinesCallback, ptr noundef %23)
  store i32 %24, ptr %5, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %1
  br label %50

28:                                               ; preds = %1
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @Pa_StartStream(ptr noundef %29)
  store i32 %30, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  br label %50

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @PaQa_WaitForStream(ptr noundef %35)
  store i32 %36, ptr %6, align 4, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call i32 @Pa_StopStream(ptr noundef %37)
  store i32 %38, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %50

42:                                               ; preds = %34
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = call i32 @Pa_CloseStream(ptr noundef %43)
  store i32 %44, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  br label %50

48:                                               ; preds = %42
  %49 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %49, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

50:                                               ; preds = %47, %41, %33, %27
  %51 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %51, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

52:                                               ; preds = %50, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %53 = load i32, ptr %2, align 4
  ret i32 %53
}

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}


; 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

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_RunInputOnly(ptr noundef %0) local_unnamed_addr #2 {
  %2 = 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
  %3 = getelementptr inbounds i8, ptr %0, i64 512
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %0, i64 520
  store volatile i32 0, ptr %5, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %4, i64 64
  %7 = load double, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %4, i64 76
  %9 = load i32, ptr %8, align 4, !tbaa !18
  %10 = sext i32 %9 to i64
  %11 = call i32 @Pa_OpenStream(ptr noundef nonnull %2, ptr noundef %4, ptr noundef null, double noundef %7, i64 noundef %10, i64 noundef 1, ptr noundef nonnull @RecordAndPlaySinesCallback, ptr noundef %0) #3
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %22

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @Pa_StartStream(ptr noundef %13) #3
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %15, label %22

15:                                               ; preds = %12
  %16 = call i32 @PaQa_WaitForStream(ptr noundef nonnull %0)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call i32 @Pa_StopStream(ptr noundef %17) #3
  %.not19 = icmp eq i32 %18, 0
  br i1 %.not19, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i32 @Pa_CloseStream(ptr noundef %20) #3
  %.not20 = icmp eq i32 %21, 0
  %spec.select = select i1 %.not20, i32 %16, i32 %21
  br label %22

22:                                               ; preds = %19, %1, %12, %15
  %.0 = phi i32 [ %11, %1 ], [ %14, %12 ], [ %18, %15 ], [ %spec.select, %19 ]
  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}


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