; 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
@QspiFlashSize = external dso_local global i32, align 4
@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: nounwind uwtable
define dso_local i32 @FlashReadID() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i8 -97, 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
  store i8 0, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 2), align 1, !tbaa !5
  store i8 0, ptr getelementptr inbounds ([5 x i8], ptr @WriteBuffer, i64 0, i64 3), align 1, !tbaa !5
  %4 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %5 = call i32 @XQspiPs_PolledTransfer(ptr noundef %4, ptr noundef @WriteBuffer, ptr noundef @ReadBuffer, i32 noundef 4)
  store i32 %5, ptr %2, align 4, !tbaa !10
  %6 = load i32, ptr %2, align 4, !tbaa !10
  %7 = zext i32 %6 to i64
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %109

10:                                               ; preds = %0
  %11 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 32
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  store i32 32, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %39

15:                                               ; preds = %10
  %16 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i32 1, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %38

20:                                               ; preds = %15
  %21 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 %22, 239
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i32 239, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %37

25:                                               ; preds = %20
  %26 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = icmp eq i32 %27, 194
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 194, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %36

30:                                               ; preds = %25
  %31 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 1), align 1, !tbaa !5
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 157
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store i32 157, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %35

35:                                               ; preds = %34, %30
  br label %36

36:                                               ; preds = %35, %29
  br label %37

37:                                               ; preds = %36, %24
  br label %38

38:                                               ; preds = %37, %19
  br label %39

39:                                               ; preds = %38, %14
  %40 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 20
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  store i32 1048576, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %108

44:                                               ; preds = %39
  %45 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %46 = zext i8 %45 to i32
  %47 = icmp eq i32 %46, 21
  br i1 %47, label %48, label %49

48:                                               ; preds = %44
  store i32 2097152, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %107

49:                                               ; preds = %44
  %50 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %51 = zext i8 %50 to i32
  %52 = icmp eq i32 %51, 22
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  store i32 4194304, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %106

54:                                               ; preds = %49
  %55 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 23
  br i1 %57, label %58, label %59

58:                                               ; preds = %54
  store i32 8388608, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %105

59:                                               ; preds = %54
  %60 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 24
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  store i32 16777216, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %104

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

68:                                               ; preds = %64
  store i32 33554432, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %103

69:                                               ; preds = %64
  %70 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %71 = zext i8 %70 to i32
  %72 = icmp eq i32 %71, 32
  br i1 %72, label %81, label %73

73:                                               ; preds = %69
  %74 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 58
  br i1 %76, label %81, label %77

77:                                               ; preds = %73
  %78 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %79 = zext i8 %78 to i32
  %80 = icmp eq i32 %79, 26
  br i1 %80, label %81, label %82

81:                                               ; preds = %77, %73, %69
  store i32 67108864, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %102

82:                                               ; preds = %77
  %83 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %84 = zext i8 %83 to i32
  %85 = icmp eq i32 %84, 33
  br i1 %85, label %90, label %86

86:                                               ; preds = %82
  %87 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %88 = zext i8 %87 to i32
  %89 = icmp eq i32 %88, 27
  br i1 %89, label %90, label %91

90:                                               ; preds = %86, %82
  store i32 134217728, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %101

91:                                               ; preds = %86
  %92 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %93 = zext i8 %92 to i32
  %94 = icmp eq i32 %93, 34
  br i1 %94, label %99, label %95

95:                                               ; preds = %91
  %96 = load i8, ptr getelementptr inbounds ([4101 x i8], ptr @ReadBuffer, i64 0, i64 3), align 1, !tbaa !5
  %97 = zext i8 %96 to i32
  %98 = icmp eq i32 %97, 28
  br i1 %98, label %99, label %100

99:                                               ; preds = %95, %91
  store i32 268435456, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %100

100:                                              ; preds = %99, %95
  br label %101

101:                                              ; preds = %100, %90
  br label %102

102:                                              ; preds = %101, %81
  br label %103

103:                                              ; preds = %102, %68
  br label %104

104:                                              ; preds = %103, %63
  br label %105

105:                                              ; preds = %104, %58
  br label %106

106:                                              ; preds = %105, %53
  br label %107

107:                                              ; preds = %106, %48
  br label %108

108:                                              ; preds = %107, %43
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %109

109:                                              ; preds = %108, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %110 = load i32, ptr %1, align 4
  ret i32 %110
}

; 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) #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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
@QspiFlashSize = external dso_local local_unnamed_addr global i32, align 4
@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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @FlashReadID() local_unnamed_addr #0 {
  store <4 x i8> <i8 -97, i8 0, i8 0, i8 0>, ptr @WriteBuffer, align 1, !tbaa !5
  %1 = load ptr, ptr @QspiInstancePtr, align 8, !tbaa !8
  %2 = tail call i32 @XQspiPs_PolledTransfer(ptr noundef %1, ptr noundef nonnull @WriteBuffer, ptr noundef nonnull @ReadBuffer, i32 noundef 4) #2
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %19

3:                                                ; preds = %0
  %4 = load i8, ptr getelementptr inbounds (i8, ptr @ReadBuffer, i64 1), align 1, !tbaa !5
  switch i8 %4, label %9 [
    i8 32, label %.sink.split
    i8 1, label %5
    i8 -17, label %6
    i8 -62, label %7
    i8 -99, label %8
  ]

5:                                                ; preds = %3
  br label %.sink.split

6:                                                ; preds = %3
  br label %.sink.split

7:                                                ; preds = %3
  br label %.sink.split

8:                                                ; preds = %3
  br label %.sink.split

.sink.split:                                      ; preds = %3, %6, %8, %7, %5
  %.sink = phi i32 [ 1, %5 ], [ 194, %7 ], [ 157, %8 ], [ 239, %6 ], [ 32, %3 ]
  store i32 %.sink, ptr @QspiFlashMake, align 4, !tbaa !10
  br label %9

9:                                                ; preds = %.sink.split, %3
  %10 = load i8, ptr getelementptr inbounds (i8, ptr @ReadBuffer, i64 3), align 1
  switch i8 %10, label %19 [
    i8 20, label %.sink.split15
    i8 21, label %11
    i8 22, label %12
    i8 23, label %13
    i8 24, label %14
    i8 25, label %15
    i8 58, label %16
    i8 32, label %16
    i8 26, label %16
    i8 33, label %17
    i8 27, label %17
    i8 34, label %18
    i8 28, label %18
  ]

11:                                               ; preds = %9
  br label %.sink.split15

12:                                               ; preds = %9
  br label %.sink.split15

13:                                               ; preds = %9
  br label %.sink.split15

14:                                               ; preds = %9
  br label %.sink.split15

15:                                               ; preds = %9
  br label %.sink.split15

16:                                               ; preds = %9, %9, %9
  br label %.sink.split15

17:                                               ; preds = %9, %9
  br label %.sink.split15

18:                                               ; preds = %9, %9
  br label %.sink.split15

.sink.split15:                                    ; preds = %9, %11, %13, %15, %17, %18, %16, %14, %12
  %.sink16 = phi i32 [ 4194304, %12 ], [ 16777216, %14 ], [ 67108864, %16 ], [ 268435456, %18 ], [ 134217728, %17 ], [ 33554432, %15 ], [ 8388608, %13 ], [ 2097152, %11 ], [ 1048576, %9 ]
  store i32 %.sink16, ptr @QspiFlashSize, align 4, !tbaa !10
  br label %19

19:                                               ; preds = %.sink.split15, %9, %0
  %.0 = phi i32 [ 1, %0 ], [ 0, %9 ], [ 0, %.sink.split15 ]
  ret i32 %.0
}

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


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