; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (BdRingUnAlloc)

; 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.XEmacPs_BdRing = type { i64, i64, i64, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32 }

@Xil_AssertStatus = external global i32, align 4
@.str = external hidden unnamed_addr constant [172 x i8], align 1

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

14:                                               ; preds = %3
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %16

15:                                               ; preds = %3
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 485)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

16:                                               ; preds = %14
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !9
  br label %21

20:                                               ; preds = %16
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 486)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !9
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

21:                                               ; preds = %19
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %22, i32 0, i32 13
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ult i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i64 1, ptr %8, align 8, !tbaa !14
  br label %75

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %29, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = ptrtoint ptr %31 to i64
  store i64 %32, ptr %10, align 8, !tbaa !14
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = mul i32 %35, %36
  %38 = zext i32 %37 to i64
  %39 = load i64, ptr %10, align 8, !tbaa !14
  %40 = sub i64 %39, %38
  store i64 %40, ptr %10, align 8, !tbaa !14
  %41 = load i64, ptr %10, align 8, !tbaa !14
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !17
  %45 = icmp ult i64 %41, %44
  br i1 %45, label %53, label %46

46:                                               ; preds = %28
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = ptrtoint ptr %49 to i64
  %51 = load i64, ptr %10, align 8, !tbaa !14
  %52 = icmp ult i64 %50, %51
  br i1 %52, label %53, label %60

53:                                               ; preds = %46, %28
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 8, !tbaa !18
  %57 = zext i32 %56 to i64
  %58 = load i64, ptr %10, align 8, !tbaa !14
  %59 = add i64 %58, %57
  store i64 %59, ptr %10, align 8, !tbaa !14
  br label %60

60:                                               ; preds = %53, %46
  %61 = load i64, ptr %10, align 8, !tbaa !14
  %62 = inttoptr i64 %61 to ptr
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %63, i32 0, i32 6
  store ptr %62, ptr %64, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %66, i32 0, i32 14
  %68 = load i32, ptr %67, align 8, !tbaa !19
  %69 = add i32 %68, %65
  store i32 %69, ptr %67, align 8, !tbaa !19
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %71, i32 0, i32 13
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = sub i32 %73, %70
  store i32 %74, ptr %72, align 4, !tbaa !11
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %75

75:                                               ; preds = %60, %27
  %76 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %76, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %75, %20, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %78 = load i64, ptr %4, align 8
  ret i64 %78
}

declare void @Xil_Assert(ptr noundef, i32 noundef) #2

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 92}
!12 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 40}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !10, i64 24}
!19 = !{!12, !10, i64 96}


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

@Xil_AssertStatus = external local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [172 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @XEmacPs_BdRingUnAlloc(ptr noundef %0, i32 noundef %1, ptr noundef readnone %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %3
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !5
  %.not27 = icmp eq ptr %2, null
  br i1 %.not27, label %10, label %6

5:                                                ; preds = %3
  tail call void @Xil_Assert(ptr noundef nonnull @.str, i32 noundef 485) #2
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !5
  br label %35

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 92
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp ult i32 %8, %1
  br i1 %9, label %35, label %11

10:                                               ; preds = %4
  tail call void @Xil_Assert(ptr noundef nonnull @.str, i32 noundef 486) #2
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !5
  br label %35

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = ptrtoint ptr %13 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = mul i32 %16, %1
  %18 = zext i32 %17 to i64
  %19 = sub i64 %14, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = icmp ult i64 %19, %21
  %23 = icmp ugt i64 %18, %14
  %or.cond = or i1 %23, %22
  br i1 %or.cond, label %24, label %29

24:                                               ; preds = %11
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = zext i32 %26 to i64
  %28 = add i64 %19, %27
  br label %29

29:                                               ; preds = %11, %24
  %.0 = phi i64 [ %28, %24 ], [ %19, %11 ]
  %30 = inttoptr i64 %.0 to ptr
  store ptr %30, ptr %12, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %0, i64 96
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = add i32 %32, %1
  store i32 %33, ptr %31, align 8, !tbaa !17
  %34 = sub i32 %8, %1
  store i32 %34, ptr %7, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %29, %6, %10, %5
  %.023 = phi i64 [ 0, %10 ], [ 0, %5 ], [ 0, %29 ], [ 1, %6 ]
  ret i64 %.023
}

declare void @Xil_Assert(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 92}
!10 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 40}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !6, i64 96}


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