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

; 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.XUsbPs = type { %struct.XUsbPs_SetupData, %struct.XUsbPs_Config, i32, ptr, %struct.XUsbPs_DeviceConfig, ptr, ptr, i32, ptr, i8, ptr }
%struct.XUsbPs_SetupData = type { i8, i8, i16, i16, i16 }
%struct.XUsbPs_Config = type { i16, i32 }
%struct.XUsbPs_DeviceConfig = type { i8, [12 x %struct.XUsbPs_EpConfig], i32, [12 x %struct.XUsbPs_Endpoint], i32 }
%struct.XUsbPs_EpConfig = type { %struct.XUsbPs_EpSetup, %struct.XUsbPs_EpSetup }
%struct.XUsbPs_EpSetup = type { i32, i32, i32, i16 }
%struct.XUsbPs_Endpoint = type { %struct.XUsbPs_EpOut, %struct.XUsbPs_EpIn }
%struct.XUsbPs_EpOut = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i8, i32 }
%struct.XUsbPs_EpIn = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, i32 }

@Xil_AssertStatus = external global i32, align 4
@.str = external hidden unnamed_addr constant [171 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

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

; 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
declare hidden i32 @XUsbPs_EpQueueRequest(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef, i8 noundef zeroext) #2

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

15:                                               ; preds = %4
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !10
  br label %17

16:                                               ; preds = %4
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 204)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !10
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %58

17:                                               ; preds = %15
  %18 = load i8, ptr %7, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.XUsbPs, ptr %20, i32 0, i32 4
  %22 = getelementptr inbounds %struct.XUsbPs_DeviceConfig, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 8, !tbaa !12
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %19, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %17
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !10
  br label %28

27:                                               ; preds = %17
  call void @Xil_Assert(ptr noundef @.str, i32 noundef 205)
  store i32 1, ptr @Xil_AssertStatus, align 4, !tbaa !10
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %58

28:                                               ; preds = %26
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XUsbPs, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds %struct.XUsbPs_DeviceConfig, ptr %30, i32 0, i32 1
  %32 = load i8, ptr %7, align 1, !tbaa !9
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds [12 x %struct.XUsbPs_EpConfig], ptr %31, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.XUsbPs_EpConfig, ptr %34, i32 0, i32 1
  store ptr %35, ptr %11, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !10
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XUsbPs_EpSetup, ptr %37, i32 0, i32 3
  %39 = load i16, ptr %38, align 4, !tbaa !18
  %40 = zext i16 %39 to i32
  %41 = icmp uge i32 %36, %40
  br i1 %41, label %42, label %51

42:                                               ; preds = %28
  %43 = load i32, ptr %9, align 4, !tbaa !10
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XUsbPs_EpSetup, ptr %44, i32 0, i32 3
  %46 = load i16, ptr %45, align 4, !tbaa !18
  %47 = zext i16 %46 to i32
  %48 = urem i32 %43, %47
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  store i8 1, ptr %10, align 1, !tbaa !9
  br label %51

51:                                               ; preds = %50, %42, %28
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i8, ptr %7, align 1, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !10
  %56 = load i8, ptr %10, align 1, !tbaa !9
  %57 = call i32 @XUsbPs_EpQueueRequest(ptr noundef %52, i8 noundef zeroext %53, ptr noundef %54, i32 noundef %55, i8 noundef zeroext %56)
  store i32 %57, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %58

58:                                               ; preds = %51, %27, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %59 = load i32, ptr %5, align 4
  ret i32 %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 32}
!13 = !{!"", !14, i64 0, !16, i64 8, !11, i64 16, !6, i64 24, !17, i64 32, !6, i64 2352, !6, i64 2360, !11, i64 2368, !6, i64 2376, !7, i64 2384, !6, i64 2392}
!14 = !{!"", !7, i64 0, !7, i64 1, !15, i64 2, !15, i64 4, !15, i64 6}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !15, i64 0, !11, i64 4}
!17 = !{!"", !7, i64 0, !7, i64 4, !11, i64 388, !7, i64 392, !11, i64 2312}
!18 = !{!19, !15, i64 12}
!19 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !15, i64 12}


; 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.XUsbPs_EpConfig = type { %struct.XUsbPs_EpSetup, %struct.XUsbPs_EpSetup }
%struct.XUsbPs_EpSetup = type { i32, i32, i32, i16 }

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

declare void @Xil_Assert(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XUsbPs_EpQueueRequest(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XUsbPs_EpBufferSendWithZLT(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %9, label %5

5:                                                ; preds = %4
  store i32 0, ptr @Xil_AssertStatus, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i8, ptr %6, align 8, !tbaa !9
  %8 = icmp ugt i8 %7, %1
  br i1 %8, label %10, label %16

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

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = zext i8 %1 to i64
  %13 = getelementptr inbounds [12 x %struct.XUsbPs_EpConfig], ptr %11, i64 0, i64 %12, i32 1, i32 3
  %14 = load i16, ptr %13, align 4, !tbaa !16
  %15 = zext i16 %14 to i32
  %.not18 = icmp ugt i32 %15, %3
  br i1 %.not18, label %20, label %17

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

17:                                               ; preds = %10
  %18 = urem i32 %3, %15
  %19 = icmp eq i32 %18, 0
  %spec.select = zext i1 %19 to i8
  br label %20

20:                                               ; preds = %17, %10
  %.014 = phi i8 [ 0, %10 ], [ %spec.select, %17 ]
  %21 = tail call i32 @XUsbPs_EpQueueRequest(ptr noundef nonnull %0, i8 noundef zeroext %1, ptr noundef %2, i32 noundef %3, i8 noundef zeroext %.014)
  br label %22

22:                                               ; preds = %20, %16, %9
  %.0 = phi i32 [ %21, %20 ], [ 0, %16 ], [ 0, %9 ]
  ret i32 %.0
}

attributes #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 32}
!10 = !{!"", !11, i64 0, !13, i64 8, !6, i64 16, !14, i64 24, !15, i64 32, !14, i64 2352, !14, i64 2360, !6, i64 2368, !14, i64 2376, !7, i64 2384, !14, i64 2392}
!11 = !{!"", !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !12, i64 0, !6, i64 4}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 4, !6, i64 388, !7, i64 392, !6, i64 2312}
!16 = !{!17, !12, i64 12}
!17 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !12, i64 12}


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