; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/zynq_fsbl (qspi)

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

@QspiInstancePtr = external dso_local global ptr, align 8
@WriteBuffer = external dso_local global [5 x i8], align 1
@ReadBuffer = external dso_local global [4101 x i8], align 16
@QspiFlashMake = external dso_local global i32, align 4

; 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

declare i32 @XQspiPs_PolledTransfer(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @SendBankSelect(i8 noundef zeroext %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %7 = icmp eq i32 %6, 32
  br i1 %7, label %11, label %8

8:                                                ; preds = %1
  %9 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %10 = icmp eq i32 %9, 194
  br i1 %10, label %11, label %27

11:                                               ; preds = %8, %1
  store i8 6, ptr @WriteBuffer, align 1, !tbaa !5
  %12 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !10
  %13 = call i32 @XQspiPs_PolledTransfer(ptr noundef %12, ptr noundef @WriteBuffer, ptr noundef null, i32 noundef 1)
  store i32 %13, ptr %4, align 4, !tbaa !8
  %14 = load i32, ptr %4, align 4, !tbaa !8
  %15 = zext i32 %14 to i64
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %11
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

18:                                               ; preds = %11
  store i8 -59, ptr @WriteBuffer, align 1, !tbaa !5
  %19 = load i8, ptr %3, align 1, !tbaa !5
  store i8 %19, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 1), align 1, !tbaa !5
  %20 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !10
  %21 = call i32 @XQspiPs_PolledTransfer(ptr noundef %20, ptr noundef @WriteBuffer, ptr noundef null, i32 noundef 2)
  store i32 %21, ptr %4, align 4, !tbaa !8
  %22 = load i32, ptr %4, align 4, !tbaa !8
  %23 = zext i32 %22 to i64
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %26, %8
  %28 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %39

30:                                               ; preds = %27
  store i8 23, ptr @WriteBuffer, align 1, !tbaa !5
  %31 = load i8, ptr %3, align 1, !tbaa !5
  store i8 %31, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 1), align 1, !tbaa !5
  %32 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !10
  %33 = call i32 @XQspiPs_PolledTransfer(ptr noundef %32, ptr noundef @WriteBuffer, ptr noundef null, i32 noundef 2)
  store i32 %33, ptr %4, align 4, !tbaa !8
  %34 = load i32, ptr %4, align 4, !tbaa !8
  %35 = zext i32 %34 to i64
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %30
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

38:                                               ; preds = %30
  br label %39

39:                                               ; preds = %38, %27
  %40 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %50

42:                                               ; preds = %39
  store i8 22, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 1), align 1, !tbaa !5
  %43 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !10
  %44 = call i32 @XQspiPs_PolledTransfer(ptr noundef %43, ptr noundef @WriteBuffer, ptr noundef @ReadBuffer, i32 noundef 2)
  store i32 %44, ptr %4, align 4, !tbaa !8
  %45 = load i32, ptr %4, align 4, !tbaa !8
  %46 = zext i32 %45 to i64
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %42
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

49:                                               ; preds = %42
  br label %50

50:                                               ; preds = %49, %39
  %51 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %52 = icmp eq i32 %51, 32
  br i1 %52, label %56, label %53

53:                                               ; preds = %50
  %54 = load i32, ptr @QspiFlashMake, align 4, !tbaa !8
  %55 = icmp eq i32 %54, 194
  br i1 %55, label %56, label %64

56:                                               ; preds = %53, %50
  store i8 -56, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 1), align 1, !tbaa !5
  %57 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !10
  %58 = call i32 @XQspiPs_PolledTransfer(ptr noundef %57, ptr noundef @WriteBuffer, ptr noundef @ReadBuffer, i32 noundef 2)
  store i32 %58, ptr %4, align 4, !tbaa !8
  %59 = load i32, ptr %4, align 4, !tbaa !8
  %60 = zext i32 %59 to i64
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %56
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

63:                                               ; preds = %56
  br label %64

64:                                               ; preds = %63, %53
  %65 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %66 = zext i8 %65 to i32
  %67 = load i8, ptr %3, align 1, !tbaa !5
  %68 = zext i8 %67 to i32
  %69 = icmp ne i32 %66, %68
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

71:                                               ; preds = %64
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %72

72:                                               ; preds = %71, %70, %62, %48, %37, %25, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %73 = load i32, ptr %2, align 4
  ret i32 %73
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


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

@QspiInstancePtr = external dso_local local_unnamed_addr global ptr, align 8
@WriteBuffer = external dso_local global [5 x i8], align 1
@ReadBuffer = external dso_local global [4101 x i8], align 16
@QspiFlashMake = external dso_local local_unnamed_addr global i32, align 4

declare i32 @XQspiPs_PolledTransfer(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @SendBankSelect(i8 noundef zeroext %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @QspiFlashMake, align 4
  switch i32 %2, label %9 [
    i32 194, label %3
    i32 32, label %3
  ]

3:                                                ; preds = %1, %1
  store i8 6, ptr @WriteBuffer, align 1, !tbaa !5
  %4 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %5 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %4, ptr noundef nonnull @WriteBuffer, ptr noundef null, i32 noundef 1) #2
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %26

6:                                                ; preds = %3
  store i8 -59, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 %0, ptr getelementptr inbounds (i8, ptr @WriteBuffer, i64 1), align 1, !tbaa !5
  %7 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %8 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %7, ptr noundef nonnull @WriteBuffer, ptr noundef null, i32 noundef 2) #2
  %.not12 = icmp eq i32 %8, 0
  br i1 %.not12, label %thread-pre-split, label %26

thread-pre-split:                                 ; preds = %6
  %.pr = load i32, ptr @QspiFlashMake, align 4
  br label %9

9:                                                ; preds = %thread-pre-split, %1
  %10 = phi i32 [ %.pr, %thread-pre-split ], [ %2, %1 ]
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %9
  store i8 23, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 %0, ptr getelementptr inbounds (i8, ptr @WriteBuffer, i64 1), align 1, !tbaa !5
  %13 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %14 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %13, ptr noundef nonnull @WriteBuffer, ptr noundef null, i32 noundef 2) #2
  %.not13 = icmp eq i32 %14, 0
  br i1 %.not13, label %15, label %26

15:                                               ; preds = %12
  %.pre = load i32, ptr @QspiFlashMake, align 4
  %16 = icmp eq i32 %.pre, 1
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %15
  store i8 22, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @WriteBuffer, i64 1), align 1, !tbaa !5
  %18 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %19 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %18, ptr noundef nonnull @WriteBuffer, ptr noundef nonnull @ReadBuffer, i32 noundef 2) #2
  %.not14 = icmp eq i32 %19, 0
  br i1 %.not14, label %thread-pre-split17, label %26

thread-pre-split17:                               ; preds = %17
  %.pr18 = load i32, ptr @QspiFlashMake, align 4
  br label %.thread

.thread:                                          ; preds = %9, %thread-pre-split17, %15
  %20 = phi i32 [ %.pr18, %thread-pre-split17 ], [ %.pre, %15 ], [ %10, %9 ]
  switch i32 %20, label %24 [
    i32 194, label %21
    i32 32, label %21
  ]

21:                                               ; preds = %.thread, %.thread
  store i8 -56, ptr @WriteBuffer, align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds (i8, ptr @WriteBuffer, i64 1), align 1, !tbaa !5
  %22 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %23 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %22, ptr noundef nonnull @WriteBuffer, ptr noundef nonnull @ReadBuffer, i32 noundef 2) #2
  %.not15 = icmp eq i32 %23, 0
  br i1 %.not15, label %24, label %26

24:                                               ; preds = %.thread, %21
  %25 = load i8, ptr getelementptr inbounds (i8, ptr @ReadBuffer, i64 1), align 1, !tbaa !5
  %.not16 = icmp ne i8 %25, %0
  %. = zext i1 %.not16 to i32
  br label %26

26:                                               ; preds = %24, %21, %17, %12, %6, %3
  %.0 = phi i32 [ 1, %3 ], [ 1, %6 ], [ 1, %12 ], [ 1, %17 ], [ 1, %21 ], [ %., %24 ]
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


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