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

; 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.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.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.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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5Gowin7spi_putEhPKhPhj(ptr noundef nonnull align 8 dereferenceable(192) %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) unnamed_addr #3 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !10
  %16 = load ptr, ptr %7, align 8
  %17 = getelementptr inbounds %class.Gowin, ptr %16, i32 0, i32 10
  %18 = load i8, ptr %17, align 8, !tbaa !12, !range !28, !noundef !29
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %26

20:                                               ; preds = %5
  %21 = load i8, ptr %8, align 1, !tbaa !9
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load i32, ptr %11, align 4, !tbaa !10
  %25 = call noundef i32 @_ZN5Gowin12spi_put_gw5aEhPKhPhj(ptr noundef nonnull align 8 dereferenceable(192) %16, i8 noundef zeroext %21, ptr noundef %22, ptr noundef %23, i32 noundef %24)
  store i32 %25, ptr %6, align 4
  br label %72

26:                                               ; preds = %5
  %27 = load i32, ptr %11, align 4, !tbaa !10
  %28 = add i32 %27, 1
  %29 = zext i32 %28 to i64
  %30 = call ptr @llvm.stacksave.p0()
  store ptr %30, ptr %12, align 8
  %31 = alloca i8, i64 %29, align 16
  store i64 %29, ptr %13, align 8
  %32 = load i32, ptr %11, align 4, !tbaa !10
  %33 = add i32 %32, 1
  %34 = zext i32 %33 to i64
  %35 = alloca i8, i64 %34, align 16
  store i64 %34, ptr %14, align 8
  %36 = load i8, ptr %8, align 1, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %35, i64 0
  store i8 %36, ptr %37, align 16, !tbaa !9
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %45

40:                                               ; preds = %26
  %41 = getelementptr inbounds i8, ptr %35, i64 1
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !10
  %44 = zext i32 %43 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %41, ptr align 1 %42, i64 %44, i1 false)
  br label %49

45:                                               ; preds = %26
  %46 = getelementptr inbounds i8, ptr %35, i64 1
  %47 = load i32, ptr %11, align 4, !tbaa !10
  %48 = zext i32 %47 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %46, i8 0, i64 %48, i1 false)
  br label %49

49:                                               ; preds = %45, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  br label %54

53:                                               ; preds = %49
  br label %54

54:                                               ; preds = %53, %52
  %55 = phi ptr [ %31, %52 ], [ null, %53 ]
  %56 = load i32, ptr %11, align 4, !tbaa !10
  %57 = add i32 %56, 1
  %58 = load ptr, ptr %16, align 8, !tbaa !30
  %59 = getelementptr inbounds ptr, ptr %58, i64 14
  %60 = load ptr, ptr %59, align 8
  %61 = call noundef i32 %60(ptr noundef nonnull align 8 dereferenceable(192) %16, ptr noundef %35, ptr noundef %55, i32 noundef %57)
  store i32 %61, ptr %15, align 4, !tbaa !10
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %69

64:                                               ; preds = %54
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %31, i64 1
  %67 = load i32, ptr %11, align 4, !tbaa !10
  %68 = zext i32 %67 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %65, ptr align 1 %66, i64 %68, i1 false)
  br label %69

69:                                               ; preds = %64, %54
  %70 = load i32, ptr %15, align 4, !tbaa !10
  store i32 %70, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  %71 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %71)
  br label %72

