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

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

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

11:                                               ; preds = %3
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %73

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %13, i32 0, i32 15
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp ult i32 %15, %16
  br i1 %17, label %24, label %18

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %19, i32 0, i32 10
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = icmp ne ptr %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %18, %12
  store i64 526, ptr %7, align 8, !tbaa !11
  br label %72

25:                                               ; preds = %18
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %27, i32 0, i32 14
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = add i32 %29, %26
  store i32 %30, ptr %28, align 8, !tbaa !16
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %32, i32 0, i32 15
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = sub i32 %34, %31
  store i32 %35, ptr %33, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %36, i32 0, i32 10
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = ptrtoint ptr %38 to i64
  store i64 %39, ptr %8, align 8, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 8, !tbaa !17
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = zext i32 %44 to i64
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = add i64 %46, %45
  store i64 %47, ptr %8, align 8, !tbaa !11
  %48 = load i64, ptr %8, align 8, !tbaa !11
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %49, i32 0, i32 2
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = icmp ugt i64 %48, %51
  br i1 %52, label %60, label %53

53:                                               ; preds = %25
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %54, i32 0, i32 10
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = ptrtoint ptr %56 to i64
  %58 = load i64, ptr %8, align 8, !tbaa !11
  %59 = icmp ugt i64 %57, %58
  br i1 %59, label %60, label %67

60:                                               ; preds = %53, %25
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !19
  %64 = zext i32 %63 to i64
  %65 = load i64, ptr %8, align 8, !tbaa !11
  %66 = sub i64 %65, %64
  store i64 %66, ptr %8, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %60, %53
  %68 = load i64, ptr %8, align 8, !tbaa !11
  %69 = inttoptr i64 %68 to ptr
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.XEmacPs_BdRing, ptr %70, i32 0, i32 10
  store ptr %69, ptr %71, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %72

72:                                               ; preds = %67, %24
  br label %73

73:                                               ; preds = %72, %11
  %74 = load i64, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 100}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, 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}
!15 = !{!14, !6, i64 72}
!16 = !{!14, !10, i64 96}
!17 = !{!14, !10, i64 32}
!18 = !{!14, !12, i64 16}
!19 = !{!14, !10, 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i64 0, 527) i64 @XEmacPs_BdRingFree(ptr nocapture noundef %0, i32 noundef %1, ptr noundef readnone %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, 0
  br i1 %4, label %34, label %5

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

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not = icmp eq ptr %11, %2
  br i1 %.not, label %12, label %34

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = add i32 %14, %1
  store i32 %15, ptr %13, align 8, !tbaa !13
  %16 = sub i32 %7, %1
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = ptrtoint ptr %2 to i64
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = mul i32 %19, %1
  %21 = zext i32 %20 to i64
  %22 = add i64 %21, %17
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = icmp ugt i64 %22, %24
  %26 = icmp ult i64 %22, %17
  %or.cond = or i1 %25, %26
  br i1 %or.cond, label %27, label %32

27:                                               ; preds = %12
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = zext i32 %29 to i64
  %31 = sub i64 %22, %30
  br label %32

32:                                               ; preds = %12, %27
  %.0 = phi i64 [ %31, %27 ], [ %22, %12 ]
  %33 = inttoptr i64 %.0 to ptr
  store ptr %33, ptr %10, align 8, !tbaa !12
  br label %34

34:                                               ; preds = %5, %9, %3, %32
  %.021 = phi i64 [ 0, %32 ], [ 0, %3 ], [ 526, %9 ], [ 526, %5 ]
  ret i64 %.021
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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" }

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


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