; LLVM IR from trabucayre/openFPGALoader :: src/spiFlash.ll (ZN8SPIFlash11get_bp_maskEv)

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

%class.SPIFlash = type <{ ptr, ptr, i8, [3 x i8], i32, ptr, i8, [7 x i8] }>
%struct.flash_t = type <{ %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i8, i8, i8, i8, i8, [3 x i8], i32, i8, [4 x i8], [3 x i8], i32, i16, [2 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN8SPIFlash11get_bp_maskEv(ptr noundef nonnull align 8 dereferenceable(33) %0) #1 align 2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.SPIFlash, ptr %6, i32 0, i32 5
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i8 28, ptr %2, align 1
  br label %39

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %12

12:                                               ; preds = %34, %11
  %13 = load i32, ptr %5, align 4, !tbaa !14
  %14 = getelementptr inbounds %class.SPIFlash, ptr %6, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.flash_t, ptr %15, i32 0, i32 10
  %17 = load i8, ptr %16, align 8, !tbaa !15
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %13, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %37

21:                                               ; preds = %12
  %22 = getelementptr inbounds %class.SPIFlash, ptr %6, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.flash_t, ptr %23, i32 0, i32 11
  %25 = load i32, ptr %5, align 4, !tbaa !14
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x i8], ptr %24, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = zext i8 %28 to i32
  %30 = load i8, ptr %4, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = or i32 %31, %29
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %4, align 1, !tbaa !13
  br label %34

34:                                               ; preds = %21
  %35 = load i32, ptr %5, align 4, !tbaa !14
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !14
  br label %12, !llvm.loop !22

37:                                               ; preds = %20
  %38 = load i8, ptr %4, align 1, !tbaa !13
  store i8 %38, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %39

39:                                               ; preds = %37, %10
  %40 = load i8, ptr %2, align 1
  ret i8 %40
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"_ZTS8SPIFlash", !6, i64 8, !7, i64 16, !11, i64 20, !6, i64 24, !12, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !7, i64 80}
!16 = !{!"_ZTS7flash_t", !17, i64 0, !17, i64 32, !11, i64 64, !12, i64 68, !12, i64 69, !12, i64 70, !12, i64 71, !7, i64 72, !20, i64 76, !7, i64 80, !7, i64 81, !20, i64 88, !21, i64 92}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"_ZTS8tb_loc_t", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i8 @_ZN8SPIFlash11get_bp_maskEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(33) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %4 = getelementptr inbounds i8, ptr %3, i64 80
  %5 = load i8, ptr %4, align 8, !tbaa !12
  %.not10 = icmp eq i8 %5, 0
  br i1 %.not10, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %3, i64 81
  %wide.trip.count = zext i8 %5 to i64
  %min.iters.check = icmp ult i8 %5, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check11 = icmp ult i8 %5, 32
  br i1 %min.iters.check11, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %wide.trip.count, 224
  %7 = getelementptr inbounds i8, ptr %3, i64 97
  %wide.load = load <16 x i8>, ptr %6, align 1, !tbaa !19
  %wide.load13 = load <16 x i8>, ptr %7, align 1, !tbaa !19
  %8 = icmp eq i64 %n.vec, 32
  br i1 %8, label %middle.block, label %vector.body.1, !llvm.loop !20

vector.body.1:                                    ; preds = %vector.ph
  %9 = getelementptr inbounds i8, ptr %3, i64 113
  %10 = getelementptr inbounds i8, ptr %3, i64 129
  %wide.load.1 = load <16 x i8>, ptr %9, align 1, !tbaa !19
  %wide.load13.1 = load <16 x i8>, ptr %10, align 1, !tbaa !19
  %11 = or <16 x i8> %wide.load.1, %wide.load
  %12 = or <16 x i8> %wide.load13.1, %wide.load13
  %13 = icmp eq i64 %n.vec, 64
  br i1 %13, label %middle.block, label %vector.body.2, !llvm.loop !20

vector.body.2:                                    ; preds = %vector.body.1
  %14 = getelementptr inbounds i8, ptr %3, i64 145
  %15 = getelementptr inbounds i8, ptr %3, i64 161
  %wide.load.2 = load <16 x i8>, ptr %14, align 1, !tbaa !19
  %wide.load13.2 = load <16 x i8>, ptr %15, align 1, !tbaa !19
  %16 = or <16 x i8> %wide.load.2, %11
  %17 = or <16 x i8> %wide.load13.2, %12
  %18 = icmp eq i64 %n.vec, 96
  br i1 %18, label %middle.block, label %vector.body.3, !llvm.loop !20

vector.body.3:                                    ; preds = %vector.body.2
  %19 = getelementptr inbounds i8, ptr %3, i64 177
  %20 = getelementptr inbounds i8, ptr %3, i64 193
  %wide.load.3 = load <16 x i8>, ptr %19, align 1, !tbaa !19
  %wide.load13.3 = load <16 x i8>, ptr %20, align 1, !tbaa !19
  %21 = or <16 x i8> %wide.load.3, %16
  %22 = or <16 x i8> %wide.load13.3, %17
  %23 = icmp eq i64 %n.vec, 128
  br i1 %23, label %middle.block, label %vector.body.4, !llvm.loop !20

vector.body.4:                                    ; preds = %vector.body.3
  %24 = getelementptr inbounds i8, ptr %3, i64 209
  %25 = getelementptr inbounds i8, ptr %3, i64 225
  %wide.load.4 = load <16 x i8>, ptr %24, align 1, !tbaa !19
  %wide.load13.4 = load <16 x i8>, ptr %25, align 1, !tbaa !19
  %26 = or <16 x i8> %wide.load.4, %21
  %27 = or <16 x i8> %wide.load13.4, %22
  %28 = icmp eq i64 %n.vec, 160
  br i1 %28, label %middle.block, label %vector.body.5, !llvm.loop !20

vector.body.5:                                    ; preds = %vector.body.4
  %29 = getelementptr inbounds i8, ptr %3, i64 241
  %30 = getelementptr inbounds i8, ptr %3, i64 257
  %wide.load.5 = load <16 x i8>, ptr %29, align 1, !tbaa !19
  %wide.load13.5 = load <16 x i8>, ptr %30, align 1, !tbaa !19
  %31 = or <16 x i8> %wide.load.5, %26
  %32 = or <16 x i8> %wide.load13.5, %27
  %33 = icmp eq i64 %n.vec, 192
  br i1 %33, label %middle.block, label %vector.body.6, !llvm.loop !20

vector.body.6:                                    ; preds = %vector.body.5
  %34 = getelementptr inbounds i8, ptr %3, i64 273
  %35 = getelementptr inbounds i8, ptr %3, i64 289
  %wide.load.6 = load <16 x i8>, ptr %34, align 1, !tbaa !19
  %wide.load13.6 = load <16 x i8>, ptr %35, align 1, !tbaa !19
  %36 = or <16 x i8> %wide.load.6, %31
  %37 = or <16 x i8> %wide.load13.6, %32
  br label %middle.block

middle.block:                                     ; preds = %vector.body.6, %vector.body.5, %vector.body.4, %vector.body.3, %vector.body.2, %vector.body.1, %vector.ph
  %.lcssa24 = phi <16 x i8> [ %wide.load, %vector.ph ], [ %11, %vector.body.1 ], [ %16, %vector.body.2 ], [ %21, %vector.body.3 ], [ %26, %vector.body.4 ], [ %31, %vector.body.5 ], [ %36, %vector.body.6 ]
  %.lcssa23 = phi <16 x i8> [ %wide.load13, %vector.ph ], [ %12, %vector.body.1 ], [ %17, %vector.body.2 ], [ %22, %vector.body.3 ], [ %27, %vector.body.4 ], [ %32, %vector.body.5 ], [ %37, %vector.body.6 ]
  %bin.rdx = or <16 x i8> %.lcssa23, %.lcssa24
  %38 = tail call i8 @llvm.vector.reduce.or.v16i8(<16 x i8> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %wide.trip.count, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %bc.merge.rdx = phi i8 [ %38, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec15 = and i64 %wide.trip.count, 248
  %39 = insertelement <8 x i8> <i8 poison, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>, i8 %bc.merge.rdx, i64 0
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index16 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next19, %vec.epilog.vector.body ]
  %vec.phi17 = phi <8 x i8> [ %39, %vec.epilog.ph ], [ %41, %vec.epilog.vector.body ]
  %40 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 %index16
  %wide.load18 = load <8 x i8>, ptr %40, align 1, !tbaa !19
  %41 = or <8 x i8> %wide.load18, %vec.phi17
  %index.next19 = add nuw i64 %index16, 8
  %42 = icmp eq i64 %index.next19, %n.vec15
  br i1 %42, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !24

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %43 = tail call i8 @llvm.vector.reduce.or.v8i8(<8 x i8> %41)
  %cmp.n20 = icmp eq i64 %n.vec15, %wide.trip.count
  br i1 %cmp.n20, label %.loopexit, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %indvars.iv.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec15, %vec.epilog.middle.block ]
  %.068.ph = phi i8 [ 0, %iter.check ], [ %38, %vec.epilog.iter.check ], [ %43, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %vec.epilog.scalar.ph ], [ %indvars.iv.ph, %vec.epilog.scalar.ph.preheader ]
  %.068 = phi i8 [ %46, %vec.epilog.scalar.ph ], [ %.068.ph, %vec.epilog.scalar.ph.preheader ]
  %44 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 %indvars.iv
  %45 = load i8, ptr %44, align 1, !tbaa !19
  %46 = or i8 %45, %.068
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %vec.epilog.scalar.ph, !llvm.loop !25

.loopexit:                                        ; preds = %vec.epilog.scalar.ph, %middle.block, %vec.epilog.middle.block, %.preheader, %1
  %.07 = phi i8 [ 28, %1 ], [ 0, %.preheader ], [ %38, %middle.block ], [ %43, %vec.epilog.middle.block ], [ %46, %vec.epilog.scalar.ph ]
  ret i8 %.07
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.vector.reduce.or.v16i8(<16 x i8>) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.vector.reduce.or.v8i8(<8 x i8>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 24}
!6 = !{!"_ZTS8SPIFlash", !7, i64 8, !8, i64 16, !10, i64 20, !7, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!13, !8, i64 80}
!13 = !{!"_ZTS7flash_t", !14, i64 0, !14, i64 32, !10, i64 64, !11, i64 68, !11, i64 69, !11, i64 70, !11, i64 71, !8, i64 72, !17, i64 76, !8, i64 80, !8, i64 81, !17, i64 88, !18, i64 92}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!"_ZTS8tb_loc_t", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!8, !8, i64 0}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !22, !23}
!25 = distinct !{!25, !21, !23, !22}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass