; 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 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
define dso_local i32 @PaQa_RunLoopbackHalfDuplexBlockingIO(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 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 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 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 %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TestParameters_s, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TestParameters_s, ptr %14, i32 0, i32 2
  %16 = load double, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TestParameters_s, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = sext i32 %19 to i64
  %21 = call i32 @Pa_OpenStream(ptr noundef %4, ptr noundef %13, ptr noundef null, double noundef %16, i64 noundef %20, i64 noundef 1, ptr noundef null, ptr noundef null)
  store i32 %21, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %1
  br label %98

25:                                               ; preds = %1
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TestParameters_s, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TestParameters_s, ptr %28, i32 0, i32 2
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TestParameters_s, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 4, !tbaa !18
  %34 = sext i32 %33 to i64
  %35 = call i32 @Pa_OpenStream(ptr noundef %5, ptr noundef null, ptr noundef %27, double noundef %30, i64 noundef %34, i64 noundef 1, ptr noundef null, ptr noundef null)
  store i32 %35, ptr %6, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %25
  br label %95

39:                                               ; preds = %25
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @CopyStreamInfoToLoopbackContext(ptr noundef %40, ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call i32 @Pa_StartStream(ptr noundef %43)
  store i32 %44, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %39
  br label %92

48:                                               ; preds = %39
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call i32 @Pa_StartStream(ptr noundef %49)
  store i32 %50, ptr %6, align 4, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  br label %92

54:                                               ; preds = %48
  br label %55

55:                                               ; preds = %66, %54
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %67

58:                                               ; preds = %55
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = call i32 @RecordAndPlayBlockingIO(ptr noundef %59, ptr noundef %60, ptr noundef %61)
  store i32 %62, ptr %6, align 4, !tbaa !9
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = icmp slt i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %58
  br label %92

66:                                               ; preds = %58
  br label %55, !llvm.loop !19

67:                                               ; preds = %55
  %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 = %67
  br label %92

73:                                               ; preds = %67
  %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 %92

79:                                               ; preds = %73
  %80 = load ptr, ptr %5, 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 %95

85:                                               ; preds = %79
  %86 = load ptr, ptr %4, 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 %98

91:                                               ; preds = %85
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %100

92:                                               ; preds = %78, %72, %65, %53, %47
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = call i32 @Pa_CloseStream(ptr noundef %93)
  br label %95

95:                                               ; preds = %92, %84, %38
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = call i32 @Pa_CloseStream(ptr noundef %96)
  br label %98

98:                                               ; preds = %95, %90, %24
  %99 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %99, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %100

100:                                              ; preds = %98, %91
  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 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %101 = load i32, ptr %2, align 4
  ret i32 %101
}

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

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 = !{!15, !13, i64 64}
!15 = !{!"TestParameters_s", !16, i64 0, !16, i64 32, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !13, i64 88, !13, i64 96, !17, i64 104, !10, i64 112}
!16 = !{!"PaStreamParameters", !10, i64 0, !10, i64 4, !17, i64 8, !13, i64 16, !6, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!15, !10, i64 76}
!19 = distinct !{!19, !20}
!20 = !{!"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: 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 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
define dso_local i32 @PaQa_RunLoopbackHalfDuplexBlockingIO(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 %5, i64 64
  %7 = load double, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %5, i64 76
  %9 = load i32, ptr %8, align 4, !tbaa !17
  %10 = sext i32 %9 to i64
  %11 = call i32 @Pa_OpenStream(ptr noundef nonnull %2, ptr noundef %5, ptr noundef null, double noundef %7, i64 noundef %10, i64 noundef 1, ptr noundef null, ptr noundef null) #3
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %48

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %5, i64 32
  %14 = load double, ptr %6, align 8, !tbaa !13
  %15 = load i32, ptr %8, align 4, !tbaa !17
  %16 = sext i32 %15 to i64
  %17 = call i32 @Pa_OpenStream(ptr noundef nonnull %3, ptr noundef null, ptr noundef nonnull %13, double noundef %14, i64 noundef %16, i64 noundef 1, ptr noundef null, ptr noundef null) #3
  %.not32 = icmp eq i32 %17, 0
  br i1 %.not32, label %18, label %45

18:                                               ; preds = %12
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  call void @CopyStreamInfoToLoopbackContext(ptr noundef nonnull %0, ptr noundef %19, ptr noundef %20)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @Pa_StartStream(ptr noundef %21) #3
  %.not33 = icmp eq i32 %22, 0
  br i1 %.not33, label %23, label %.loopexit

23:                                               ; preds = %18
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @Pa_StartStream(ptr noundef %24) #3
  %.not34 = icmp eq i32 %25, 0
  br i1 %.not34, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %23, %28
  %.020 = phi i32 [ %30, %28 ], [ 0, %23 ]
  %26 = icmp eq i32 %.020, 0
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  br i1 %26, label %28, label %32

28:                                               ; preds = %.preheader
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i32 @RecordAndPlayBlockingIO(ptr noundef %27, ptr noundef %29, ptr noundef %0)
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %.loopexit, label %.preheader, !llvm.loop !18

32:                                               ; preds = %.preheader
  %33 = call i32 @Pa_StopStream(ptr noundef %27) #3
  %.not35 = icmp eq i32 %33, 0
  br i1 %.not35, label %34, label %.loopexit

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

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

40:                                               ; preds = %37
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = call i32 @Pa_CloseStream(ptr noundef %41) #3
  br label %48

.loopexit:                                        ; preds = %28, %34, %32, %23, %18
  %.1 = phi i32 [ %22, %18 ], [ %25, %23 ], [ %33, %32 ], [ %36, %34 ], [ %30, %28 ]
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = call i32 @Pa_CloseStream(ptr noundef %43) #3
  br label %45

45:                                               ; preds = %37, %12, %.loopexit
  %.2 = phi i32 [ %17, %12 ], [ %.1, %.loopexit ], [ %39, %37 ]
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = call i32 @Pa_CloseStream(ptr noundef %46) #3
  br label %48

48:                                               ; preds = %40, %45, %1
  %.0 = phi i32 [ %11, %1 ], [ %.2, %45 ], [ %42, %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
}

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

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 = !{!14, !11, i64 64}
!14 = !{!"TestParameters_s", !15, i64 0, !15, i64 32, !11, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !11, i64 88, !11, i64 96, !16, i64 104, !12, i64 112}
!15 = !{!"PaStreamParameters", !12, i64 0, !12, i64 4, !16, i64 8, !11, i64 16, !6, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!14, !12, i64 76}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass