; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/usb/stm32 (usb)

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

%struct.usb_t = type { [32 x i8], [32 x i8], %struct.file_operations, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, %struct.usb_private_t }
%struct.file_operations = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.usb_private_t = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8, i32, i32, i8 }

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @usb_transmit(ptr noundef, ptr noundef, i16 noundef zeroext) #1

declare void @vTaskDelay(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @usb_write_task(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.usb_t, ptr %7, i32 0, i32 12
  %9 = getelementptr inbounds %struct.usb_private_t, ptr %8, i32 0, i32 8
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  call void @vTaskDelay(i32 noundef 2000)
  br label %11

11:                                               ; preds = %48, %22, %1
  br label %12

12:                                               ; preds = %11
  %13 = call zeroext i8 @CDC_Busy_FS()
  %14 = zext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %22, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.usb_t, ptr %17, i32 0, i32 12
  %19 = getelementptr inbounds %struct.usb_private_t, ptr %18, i32 0, i32 16
  %20 = load i8, ptr %19, align 8, !tbaa !15, !range !16, !noundef !17
  %21 = trunc i8 %20 to i1
  br i1 %21, label %23, label %22

22:                                               ; preds = %16, %12
  call void @vTaskDelay(i32 noundef 10)
  br label %11

23:                                               ; preds = %16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.usb_t, ptr %24, i32 0, i32 12
  %26 = getelementptr inbounds %struct.usb_private_t, ptr %25, i32 0, i32 5
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.usb_t, ptr %29, i32 0, i32 8
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = trunc i32 %31 to i16
  %33 = call i32 @ring_buf_read(ptr noundef %27, ptr noundef %28, i16 noundef zeroext %32)
  %34 = trunc i32 %33 to i16
  store i16 %34, ptr %5, align 2, !tbaa !20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i16, ptr %5, align 2, !tbaa !20
  %38 = call i32 @usb_transmit(ptr noundef %35, ptr noundef %36, i16 noundef zeroext %37)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %23
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.usb_t, ptr %41, i32 0, i32 12
  %43 = getelementptr inbounds %struct.usb_private_t, ptr %42, i32 0, i32 9
  store i32 1, ptr %43, align 8, !tbaa !22
  br label %48

44:                                               ; preds = %23
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.usb_t, ptr %45, i32 0, i32 12
  %47 = getelementptr inbounds %struct.usb_private_t, ptr %46, i32 0, i32 9
  store i32 0, ptr %47, align 8, !tbaa !22
  br label %48

48:                                               ; preds = %44, %40
  br label %11
}

declare zeroext i8 @CDC_Busy_FS() #2

declare i32 @ring_buf_read(ptr noundef, ptr noundef, i16 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 272}
!10 = !{!"", !7, i64 0, !7, i64 32, !11, i64 64, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !12, i64 192, !12, i64 196, !12, i64 200, !12, i64 204, !13, i64 208}
!11 = !{!"file_operations", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !14, i64 76, !14, i64 77, !14, i64 78, !14, i64 79, !12, i64 80, !12, i64 84, !14, i64 88}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !14, i64 296}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !6, i64 248}
!19 = !{!10, !12, i64 192}
!20 = !{!21, !21, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!10, !12, i64 280}


; 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: nounwind uwtable
declare dso_local i32 @usb_transmit(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare void @vTaskDelay(i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @usb_write_task(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 272
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @vTaskDelay(i32 noundef 2000) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 296
  %5 = getelementptr inbounds i8, ptr %0, i64 248
  %6 = getelementptr inbounds i8, ptr %0, i64 192
  %7 = getelementptr inbounds i8, ptr %0, i64 280
  br label %.backedge

.backedge:                                        ; preds = %.backedge.backedge, %1
  %8 = tail call zeroext i8 @CDC_Busy_FS() #3
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %9, label %12

9:                                                ; preds = %.backedge
  %10 = load i8, ptr %4, align 8, !tbaa !14, !range !15, !noundef !16
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %13, label %12

12:                                               ; preds = %9, %.backedge
  tail call void @vTaskDelay(i32 noundef 10) #3
  br label %.backedge.backedge

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !17
  %15 = load i32, ptr %6, align 8, !tbaa !18
  %16 = trunc i32 %15 to i16
  %17 = tail call i32 @ring_buf_read(ptr noundef %14, ptr noundef %3, i16 noundef zeroext %16) #3
  %18 = trunc i32 %17 to i16
  %19 = tail call i32 @usb_transmit(ptr noundef nonnull %0, ptr noundef %3, i16 noundef zeroext %18)
  %.not10 = icmp eq i32 %19, 0
  br i1 %.not10, label %21, label %20

20:                                               ; preds = %13
  store i32 1, ptr %7, align 8, !tbaa !19
  br label %.backedge.backedge

.backedge.backedge:                               ; preds = %20, %21, %12
  br label %.backedge

21:                                               ; preds = %13
  store i32 0, ptr %7, align 8, !tbaa !19
  br label %.backedge.backedge
}

declare zeroext i8 @CDC_Busy_FS() local_unnamed_addr #1

declare i32 @ring_buf_read(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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 = { noreturn 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 #3 = { 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, !10, i64 272}
!6 = !{!"", !7, i64 0, !7, i64 32, !9, i64 64, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !12, i64 208}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"file_operations", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !11, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !13, i64 76, !13, i64 77, !13, i64 78, !13, i64 79, !11, i64 80, !11, i64 84, !13, i64 88}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!6, !13, i64 296}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !10, i64 248}
!18 = !{!6, !11, i64 192}
!19 = !{!6, !11, i64 280}


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