; LLVM IR from trabucayre/openFPGALoader :: src/remoteBitbang_client.ll (ZN20RemoteBitbang_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.RemoteBitbang_client = type { %class.JtagInterface.base, ptr, i32, i32, i32, i32, i32, i32 }
%class.JtagInterface.base = type <{ ptr, i32 }>

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN20RemoteBitbang_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN20RemoteBitbang_client9toggleClkEhhj(ptr noundef nonnull align 8 dereferenceable(48) %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %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 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
  %12 = load ptr, ptr %6, align 8
  %13 = load i32, ptr %9, align 4, !tbaa !10
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %89

16:                                               ; preds = %4
  %17 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !12
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %16
  %21 = load ptr, ptr %12, align 8, !tbaa !15
  %22 = getelementptr inbounds ptr, ptr %21, i64 14
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(48) %12)
  br label %25

25:                                               ; preds = %20, %16
  %26 = load i8, ptr %7, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 3
  store i32 %27, ptr %28, align 4, !tbaa !17
  %29 = load i8, ptr %8, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 4
  store i32 %30, ptr %31, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  %32 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !17
  %34 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 4
  %35 = load i32, ptr %34, align 8, !tbaa !18
  %36 = or i32 %33, %35
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %10, align 1, !tbaa !9
  %38 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !12
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %25
  %42 = load ptr, ptr %12, align 8, !tbaa !15
  %43 = getelementptr inbounds ptr, ptr %42, i64 14
  %44 = load ptr, ptr %43, align 8
  %45 = call noundef i32 %44(ptr noundef nonnull align 8 dereferenceable(48) %12)
  br label %46

46:                                               ; preds = %41, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !10
  br label %47

47:                                               ; preds = %83, %46
  %48 = load i32, ptr %11, align 4, !tbaa !10
  %49 = load i32, ptr %9, align 4, !tbaa !10
  %50 = icmp ult i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %86

52:                                               ; preds = %47
  %53 = load i32, ptr %11, align 4, !tbaa !10
  %54 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = icmp eq i32 %53, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %52
  %58 = call noundef zeroext i1 @_ZN20RemoteBitbang_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(48) %12, ptr noundef null)
  br label %59

59:                                               ; preds = %57, %52
  %60 = load i8, ptr %10, align 1, !tbaa !9
  %61 = zext i8 %60 to i32
  %62 = add nsw i32 48, %61
  %63 = trunc i32 %62 to i8
  %64 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !19
  %66 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !12
  %68 = add i32 %67, 1
  store i32 %68, ptr %66, align 8, !tbaa !12
  %69 = zext i32 %67 to i64
  %70 = getelementptr inbounds i8, ptr %65, i64 %69
  store i8 %63, ptr %70, align 1, !tbaa !9
  %71 = load i8, ptr %10, align 1, !tbaa !9
  %72 = zext i8 %71 to i32
  %73 = or i32 %72, 4
  %74 = add nsw i32 48, %73
  %75 = trunc i32 %74 to i8
  %76 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = getelementptr inbounds %class.RemoteBitbang_client, ptr %12, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !12
  %80 = add i32 %79, 1
  store i32 %80, ptr %78, align 8, !tbaa !12
  %81 = zext i32 %79 to i64
  %82 = getelementptr inbounds i8, ptr %77, i64 %81
  store i8 %75, ptr %82, align 1, !tbaa !9
  br label %83

83:                                               ; preds = %59
  %84 = load i32, ptr %11, align 4, !tbaa !10
  %85 = add i32 %84, 1
  store i32 %85, ptr %11, align 4, !tbaa !10
  br label %47, !llvm.loop !20

86:                                               ; preds = %51
  %87 = call noundef zeroext i1 @_ZN20RemoteBitbang_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(48) %12, ptr noundef null)
  %88 = load i32, ptr %9, align 4, !tbaa !10
  store i32 %88, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  br label %89

89:                                               ; preds = %86, %15
  %90 = load i32, ptr %5, align 4
  ret i32 %90
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !11, i64 24}
!13 = !{!"_ZTS20RemoteBitbang_client", !14, i64 0, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44}
!14 = !{!"_ZTS13JtagInterface", !11, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = !{!13, !11, i64 28}
!18 = !{!13, !11, i64 32}
!19 = !{!13, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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"

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

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

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

.thread:                                          ; preds = %6
  %9 = zext i8 %1 to i32
  %10 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %9, ptr %10, align 4, !tbaa !12
  %11 = zext i8 %2 to i32
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %11, ptr %12, align 8, !tbaa !13
  br label %28

13:                                               ; preds = %6
  %14 = load ptr, ptr %0, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 112
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %.pre = load i32, ptr %7, align 8, !tbaa !5
  %18 = icmp eq i32 %.pre, 0
  %19 = zext i8 %1 to i32
  %20 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %19, ptr %20, align 4, !tbaa !12
  %21 = zext i8 %2 to i32
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %21, ptr %22, align 8, !tbaa !13
  br i1 %18, label %28, label %23

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

28:                                               ; preds = %.thread, %23, %13
  %29 = or i8 %2, %1
  %30 = add i8 %29, 48
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = or i8 %29, 4
  %33 = add i8 %32, 48
  br label %36

34:                                               ; preds = %41
  %35 = tail call noundef zeroext i1 @_ZN20RemoteBitbang_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef null)
  br label %53

36:                                               ; preds = %28, %41
  %.014 = phi i32 [ 0, %28 ], [ %52, %41 ]
  %37 = load i32, ptr %7, align 8, !tbaa !5
  %38 = icmp eq i32 %.014, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = tail call noundef zeroext i1 @_ZN20RemoteBitbang_client8ll_writeEPh(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef null)
  %.pre15 = load i32, ptr %7, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39, %36
  %42 = phi i32 [ %.pre15, %39 ], [ %37, %36 ]
  %43 = load ptr, ptr %31, align 8, !tbaa !16
  %44 = add i32 %42, 1
  store i32 %44, ptr %7, align 8, !tbaa !5
  %45 = zext i32 %42 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  store i8 %30, ptr %46, align 1, !tbaa !17
  %47 = load ptr, ptr %31, align 8, !tbaa !16
  %48 = load i32, ptr %7, align 8, !tbaa !5
  %49 = add i32 %48, 1
  store i32 %49, ptr %7, align 8, !tbaa !5
  %50 = zext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %47, i64 %50
  store i8 %33, ptr %51, align 1, !tbaa !17
  %52 = add nuw i32 %.014, 1
  %exitcond.not = icmp eq i32 %52, %3
  br i1 %exitcond.not, label %34, label %36, !llvm.loop !18

53:                                               ; preds = %4, %34
  ret i32 %3
}

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

!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 24}
!6 = !{!"_ZTS20RemoteBitbang_client", !7, i64 0, !11, i64 16, !8, i64 24, !8, i64 28, !8, i64 32, !8, i64 36, !8, i64 40, !8, i64 44}
!7 = !{!"_ZTS13JtagInterface", !8, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !8, i64 28}
!13 = !{!6, !8, i64 32}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !10, i64 0}
!16 = !{!6, !11, i64 16}
!17 = !{!9, !9, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass