; LLVM IR from trabucayre/openFPGALoader :: src/remoteBitbang_client.ll (ZN20RemoteBitbang_clientD2Ev)

; 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.RemoteBitbang_client = type { %class.JtagInterface.base, ptr, i32, i32, i32, i32, i32, i32 }
%class.JtagInterface.base = type <{ ptr, i32 }>

@_ZTV20RemoteBitbang_client = external dso_local unnamed_addr constant { [17 x ptr] }, align 8
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [25 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48), i8 noundef zeroext, ptr noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN20RemoteBitbang_clientD2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  store ptr getelementptr inbounds inrange(-16, 120) ({ [17 x ptr] }, ptr @_ZTV20RemoteBitbang_client, i32 0, i32 0, i32 2), ptr %3, align 8, !tbaa !9
  %4 = getelementptr inbounds %class.RemoteBitbang_client, ptr %3, i32 0, i32 2
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %13

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !9
  %9 = getelementptr inbounds ptr, ptr %8, i64 14
  %10 = load ptr, ptr %9, align 8
  %11 = invoke noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(48) %3)
          to label %12 unwind label %39

12:                                               ; preds = %7
  br label %13

13:                                               ; preds = %12, %1
  %14 = invoke noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48) %3, i8 noundef zeroext 66, ptr noundef null)
          to label %15 unwind label %39

15:                                               ; preds = %13
  %16 = icmp slt i64 %14, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.3)
          to label %19 unwind label %39

19:                                               ; preds = %17
  br label %20

20:                                               ; preds = %19, %15
  %21 = invoke noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48) %3, i8 noundef zeroext 81, ptr noundef null)
          to label %22 unwind label %39

22:                                               ; preds = %20
  %23 = icmp slt i64 %21, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %22
  %25 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.4)
          to label %26 unwind label %39

26:                                               ; preds = %24
  br label %27

27:                                               ; preds = %26, %22
  %28 = getelementptr inbounds %class.RemoteBitbang_client, ptr %3, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %27
  %32 = getelementptr inbounds %class.RemoteBitbang_client, ptr %3, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  call void @free(ptr noundef %33) #5
  br label %34

34:                                               ; preds = %31, %27
  %35 = getelementptr inbounds %class.RemoteBitbang_client, ptr %3, i32 0, i32 6
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = invoke i32 @close(i32 noundef %36)
          to label %38 unwind label %39

38:                                               ; preds = %34
  call void @_ZN13JtagInterfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %3) #5
  ret void

39:                                               ; preds = %34, %24, %20, %17, %13, %7
  %40 = landingpad { ptr, i32 }
          catch ptr null
  %41 = extractvalue { ptr, i32 } %40, 0
  call void @__clang_call_terminate(ptr %41) #6
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

declare i32 @close(i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13JtagInterfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #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" }
attributes #2 = { noinline noreturn nounwind uwtable "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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !14, i64 24}
!12 = !{!"_ZTS20RemoteBitbang_client", !13, i64 0, !6, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44}
!13 = !{!"_ZTS13JtagInterface", !14, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !14, i64 40}


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

@_ZTV20RemoteBitbang_client = external dso_local unnamed_addr constant { [17 x ptr] }, align 8
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [25 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48), i8 noundef zeroext, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN20RemoteBitbang_clientD2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 120) (i8, ptr @_ZTV20RemoteBitbang_client, i64 16), ptr %0, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i32, ptr %2, align 8, !tbaa !8
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %7, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr getelementptr inbounds inrange(-128, 8) (i8, ptr @_ZTV20RemoteBitbang_client, i64 128), align 8
  %6 = invoke noundef i32 %5(ptr noundef nonnull align 8 dereferenceable(48) %0)
          to label %7 unwind label %28

7:                                                ; preds = %4, %1
  %8 = invoke noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48) %0, i8 noundef zeroext 66, ptr noundef null)
          to label %9 unwind label %28

9:                                                ; preds = %7
  %10 = icmp slt i64 %8, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %13

13:                                               ; preds = %11, %9
  %14 = invoke noundef i64 @_ZN20RemoteBitbang_client8xfer_pktEhPh(ptr noundef nonnull align 8 dereferenceable(48) %0, i8 noundef zeroext 81, ptr noundef null)
          to label %15 unwind label %28

15:                                               ; preds = %13
  %16 = icmp slt i64 %14, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %15
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %19

19:                                               ; preds = %17, %15
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %.not1 = icmp eq ptr %21, null
  br i1 %.not1, label %23, label %22

22:                                               ; preds = %19
  tail call void @free(ptr noundef nonnull %21) #6
  br label %23

23:                                               ; preds = %22, %19
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = invoke i32 @close(i32 noundef %25)
          to label %27 unwind label %28

27:                                               ; preds = %23
  tail call void @_ZN13JtagInterfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %0) #6
  ret void

28:                                               ; preds = %23, %13, %7, %4
  %29 = landingpad { ptr, i32 }
          catch ptr null
  %30 = extractvalue { ptr, i32 } %29, 0
  tail call void @__clang_call_terminate(ptr %30) #7
  unreachable
}

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

declare i32 @close(i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13JtagInterfaceD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #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" }
attributes #2 = { noinline noreturn nounwind uwtable "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 = { 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 #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 24}
!9 = !{!"_ZTS20RemoteBitbang_client", !10, i64 0, !13, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44}
!10 = !{!"_ZTS13JtagInterface", !11, i64 8}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"any pointer", !12, i64 0}
!14 = !{!9, !13, i64 16}
!15 = !{!9, !11, i64 40}


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