; 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 }

@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaQa_RunLoopbackFullDuplex(ptr noundef) #0

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

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaQa_RunLoopbackHalfDuplex(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaQa_RunLoopbackHalfDuplexBlockingIO(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @PaQa_RunLoopbackFullDuplexBlockingIO(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @PaQa_RunLoopback(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.LoopbackContext_s, ptr %5, i32 0, i32 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TestParameters_s, ptr %8, i32 0, i32 9
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %26

13:                                               ; preds = %1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TestParameters_s, ptr %14, i32 0, i32 9
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = and i32 %16, 2
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call i32 @PaQa_RunLoopbackHalfDuplexBlockingIO(ptr noundef %20)
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %25

22:                                               ; preds = %13
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 @PaQa_RunLoopbackHalfDuplex(ptr noundef %23)
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %22, %19
  br label %39

26:                                               ; preds = %1
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TestParameters_s, ptr %27, i32 0, i32 9
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = and i32 %29, 2
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = call i32 @PaQa_RunLoopbackFullDuplexBlockingIO(ptr noundef %33)
  store i32 %34, ptr %3, align 4, !tbaa !9
  br label %38

35:                                               ; preds = %26
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i32 @PaQa_RunLoopbackFullDuplex(ptr noundef %36)
  store i32 %37, ptr %3, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %32
  br label %39

39:                                               ; preds = %38, %25
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %39
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = call ptr @Pa_GetErrorText(i32 noundef %43)
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, ptr noundef %44)
  br label %46

46:                                               ; preds = %42, %39
  %47 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %47
}

declare ptr @Pa_GetErrorText(i32 noundef) #2

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 = !{!15, !10, i64 112}
!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}


; 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"

@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PaQa_RunLoopback(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 512
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 112
  %5 = load i32, ptr %4, align 8, !tbaa !12
  %6 = and i32 %5, 1
  %.not = icmp eq i32 %6, 0
  %7 = and i32 %5, 2
  %.not10 = icmp eq i32 %7, 0
  br i1 %.not, label %13, label %8

8:                                                ; preds = %1
  br i1 %.not10, label %11, label %9

9:                                                ; preds = %8
  %10 = tail call i32 @PaQa_RunLoopbackHalfDuplexBlockingIO(ptr noundef nonnull %0)
  br label %18

11:                                               ; preds = %8
  %12 = tail call i32 @PaQa_RunLoopbackHalfDuplex(ptr noundef nonnull %0)
  br label %18

13:                                               ; preds = %1
  br i1 %.not10, label %16, label %14

14:                                               ; preds = %13
  %15 = tail call i32 @PaQa_RunLoopbackFullDuplexBlockingIO(ptr noundef nonnull %0)
  br label %18

16:                                               ; preds = %13
  %17 = tail call i32 @PaQa_RunLoopbackFullDuplex(ptr noundef nonnull %0)
  br label %18

18:                                               ; preds = %14, %16, %9, %11
  %.0 = phi i32 [ %10, %9 ], [ %12, %11 ], [ %15, %14 ], [ %17, %16 ]
  %.not12 = icmp eq i32 %.0, 0
  br i1 %.not12, label %22, label %19

19:                                               ; preds = %18
  %20 = tail call ptr @Pa_GetErrorText(i32 noundef %.0) #3
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, ptr noundef %20)
  br label %22

22:                                               ; preds = %19, %18
  ret i32 %.0
}

declare ptr @Pa_GetErrorText(i32 noundef) local_unnamed_addr #2

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 = { nofree 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 }

!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, !11, i64 512}
!6 = !{!"LoopbackContext_s", !7, i64 0, !7, i64 256, !9, i64 448, !9, 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, !11, i64 512, !10, i64 520}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"double", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !10, i64 112}
!13 = !{!"TestParameters_s", !14, i64 0, !14, i64 32, !9, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !9, i64 88, !9, i64 96, !15, i64 104, !10, i64 112}
!14 = !{!"PaStreamParameters", !10, i64 0, !10, i64 4, !15, i64 8, !9, i64 16, !11, i64 24}
!15 = !{!"long", !7, i64 0}


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