72:                                               ; preds = %69, %20
  %73 = load i32, ptr %6, align 4
  ret i32 %73
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5Gowin12spi_put_gw5aEhPKhPhj(ptr noundef nonnull align 8 dereferenceable(192), i8 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { nocallback nofree nosync nounwind willreturn }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !19, i64 176}
!13 = !{!"_ZTS5Gowin", !14, i64 0, !20, i64 88, !21, i64 144, !21, i64 152, !21, i64 160, !11, i64 168, !19, i64 172, !19, i64 173, !19, i64 174, !19, i64 175, !19, i64 176, !19, i64 177, !19, i64 178, !7, i64 179, !7, i64 180, !7, i64 181, !7, i64 182, !7, i64 183, !27, i64 184, !27, i64 188}
!14 = !{!"_ZTS6Device", !6, i64 8, !15, i64 16, !15, i64 48, !18, i64 80, !19, i64 84, !19, i64 85, !19, 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 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTS12SPIInterface", !7, i64 8, !11, i64 12, !19, i64 16, !19, i64 17, !19, i64 18, !15, i64 24}
!21 = !{!"_ZTSSt10unique_ptrI21ConfigBitstreamParserSt14default_deleteIS0_EE", !22, i64 0}
!22 = !{!"_ZTSSt15__uniq_ptr_dataI21ConfigBitstreamParserSt14default_deleteIS0_ELb1ELb1EE", !23, i64 0}
!23 = !{!"_ZTSSt15__uniq_ptr_implI21ConfigBitstreamParserSt14default_deleteIS0_EE", !24, i64 0}
!24 = !{!"_ZTSSt5tupleIJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !25, i64 0}
!25 = !{!"_ZTSSt11_Tuple_implILm0EJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !26, i64 0}
!26 = !{!"_ZTSSt10_Head_baseILm0EP21ConfigBitstreamParserLb0EE", !6, i64 0}
!27 = !{!"_ZTSN13JtagInterface10tck_edge_tE", !7, i64 0}
!28 = !{i8 0, i8 2}
!29 = !{}
!30 = !{!31, !31, i64 0}
!31 = !{!"vtable pointer", !8, 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"

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5Gowin7spi_putEhPKhPhj(ptr noundef nonnull align 8 dereferenceable(192) %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) unnamed_addr #2 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 176
  %7 = load i8, ptr %6, align 8, !tbaa !5, !range !25, !noundef !26
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call noundef i32 @_ZN5Gowin12spi_put_gw5aEhPKhPhj(ptr noundef nonnull align 8 dereferenceable(192) %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3, i32 noundef %4)
  br label %30

11:                                               ; preds = %5
  %12 = add i32 %4, 1
  %13 = zext i32 %12 to i64
  %14 = tail call ptr @llvm.stacksave.p0()
  %15 = alloca i8, i64 %13, align 16
  %16 = alloca i8, i64 %13, align 16
  store i8 %1, ptr %16, align 16, !tbaa !27
  %.not = icmp eq ptr %2, null
  %17 = getelementptr inbounds i8, ptr %16, i64 1
  %18 = zext i32 %4 to i64
  br i1 %.not, label %20, label %19

19:                                               ; preds = %11
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %17, ptr nonnull align 1 %2, i64 %18, i1 false)
  br label %21

20:                                               ; preds = %11
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %17, i8 0, i64 %18, i1 false)
  br label %21

21:                                               ; preds = %20, %19
  %.not21 = icmp eq ptr %3, null
  %. = select i1 %.not21, ptr null, ptr %15
  %22 = load ptr, ptr %0, align 8, !tbaa !28
  %23 = getelementptr inbounds i8, ptr %22, i64 112
  %24 = load ptr, ptr %23, align 8
  %25 = call noundef i32 %24(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef nonnull %16, ptr noundef %., i32 noundef %12)
  br i1 %.not21, label %29, label %26

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %15, i64 1
  %28 = zext i32 %4 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %3, ptr nonnull align 1 %27, i64 %28, i1 false)
  br label %29

29:                                               ; preds = %26, %21
  call void @llvm.stackrestore.p0(ptr %14)
  br label %30

30:                                               ; preds = %29, %9
  %.0 = phi i32 [ %10, %9 ], [ %25, %29 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nosync nounwind willreturn }

!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, !15, i64 176}
!6 = !{!"_ZTS5Gowin", !7, i64 0, !16, i64 88, !18, i64 144, !18, i64 152, !18, i64 160, !17, i64 168, !15, i64 172, !15, i64 173, !15, i64 174, !15, i64 175, !15, i64 176, !15, i64 177, !15, i64 178, !9, i64 179, !9, i64 180, !9, i64 181, !9, i64 182, !9, i64 183, !24, i64 184, !24, i64 188}
!7 = !{!"_ZTS6Device", !8, i64 8, !11, i64 16, !11, i64 48, !14, i64 80, !15, i64 84, !15, i64 85, !15, i64 86}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !9, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !8, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!"_ZTSN6Device9prog_modeE", !9, i64 0}
!15 = !{!"bool", !9, i64 0}
!16 = !{!"_ZTS12SPIInterface", !9, i64 8, !17, i64 12, !15, i64 16, !15, i64 17, !15, i64 18, !11, i64 24}
!17 = !{!"int", !9, i64 0}
!18 = !{!"_ZTSSt10unique_ptrI21ConfigBitstreamParserSt14default_deleteIS0_EE", !19, i64 0}
!19 = !{!"_ZTSSt15__uniq_ptr_dataI21ConfigBitstreamParserSt14default_deleteIS0_ELb1ELb1EE", !20, i64 0}
!20 = !{!"_ZTSSt15__uniq_ptr_implI21ConfigBitstreamParserSt14default_deleteIS0_EE", !21, i64 0}
!21 = !{!"_ZTSSt5tupleIJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !22, i64 0}
!22 = !{!"_ZTSSt11_Tuple_implILm0EJP21ConfigBitstreamParserSt14default_deleteIS0_EEE", !23, i64 0}
!23 = !{!"_ZTSSt10_Head_baseILm0EP21ConfigBitstreamParserLb0EE", !8, i64 0}
!24 = !{!"_ZTSN13JtagInterface10tck_edge_tE", !9, i64 0}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!9, !9, i64 0}
!28 = !{!29, !29, i64 0}
!29 = !{!"vtable pointer", !10, i64 0}


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