; LLVM IR from trabucayre/openFPGALoader :: src/lattice.ll (ZN7Lattice12pollBusyFlagEb)

; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%class.Device = type <{ ptr, ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i8, i8, i8, 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] }

@.str.713 = external hidden unnamed_addr constant [20 x i8], align 1
@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.714 = external hidden unnamed_addr constant [8 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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7Lattice5wr_rdEhPhiS0_ib(ptr noundef nonnull align 8 dereferenceable(152), i8 noundef zeroext, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i1 noundef zeroext) #2 align 2

declare void @_ZN4Jtag9set_stateENS_10tapState_tEh(ptr noundef nonnull align 8 dereferenceable(193), i32 noundef, i8 noundef zeroext) #1

declare void @_ZN4Jtag9toggleClkEi(ptr noundef nonnull align 8 dereferenceable(193), i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Lattice12pollBusyFlagEb(ptr noundef nonnull align 8 dereferenceable(152) %0, i1 noundef zeroext %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %33, %2
  %12 = call noundef zeroext i1 @_ZN7Lattice5wr_rdEhPhiS0_ib(ptr noundef nonnull align 8 dereferenceable(152) %10, i8 noundef zeroext -16, ptr noundef null, i32 noundef 0, ptr noundef %6, i32 noundef 1, i1 noundef zeroext false)
  %13 = getelementptr inbounds %class.Device, ptr %10, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  call void @_ZN4Jtag9set_stateENS_10tapState_tEh(ptr noundef nonnull align 8 dereferenceable(193) %14, i32 noundef 1, i8 noundef zeroext 1)
  %15 = getelementptr inbounds %class.Device, ptr %10, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  call void @_ZN4Jtag9toggleClkEi(ptr noundef nonnull align 8 dereferenceable(193) %16, i32 noundef 1000)
  %17 = load i8, ptr %5, align 1, !tbaa !9, !range !19, !noundef !20
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %23

19:                                               ; preds = %11
  %20 = load i8, ptr %6, align 1, !tbaa !21
  %21 = zext i8 %20 to i32
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.713, i32 noundef %21)
  br label %23

23:                                               ; preds = %19, %11
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = icmp eq i32 %24, 100000000
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef @.str.714)
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %38

29:                                               ; preds = %23
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %29
  br label %33

33:                                               ; preds = %32
  %34 = load i8, ptr %6, align 1, !tbaa !21
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %11, label %37, !llvm.loop !22

37:                                               ; preds = %33
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %38

38:                                               ; preds = %37, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %39 = load i1, ptr %3, align 1
  ret i1 %39
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

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 = { mustprogress 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 = { inlinehint mustprogress 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 #4 = { 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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTS6Device", !6, i64 8, !15, i64 16, !15, i64 48, !18, i64 80, !10, i64 84, !10, i64 85, !10, i64 86}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN6Device9prog_modeE", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!7, !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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@.str.713 = external hidden unnamed_addr constant [20 x i8], align 1
@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.714 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7Lattice5wr_rdEhPhiS0_ib(ptr noundef nonnull align 8 dereferenceable(152), i8 noundef zeroext, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #2 align 2

declare void @_ZN4Jtag9set_stateENS_10tapState_tEh(ptr noundef nonnull align 8 dereferenceable(193), i32 noundef, i8 noundef zeroext) local_unnamed_addr #3

declare void @_ZN4Jtag9toggleClkEi(ptr noundef nonnull align 8 dereferenceable(193), i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7Lattice12pollBusyFlagEb(ptr noundef nonnull align 8 dereferenceable(152) %0, i1 noundef zeroext %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %1, label %.split.us, label %.split

.split.us:                                        ; preds = %2, %11
  %.0.us = phi i32 [ %12, %11 ], [ 0, %2 ]
  %5 = call noundef zeroext i1 @_ZN7Lattice5wr_rdEhPhiS0_ib(ptr noundef nonnull align 8 dereferenceable(152) %0, i8 noundef zeroext -16, ptr noundef null, i32 noundef 0, ptr noundef nonnull %3, i32 noundef 1, i1 noundef zeroext false)
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4Jtag9set_stateENS_10tapState_tEh(ptr noundef nonnull align 8 dereferenceable(193) %6, i32 noundef 1, i8 noundef zeroext 1)
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4Jtag9toggleClkEi(ptr noundef nonnull align 8 dereferenceable(193) %7, i32 noundef 1000)
  %8 = load i8, ptr %3, align 1, !tbaa !15
  %9 = zext i8 %8 to i32
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.713, i32 noundef %9)
  %.not15 = icmp eq i32 %.0.us, 100000000
  br i1 %.not15, label %.split7.us, label %11

11:                                               ; preds = %.split.us
  %12 = add nuw nsw i32 %.0.us, 1
  %13 = load i8, ptr %3, align 1, !tbaa !15
  %.not.us = icmp eq i8 %13, 0
  br i1 %.not.us, label %.loopexit, label %.split.us, !llvm.loop !16

.split:                                           ; preds = %2, %19
  %.0 = phi i32 [ %20, %19 ], [ 0, %2 ]
  %14 = call noundef zeroext i1 @_ZN7Lattice5wr_rdEhPhiS0_ib(ptr noundef nonnull align 8 dereferenceable(152) %0, i8 noundef zeroext -16, ptr noundef null, i32 noundef 0, ptr noundef nonnull %3, i32 noundef 1, i1 noundef zeroext false)
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4Jtag9set_stateENS_10tapState_tEh(ptr noundef nonnull align 8 dereferenceable(193) %15, i32 noundef 1, i8 noundef zeroext 1)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4Jtag9toggleClkEi(ptr noundef nonnull align 8 dereferenceable(193) %16, i32 noundef 1000)
  %.not14 = icmp eq i32 %.0, 100000000
  br i1 %.not14, label %.split7.us, label %19

.split7.us:                                       ; preds = %.split, %.split.us
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef nonnull @.str.714)
  %18 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %.loopexit

19:                                               ; preds = %.split
  %20 = add nuw nsw i32 %.0, 1
  %21 = load i8, ptr %3, align 1, !tbaa !15
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %.loopexit, label %.split, !llvm.loop !16

.loopexit:                                        ; preds = %19, %11, %.split7.us
  %22 = phi i1 [ false, %.split7.us ], [ true, %11 ], [ true, %19 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  ret i1 %22
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 = { mustprogress 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 = { "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 #4 = { inlinehint mustprogress 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 #5 = { 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, !7, i64 8}
!6 = !{!"_ZTS6Device", !7, i64 8, !10, i64 16, !10, i64 48, !13, i64 80, !14, i64 84, !14, i64 85, !14, i64 86}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !11, i64 0, !12, i64 8, !8, i64 16}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"_ZTSN6Device9prog_modeE", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass