; LLVM IR from TobiasKozel/VAE :: external/portaudio/src/common (pa_process)

; 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.PaUtilBufferProcessor = type { i64, i64, i32, i32, i32, i32, i64, i32, i32, i32, i32, ptr, ptr, i32, i32, i32, i32, ptr, ptr, i64, i64, ptr, ptr, i64, ptr, ptr, i64, ptr, i64, i32, [2 x i64], [2 x ptr], i32, [2 x i64], [2 x ptr], %struct.PaUtilTriangularDitherGenerator, double, ptr, ptr }
%struct.PaUtilTriangularDitherGenerator = type { i32, i32, i32 }
%struct.PaUtilChannelDescriptor = type { ptr, i32 }

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

; 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 i64 @PaUtil_ZeroOutput(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %8, i32 0, i32 34
  %10 = getelementptr inbounds [2 x ptr], ptr %9, i64 0, i64 0
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %12, i32 0, i32 33
  %14 = getelementptr inbounds [2 x i64], ptr %13, i64 0, i64 0
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %23

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %19, i32 0, i32 33
  %21 = getelementptr inbounds [2 x i64], ptr %20, i64 0, i64 0
  %22 = load i64, ptr %21, align 8, !tbaa !9
  br label %25

23:                                               ; preds = %2
  %24 = load i64, ptr %4, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %23, %18
  %26 = phi i64 [ %22, %18 ], [ %24, %23 ]
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %6, align 4, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %76, %25
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %30, i32 0, i32 13
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = icmp ult i32 %29, %32
  br i1 %33, label %34, label %79

34:                                               ; preds = %28
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %35, i32 0, i32 18
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !20
  %50 = load i32, ptr %6, align 4, !tbaa !11
  call void %37(ptr noundef %43, i32 noundef %49, i32 noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !11
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = load i32, ptr %6, align 4, !tbaa !11
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !11
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !20
  %64 = mul i32 %57, %63
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %65, i32 0, i32 14
  %67 = load i32, ptr %66, align 4, !tbaa !21
  %68 = mul i32 %64, %67
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %56, i64 %69
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !11
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %74, i32 0, i32 0
  store ptr %70, ptr %75, align 8, !tbaa !18
  br label %76

76:                                               ; preds = %34
  %77 = load i32, ptr %7, align 4, !tbaa !11
  %78 = add i32 %77, 1
  store i32 %78, ptr %7, align 4, !tbaa !11
  br label %28, !llvm.loop !22

79:                                               ; preds = %28
  %80 = load i32, ptr %6, align 4, !tbaa !11
  %81 = zext i32 %80 to i64
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.PaUtilBufferProcessor, ptr %82, i32 0, i32 33
  %84 = getelementptr inbounds [2 x i64], ptr %83, i64 0, i64 0
  %85 = load i64, ptr %84, align 8, !tbaa !9
  %86 = add i64 %85, %81
  store i64 %86, ptr %84, align 8, !tbaa !9
  %87 = load i32, ptr %6, align 4, !tbaa !11
  %88 = zext i32 %87 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %88
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 72}
!14 = !{!"", !10, i64 0, !10, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !10, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !6, i64 56, !6, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96, !10, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !12, i64 184, !7, i64 192, !7, i64 208, !12, i64 224, !7, i64 232, !7, i64 248, !15, i64 264, !16, i64 280, !6, i64 288, !6, i64 296}
!15 = !{!"PaUtilTriangularDitherGenerator", !12, i64 0, !12, i64 4, !12, i64 8}
!16 = !{!"double", !7, i64 0}
!17 = !{!14, !6, i64 96}
!18 = !{!19, !6, i64 0}
!19 = !{!"PaUtilChannelDescriptor", !6, i64 0, !12, i64 8}
!20 = !{!19, !12, i64 8}
!21 = !{!14, !12, i64 76}
!22 = distinct !{!22, !23}
!23 = !{!"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"

%struct.PaUtilChannelDescriptor = type { ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 4294967296) i64 @PaUtil_ZeroOutput(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 248
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 232
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %. = tail call i64 @llvm.umin.i64(i64 %6, i64 %1)
  %7 = trunc i64 %. to i32
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 96
  %11 = getelementptr inbounds i8, ptr %0, i64 76
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = load ptr, ptr %10, align 8, !tbaa !16
  %14 = getelementptr inbounds %struct.PaUtilChannelDescriptor, ptr %4, i64 %indvars.iv
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %14, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !19
  tail call void %13(ptr noundef %15, i32 noundef %17, i32 noundef %7) #2
  %18 = load ptr, ptr %14, align 8, !tbaa !17
  %19 = load i32, ptr %16, align 8, !tbaa !19
  %20 = mul i32 %19, %7
  %21 = load i32, ptr %11, align 4, !tbaa !20
  %22 = mul i32 %20, %21
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %18, i64 %23
  store ptr %24, ptr %14, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %8, align 8, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %12, label %._crit_edge.loopexit, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %12
  %.pre = load i64, ptr %5, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %28 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %6, %2 ]
  %29 = and i64 %., 4294967295
  %30 = add i64 %28, %29
  store i64 %30, ptr %5, align 8, !tbaa !9
  ret i64 %29
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 72}
!12 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !10, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !6, i64 56, !6, i64 64, !13, i64 72, !13, i64 76, !13, i64 80, !13, i64 84, !6, i64 88, !6, i64 96, !10, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !6, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !13, i64 184, !7, i64 192, !7, i64 208, !13, i64 224, !7, i64 232, !7, i64 248, !14, i64 264, !15, i64 280, !6, i64 288, !6, i64 296}
!13 = !{!"int", !7, i64 0}
!14 = !{!"PaUtilTriangularDitherGenerator", !13, i64 0, !13, i64 4, !13, i64 8}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !6, i64 96}
!17 = !{!18, !6, i64 0}
!18 = !{!"PaUtilChannelDescriptor", !6, i64 0, !13, i64 8}
!19 = !{!18, !13, i64 8}
!20 = !{!12, !13, i64 76}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass