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

28:                                               ; preds = %1
  br label %58

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

37:                                               ; preds = %29
  br label %58

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %44, %38
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LoopbackContext_s, ptr %40, i32 0, i32 17
  %42 = load volatile i32, ptr %41, align 8, !tbaa !14
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  call void @Pa_Sleep(i64 noundef 100)
  br label %39, !llvm.loop !20

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call i32 @Pa_StopStream(ptr noundef %46)
  store i32 %47, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %45
  br label %58

51:                                               ; preds = %45
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = call i32 @Pa_CloseStream(ptr noundef %52)
  store i32 %53, ptr %5, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  br label %58

57:                                               ; preds = %51
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %60

58:                                               ; preds = %56, %50, %37, %28
  %59 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %59, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 8, 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
  %61 = load i32, ptr %2, align 4
  ret i32 %61
}

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

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

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

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

declare i32 @Pa_StartStream(ptr noundef) #2

declare void @Pa_Sleep(i64 noundef) #2

declare i32 @Pa_StopStream(ptr noundef) #2

declare i32 @Pa_CloseStream(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = 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: nounwind uwtable
define dso_local i32 @PaQa_RunLoopbackFullDuplex(ptr noundef %0) local_unnamed_addr #0 {
  %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 32
  %7 = getelementptr inbounds i8, ptr %4, i64 64
  %8 = load double, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %4, i64 76
  %10 = load i32, ptr %9, align 4, !tbaa !18
  %11 = sext i32 %10 to i64
  %12 = call i32 @Pa_OpenStream(ptr noundef nonnull %2, ptr noundef %4, ptr noundef nonnull %6, double noundef %8, i64 noundef %11, i64 noundef 1, ptr noundef nonnull @RecordAndPlaySinesCallback, ptr noundef %0) #3
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %26

13:                                               ; preds = %1
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @CopyStreamInfoToLoopbackContext(ptr noundef nonnull %0, ptr noundef %14, ptr noundef %14)
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @Pa_StartStream(ptr noundef %15) #3
  %.not19 = icmp eq i32 %16, 0
  br i1 %.not19, label %.preheader, label %26

.preheader:                                       ; preds = %13
  %17 = load volatile i32, ptr %5, align 8, !tbaa !13
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  call void @Pa_Sleep(i64 noundef 100) #3
  %19 = load volatile i32, ptr %5, align 8, !tbaa !13
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = call i32 @Pa_StopStream(ptr noundef %21) #3
  %.not20 = icmp eq i32 %22, 0
  br i1 %.not20, label %23, label %26

23:                                               ; preds = %._crit_edge
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @Pa_CloseStream(ptr noundef %24) #3
  br label %26

26:                                               ; preds = %23, %1, %13, %._crit_edge
  %.0 = phi i32 [ %12, %1 ], [ %16, %13 ], [ %22, %._crit_edge ], [ %25, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i32 %.0
}

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

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

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

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

declare i32 @Pa_StartStream(ptr noundef) local_unnamed_addr #2

declare void @Pa_Sleep(i64 noundef) local_unnamed_addr #2

declare i32 @Pa_StopStream(ptr noundef) local_unnamed_addr #2

declare i32 @Pa_CloseStream(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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