; LLVM IR from trabucayre/openFPGALoader :: src/xvc_client.ll (ZN10XVC_client9toggleClkEhhj)

; 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.XVC_client = type { %class.JtagInterface.base, i8, ptr, ptr, ptr, i32, i32, i32, i32, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i32 }
%class.JtagInterface.base = type <{ ptr, i32 }>
%"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] }

@_ZTISt13runtime_error = external constant ptr
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #0

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

declare void @__cxa_throw(ptr, ptr, ptr)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN10XVC_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(128), ptr noundef) #3 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10XVC_client9toggleClkEhhj(ptr noundef nonnull align 8 dereferenceable(128) %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i32 noundef %3) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !10
  %15 = load ptr, ptr %6, align 8
  %16 = load i32, ptr %9, align 4, !tbaa !10
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %102

19:                                               ; preds = %4
  %20 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  %21 = load i32, ptr %20, align 8, !tbaa !12
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = load ptr, ptr %15, align 8, !tbaa !19
  %25 = getelementptr inbounds ptr, ptr %24, i64 14
  %26 = load ptr, ptr %25, align 8
  %27 = call noundef i32 %26(ptr noundef nonnull align 8 dereferenceable(128) %15)
  br label %28

28:                                               ; preds = %23, %19
  %29 = load i8, ptr %7, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 6
  store i32 %30, ptr %31, align 4, !tbaa !21
  %32 = load i8, ptr %8, align 1, !tbaa !9
  %33 = zext i8 %32 to i32
  %34 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 7
  store i32 %33, ptr %34, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %35 = load i8, ptr %7, align 1, !tbaa !9
  %36 = icmp ne i8 %35, 0
  %37 = zext i1 %36 to i64
  %38 = select i1 %36, i32 255, i32 0
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %40 = load i8, ptr %8, align 1, !tbaa !9
  %41 = icmp ne i8 %40, 0
  %42 = zext i1 %41 to i64
  %43 = select i1 %41, i32 255, i32 0
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %45 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %45, ptr %12, align 4, !tbaa !10
  %46 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  %47 = load i32, ptr %46, align 8, !tbaa !12
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %28
  %50 = load ptr, ptr %15, align 8, !tbaa !19
  %51 = getelementptr inbounds ptr, ptr %50, i64 14
  %52 = load ptr, ptr %51, align 8
  %53 = call noundef i32 %52(ptr noundef nonnull align 8 dereferenceable(128) %15)
  br label %54

54:                                               ; preds = %49, %28
  %55 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !23
  %57 = load i8, ptr %11, align 1, !tbaa !9
  %58 = zext i8 %57 to i32
  %59 = trunc i32 %58 to i8
  %60 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 8
  %61 = load i32, ptr %60, align 4, !tbaa !24
  %62 = zext i32 %61 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %56, i8 %59, i64 %62, i1 false)
  %63 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !25
  %65 = load i8, ptr %10, align 1, !tbaa !9
  %66 = zext i8 %65 to i32
  %67 = trunc i32 %66 to i8
  %68 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 8
  %69 = load i32, ptr %68, align 4, !tbaa !24
  %70 = zext i32 %69 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %64, i8 %67, i64 %70, i1 false)
  br label %71

71:                                               ; preds = %97, %54
  %72 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 8
  %73 = load i32, ptr %72, align 4, !tbaa !24
  %74 = mul i32 %73, 8
  %75 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  store i32 %74, ptr %75, align 8, !tbaa !12
  %76 = load i32, ptr %12, align 4, !tbaa !10
  %77 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  %78 = load i32, ptr %77, align 8, !tbaa !12
  %79 = icmp ult i32 %76, %78
  br i1 %79, label %80, label %83

80:                                               ; preds = %71
  %81 = load i32, ptr %12, align 4, !tbaa !10
  %82 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  store i32 %81, ptr %82, align 8, !tbaa !12
  br label %83

83:                                               ; preds = %80, %71
  %84 = getelementptr inbounds %class.XVC_client, ptr %15, i32 0, i32 5
  %85 = load i32, ptr %84, align 8, !tbaa !12
  %86 = load i32, ptr %12, align 4, !tbaa !10
  %87 = sub i32 %86, %85
  store i32 %87, ptr %12, align 4, !tbaa !10
  %88 = call noundef zeroext i1 @_ZN10XVC_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(128) %15, ptr noundef null)
  br i1 %88, label %96, label %89

89:                                               ; preds = %83
  %90 = call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %90, ptr noundef @.str.7)
          to label %91 unwind label %92

91:                                               ; preds = %89
  call void @__cxa_throw(ptr %90, ptr @_ZTISt13runtime_error, ptr @_ZNSt13runtime_errorD1Ev) #6
  unreachable

92:                                               ; preds = %89
  %93 = landingpad { ptr, i32 }
          cleanup
  %94 = extractvalue { ptr, i32 } %93, 0
  store ptr %94, ptr %13, align 8
  %95 = extractvalue { ptr, i32 } %93, 1
  store i32 %95, ptr %14, align 4
  call void @__cxa_free_exception(ptr %90) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %104

96:                                               ; preds = %83
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %12, align 4, !tbaa !10
  %99 = icmp ugt i32 %98, 0
  br i1 %99, label %71, label %100, !llvm.loop !26

100:                                              ; preds = %97
  %101 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %101, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %102

102:                                              ; preds = %100, %18
  %103 = load i32, ptr %5, align 4
  ret i32 %103

104:                                              ; preds = %92
  %105 = load ptr, ptr %13, align 8
  %106 = load i32, ptr %14, align 4
  %107 = insertvalue { ptr, i32 } poison, ptr %105, 0
  %108 = insertvalue { ptr, i32 } %107, i32 %106, 1
  resume { ptr, i32 } %108
}

attributes #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 = { 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 = { nocallback nofree nosync 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 nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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, !11, i64 40}
!13 = !{!"_ZTS10XVC_client", !14, i64 0, !15, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !16, i64 56, !16, i64 88, !11, i64 120, !11, i64 124}
!14 = !{!"_ZTS13JtagInterface", !11, i64 8}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!13, !11, i64 44}
!22 = !{!13, !11, i64 48}
!23 = !{!13, !6, i64 32}
!24 = !{!13, !11, i64 52}
!25 = !{!13, !6, i64 24}
!26 = distinct !{!26, !27}
!27 = !{!"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"

@_ZTISt13runtime_error = external constant ptr
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1

declare i32 @__gxx_personality_v0(...)

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #0

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN10XVC_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(128), ptr noundef) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10XVC_client9toggleClkEhhj(ptr noundef nonnull align 8 dereferenceable(128) %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i32 noundef returned %3) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %5 = icmp eq i32 %3, 0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %15, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr %0, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %10, i64 112
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(128) %0)
  %.pre = load i32, ptr %7, align 8, !tbaa !5
  %14 = icmp eq i32 %.pre, 0
  br label %15

15:                                               ; preds = %9, %6
  %.not21 = phi i1 [ %14, %9 ], [ true, %6 ]
  %16 = zext i8 %1 to i32
  %17 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %16, ptr %17, align 4, !tbaa !18
  %18 = zext i8 %2 to i32
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %18, ptr %19, align 8, !tbaa !19
  %.not19 = icmp ne i8 %1, 0
  %20 = sext i1 %.not19 to i8
  %.not20 = icmp ne i8 %2, 0
  %21 = sext i1 %.not20 to i8
  br i1 %.not21, label %27, label %22

22:                                               ; preds = %15
  %23 = load ptr, ptr %0, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %23, i64 112
  %25 = load ptr, ptr %24, align 8
  %26 = tail call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(128) %0)
  br label %27

27:                                               ; preds = %22, %15
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %0, i64 52
  %31 = load i32, ptr %30, align 4, !tbaa !21
  %32 = zext i32 %31 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %29, i8 %21, i64 %32, i1 false)
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = load i32, ptr %30, align 4, !tbaa !21
  %36 = zext i32 %35 to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %34, i8 %20, i64 %36, i1 false)
  br label %37

37:                                               ; preds = %46, %27
  %.016 = phi i32 [ %3, %27 ], [ %47, %46 ]
  %38 = load i32, ptr %30, align 4, !tbaa !21
  %39 = shl i32 %38, 3
  %spec.select = tail call i32 @llvm.umin.i32(i32 %.016, i32 %39)
  store i32 %spec.select, ptr %7, align 8, !tbaa !5
  %40 = tail call noundef zeroext i1 @_ZN10XVC_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef null)
  br i1 %40, label %46, label %41

41:                                               ; preds = %37
  %42 = tail call ptr @__cxa_allocate_exception(i64 16) #5
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %42, ptr noundef nonnull @.str.7)
          to label %43 unwind label %44

43:                                               ; preds = %41
  tail call void @__cxa_throw(ptr nonnull %42, ptr nonnull @_ZTISt13runtime_error, ptr nonnull @_ZNSt13runtime_errorD1Ev) #6
  unreachable

44:                                               ; preds = %41
  %45 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %42) #5
  resume { ptr, i32 } %45

46:                                               ; preds = %37
  %47 = sub i32 %.016, %spec.select
  %.not22 = icmp eq i32 %47, 0
  br i1 %.not22, label %.loopexit, label %37, !llvm.loop !23

.loopexit:                                        ; preds = %46, %4
  ret i32 %3
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #4

attributes #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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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, !8, i64 40}
!6 = !{!"_ZTS10XVC_client", !7, i64 0, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !8, i64 40, !8, i64 44, !8, i64 48, !8, i64 52, !13, i64 56, !13, i64 88, !8, i64 120, !8, i64 124}
!7 = !{!"_ZTS13JtagInterface", !8, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !9, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !12, i64 0}
!15 = !{!"long", !9, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !10, i64 0}
!18 = !{!6, !8, i64 44}
!19 = !{!6, !8, i64 48}
!20 = !{!6, !12, i64 32}
!21 = !{!6, !8, i64 52}
!22 = !{!6, !12, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass