; LLVM IR from trabucayre/openFPGALoader :: src/gowin.ll (ZN5Gowin12detectFamilyEv)

; 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.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] }
%class.Gowin = type { %class.Device.base, %class.SPIInterface, %"class.std::unique_ptr", %"class.std::unique_ptr", %"class.std::unique_ptr", i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32 }
%class.Device.base = type <{ ptr, ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i8, i8, i8 }>
%class.SPIInterface = type { ptr, i8, i32, i8, i8, i8, %"class.std::__cxx11::basic_string" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.68" }
%"struct.std::_Head_base.68" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5Gowin12detectFamilyEv(ptr noundef nonnull align 8 dereferenceable(192) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.Device, ptr %3, i32 0, i32 1
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = call noundef i32 @_ZN4Jtag20get_target_device_idEv(ptr noundef nonnull align 8 dereferenceable(193) %5)
  %7 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 5
  store i32 %6, ptr %7, align 8, !tbaa !16
  %8 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 5
  %9 = load i32, ptr %8, align 8, !tbaa !16
  %10 = icmp eq i32 %9, 16816155
  br i1 %10, label %11, label %17

11:                                               ; preds = %1
  %12 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 13
  store i8 -128, ptr %12, align 1, !tbaa !27
  %13 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 14
  store i8 32, ptr %13, align 4, !tbaa !28
  %14 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 15
  store i8 8, ptr %14, align 1, !tbaa !29
  %15 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 16
  store i8 2, ptr %15, align 2, !tbaa !30
  %16 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 17
  store i8 1, ptr %16, align 1, !tbaa !31
  br label %17

17:                                               ; preds = %11, %1
  %18 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 5
  %19 = load i32, ptr %18, align 8, !tbaa !16
  switch i32 %19, label %34 [
    i32 151005211, label %20
    i32 16791579, label %22
    i32 16803867, label %22
    i32 16795675, label %24
    i32 2075, label %26
    i32 10267, label %26
    i32 67611, label %30
    i32 83995, label %30
    i32 71707, label %30
    i32 75803, label %30
  ]

20:                                               ; preds = %17
  %21 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 6
  store i8 1, ptr %21, align 4, !tbaa !32
  br label %34

22:                                               ; preds = %17, %17
  %23 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 7
  store i8 1, ptr %23, align 1, !tbaa !33
  br label %34

24:                                               ; preds = %17
  %25 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 8
  store i8 1, ptr %25, align 2, !tbaa !34
  br label %34

26:                                               ; preds = %17, %17
  %27 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 12
  store i8 1, ptr %27, align 2, !tbaa !35
  %28 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 11
  store i8 1, ptr %28, align 1, !tbaa !36
  %29 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 9
  store i8 1, ptr %29, align 1, !tbaa !37
  br label %34

30:                                               ; preds = %17, %17, %17, %17
  %31 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 12
  store i8 1, ptr %31, align 2, !tbaa !35
  %32 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 11
  store i8 1, ptr %32, align 1, !tbaa !36
  %33 = getelementptr inbounds %class.Gowin, ptr %3, i32 0, i32 10
  store i8 1, ptr %33, align 8, !tbaa !38
  br label %34

34:                                               ; preds = %30, %26, %24, %22, %20, %17
  ret i1 true
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Jtag20get_target_device_idEv(ptr noundef nonnull align 8 dereferenceable(193)) #1 align 2

attributes #0 = { 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 #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" }

!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 8}
!10 = !{!"_ZTS6Device", !6, i64 8, !11, i64 16, !11, i64 48, !14, i64 80, !15, i64 84, !15, i64 85, !15, i64 86}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !7, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSN6Device9prog_modeE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!17, !19, i64 168}
!17 = !{!"_ZTS5Gowin", !10, i64 0, !18, i64 88, !20, i64 144, !20, i64 152, !20, i64 160, !19, i64 168, !15, i64 172, !15, i64 173, !15, i64 174, !15, i64 175, !15, i64 176, !15, i64 177, !15, i64 178, !7, i64 179, !7, i64 180, !7, i64 181, !7, i64 182, !7, i64 183, !26, i64 184, !26, i64 188}
!18 = !{!"_ZTS12SPIInterface", !7, i64 8, !19, i64 12, !15, i64 16, !15, i64 17, !15, i64 18, !11, i64 24}
!19 = !{!"int", !7, i64 0}
!20 = !{!"_ZTSSt10unique_ptrI21ConfigBitstreamParserSt14default_deleteIS0_EE", !21, i64 0}
!21 = !{!"_ZTSSt15__uniq_ptr_dataI21ConfigBitstreamParserSt14default_deleteIS0_ELb1ELb1EE", !22, i64 0}
!22 = !{!"_ZTSSt15__uniq_ptr_implI21ConfigBitstreamParserSt14default_deleteIS0_EE", !23, i64 0}
!23 = !{!"_ZTSSt5tupleIJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !24, i64 0}
!24 = !{!"_ZTSSt11_Tuple_implILm0EJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !25, i64 0}
!25 = !{!"_ZTSSt10_Head_baseILm0EP21ConfigBitstreamParserLb0EE", !6, i64 0}
!26 = !{!"_ZTSN13JtagInterface10tck_edge_tE", !7, i64 0}
!27 = !{!17, !7, i64 179}
!28 = !{!17, !7, i64 180}
!29 = !{!17, !7, i64 181}
!30 = !{!17, !7, i64 182}
!31 = !{!17, !7, i64 183}
!32 = !{!17, !15, i64 172}
!33 = !{!17, !15, i64 173}
!34 = !{!17, !15, i64 174}
!35 = !{!17, !15, i64 178}
!36 = !{!17, !15, i64 177}
!37 = !{!17, !15, i64 175}
!38 = !{!17, !15, i64 176}


; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZN5Gowin12detectFamilyEv(ptr nocapture noundef nonnull align 8 dereferenceable(192) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call noundef i32 @_ZN4Jtag20get_target_device_idEv(ptr noundef nonnull align 8 dereferenceable(193) %3)
  %5 = getelementptr inbounds i8, ptr %0, i64 168
  store i32 %4, ptr %5, align 8, !tbaa !15
  switch i32 %4, label %22 [
    i32 16816155, label %.thread
    i32 151005211, label %8
    i32 16791579, label %10
    i32 16803867, label %10
    i32 16795675, label %12
    i32 2075, label %14
    i32 10267, label %14
    i32 67611, label %18
    i32 83995, label %18
    i32 71707, label %18
    i32 75803, label %18
  ]

.thread:                                          ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 179
  store <4 x i8> <i8 -128, i8 32, i8 8, i8 2>, ptr %6, align 1, !tbaa !26
  %7 = getelementptr inbounds i8, ptr %0, i64 183
  store i8 1, ptr %7, align 1, !tbaa !27
  br label %22

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 172
  store i8 1, ptr %9, align 4, !tbaa !28
  br label %22

10:                                               ; preds = %1, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 173
  store i8 1, ptr %11, align 1, !tbaa !29
  br label %22

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 174
  store i8 1, ptr %13, align 2, !tbaa !30
  br label %22

14:                                               ; preds = %1, %1
  %15 = getelementptr inbounds i8, ptr %0, i64 178
  store i8 1, ptr %15, align 2, !tbaa !31
  %16 = getelementptr inbounds i8, ptr %0, i64 177
  store i8 1, ptr %16, align 1, !tbaa !32
  %17 = getelementptr inbounds i8, ptr %0, i64 175
  store i8 1, ptr %17, align 1, !tbaa !33
  br label %22

18:                                               ; preds = %1, %1, %1, %1
  %19 = getelementptr inbounds i8, ptr %0, i64 178
  store i8 1, ptr %19, align 2, !tbaa !31
  %20 = getelementptr inbounds i8, ptr %0, i64 177
  store i8 1, ptr %20, align 1, !tbaa !32
  %21 = getelementptr inbounds i8, ptr %0, i64 176
  store i8 1, ptr %21, align 8, !tbaa !34
  br label %22

22:                                               ; preds = %1, %.thread, %18, %14, %12, %10, %8
  ret i1 true
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN4Jtag20get_target_device_idEv(ptr noundef nonnull align 8 dereferenceable(193)) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

!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 = !{!16, !18, i64 168}
!16 = !{!"_ZTS5Gowin", !6, i64 0, !17, i64 88, !19, i64 144, !19, i64 152, !19, i64 160, !18, i64 168, !14, i64 172, !14, i64 173, !14, i64 174, !14, i64 175, !14, i64 176, !14, i64 177, !14, i64 178, !8, i64 179, !8, i64 180, !8, i64 181, !8, i64 182, !8, i64 183, !25, i64 184, !25, i64 188}
!17 = !{!"_ZTS12SPIInterface", !8, i64 8, !18, i64 12, !14, i64 16, !14, i64 17, !14, i64 18, !10, i64 24}
!18 = !{!"int", !8, i64 0}
!19 = !{!"_ZTSSt10unique_ptrI21ConfigBitstreamParserSt14default_deleteIS0_EE", !20, i64 0}
!20 = !{!"_ZTSSt15__uniq_ptr_dataI21ConfigBitstreamParserSt14default_deleteIS0_ELb1ELb1EE", !21, i64 0}
!21 = !{!"_ZTSSt15__uniq_ptr_implI21ConfigBitstreamParserSt14default_deleteIS0_EE", !22, i64 0}
!22 = !{!"_ZTSSt5tupleIJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !23, i64 0}
!23 = !{!"_ZTSSt11_Tuple_implILm0EJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !24, i64 0}
!24 = !{!"_ZTSSt10_Head_baseILm0EP21ConfigBitstreamParserLb0EE", !7, i64 0}
!25 = !{!"_ZTSN13JtagInterface10tck_edge_tE", !8, i64 0}
!26 = !{!8, !8, i64 0}
!27 = !{!16, !8, i64 183}
!28 = !{!16, !14, i64 172}
!29 = !{!16, !14, i64 173}
!30 = !{!16, !14, i64 174}
!31 = !{!16, !14, i64 178}
!32 = !{!16, !14, i64 177}
!33 = !{!16, !14, i64 175}
!34 = !{!16, !14, i64 176}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass