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

; 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.PaUtilAllocationGroup = type { i64, ptr, ptr, ptr }
%struct.PaUtilAllocationGroupLink = type { ptr, ptr }

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

; Function Attrs: nounwind uwtable
declare hidden ptr @AllocateLinks(i64 noundef, ptr noundef, ptr noundef) #1

declare ptr @PaUtil_AllocateMemory(i64 noundef) #2

; 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 ptr @PaUtil_GroupAllocateMemory(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %42, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = call ptr @AllocateLinks(i64 noundef %15, ptr noundef %18, ptr noundef %21)
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %41

25:                                               ; preds = %12
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %26, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %29, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = add nsw i64 %31, %28
  store i64 %32, ptr %30, align 8, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.PaUtilAllocationGroupLink, ptr %33, i64 0
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %35, i32 0, i32 1
  store ptr %34, ptr %36, align 8, !tbaa !14
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.PaUtilAllocationGroupLink, ptr %37, i64 1
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %39, i32 0, i32 2
  store ptr %38, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %25, %12
  br label %42

42:                                               ; preds = %41, %2
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %73

47:                                               ; preds = %42
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = call ptr @PaUtil_AllocateMemory(i64 noundef %48)
  store ptr %49, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %72

52:                                               ; preds = %47
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.PaUtilAllocationGroupLink, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %59, i32 0, i32 2
  store ptr %58, ptr %60, align 8, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.PaUtilAllocationGroupLink, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !17
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !18
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.PaUtilAllocationGroupLink, ptr %67, i32 0, i32 0
  store ptr %66, ptr %68, align 8, !tbaa !15
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.PaUtilAllocationGroup, ptr %70, i32 0, i32 3
  store ptr %69, ptr %71, align 8, !tbaa !18
  br label %72

72:                                               ; preds = %52, %47
  br label %73

73:                                               ; preds = %72, %42
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %74
}

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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"PaUtilAllocationGroupLink", !6, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!12, !6, i64 24}


; 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
declare hidden ptr @AllocateLinks(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @PaUtil_AllocateMemory(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @PaUtil_GroupAllocateMemory(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %.thread

5:                                                ; preds = %2
  %6 = load i64, ptr %0, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = tail call ptr @AllocateLinks(i64 noundef %6, ptr noundef %8, ptr noundef null)
  %.not26 = icmp eq ptr %9, null
  br i1 %.not26, label %14, label %10

10:                                               ; preds = %5
  %11 = load i64, ptr %0, align 8, !tbaa !11
  %12 = shl nsw i64 %11, 1
  store i64 %12, ptr %0, align 8, !tbaa !11
  store ptr %9, ptr %7, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %.thread

14:                                               ; preds = %5
  %.pr = load ptr, ptr %3, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.pr, null
  br i1 %.not27, label %22, label %.thread

.thread:                                          ; preds = %2, %10, %14
  %15 = tail call ptr @PaUtil_AllocateMemory(i64 noundef %1) #2
  %.not28 = icmp eq ptr %15, null
  br i1 %.not28, label %22, label %16

16:                                               ; preds = %.thread
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %15, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  store ptr %21, ptr %17, align 8, !tbaa !13
  store ptr %17, ptr %20, align 8, !tbaa !16
  br label %22

22:                                               ; preds = %.thread, %16, %14
  %.0 = phi ptr [ %15, %16 ], [ null, %.thread ], [ null, %14 ]
  ret ptr %.0
}

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 = { "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, !10, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"PaUtilAllocationGroupLink", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!6, !10, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass