; 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.file = type { i32, ptr, ptr }
%struct.node = type { [64 x i8], %struct.file_operations, ptr, ptr, ptr }
%struct.file_operations = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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.usb_private_t = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8, i32, i32, i8 }

@FreeRTOS_errno = external global i32, align 4
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1

; 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
define dso_local i32 @usb_open(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca [32 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.file, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 1
  %13 = getelementptr inbounds %struct.file_operations, ptr %12, i32 0, i32 10
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  store ptr %14, ptr %6, align 8, !tbaa !5
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !15
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.usb_t, ptr %15, i32 0, i32 12
  %17 = getelementptr inbounds %struct.usb_private_t, ptr %16, i32 0, i32 12
  %18 = load i8, ptr %17, align 2, !tbaa !16, !range !20, !noundef !21
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %27

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.usb_t, ptr %21, i32 0, i32 12
  %23 = getelementptr inbounds %struct.usb_private_t, ptr %22, i32 0, i32 13
  %24 = load i8, ptr %23, align 1, !tbaa !22, !range !20, !noundef !21
  %25 = trunc i8 %24 to i1
  br i1 %25, label %27, label %26

26:                                               ; preds = %20
  store i32 13, ptr @FreeRTOS_errno, align 4, !tbaa !15
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

27:                                               ; preds = %20, %2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.usb_t, ptr %28, i32 0, i32 12
  %30 = getelementptr inbounds %struct.usb_private_t, ptr %29, i32 0, i32 11
  %31 = load i8, ptr %30, align 1, !tbaa !23, !range !20, !noundef !21
  %32 = trunc i8 %31 to i1
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

34:                                               ; preds = %27
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.usb_t, ptr %35, i32 0, i32 8
  %37 = load i32, ptr %36, align 8, !tbaa !24
  %38 = icmp sle i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i32 22, ptr @FreeRTOS_errno, align 4, !tbaa !15
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

40:                                               ; preds = %34
  %41 = load ptr, ptr %6, 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 6
  %44 = load ptr, ptr %43, align 8, !tbaa !25
  %45 = icmp eq ptr %44, null
  br i1 %45, label %52, label %46

46:                                               ; preds = %40
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.usb_t, ptr %47, i32 0, i32 12
  %49 = getelementptr inbounds %struct.usb_private_t, ptr %48, i32 0, i32 5
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %46, %40
  store i32 12, ptr @FreeRTOS_errno, align 4, !tbaa !15
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %84

53:                                               ; preds = %46
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.usb_t, ptr %54, i32 0, i32 12
  %56 = getelementptr inbounds %struct.usb_private_t, ptr %55, i32 0, i32 11
  store i8 1, ptr %56, align 1, !tbaa !23
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.usb_t, ptr %57, i32 0, i32 12
  %59 = getelementptr inbounds %struct.usb_private_t, ptr %58, i32 0, i32 12
  store i8 1, ptr %59, align 2, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #3
  %60 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.usb_t, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds [32 x i8], ptr %62, i64 0, i64 0
  %64 = call i32 (ptr, i64, ptr, ...) @snprintf_(ptr noundef %60, i64 noundef 32, ptr noundef @.str.1, ptr noundef %63)
  %65 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.usb_t, ptr %67, i32 0, i32 10
  %69 = load i32, ptr %68, align 8, !tbaa !27
  %70 = sext i32 %69 to i64
  %71 = call i64 @xTaskCreate(ptr noundef @usb_read_task, ptr noundef %65, i16 noundef zeroext 512, ptr noundef %66, i64 noundef %70, ptr noundef null)
  %72 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.usb_t, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds [32 x i8], ptr %74, i64 0, i64 0
  %76 = call i32 (ptr, i64, ptr, ...) @snprintf_(ptr noundef %72, i64 noundef 32, ptr noundef @.str.2, ptr noundef %75)
  %77 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.usb_t, ptr %79, i32 0, i32 10
  %81 = load i32, ptr %80, align 8, !tbaa !27
  %82 = sext i32 %81 to i64
  %83 = call i64 @xTaskCreate(ptr noundef @usb_write_task, ptr noundef %77, i16 noundef zeroext 512, ptr noundef %78, i64 noundef %82, ptr noundef null)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  br label %84

84:                                               ; preds = %53, %52, %39, %33, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @usb_read_task(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @usb_write_task(ptr noundef) #1

declare i32 @snprintf_(ptr noundef, i64 noundef, ptr noundef, ...) #2

declare i64 @xTaskCreate(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) #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 8}
!10 = !{!"file", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 144}
!13 = !{!"node", !7, i64 0, !14, i64 64, !6, i64 152, !6, i64 160, !6, i64 168}
!14 = !{!"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}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !19, i64 286}
!17 = !{!"", !7, i64 0, !7, i64 32, !14, i64 64, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !18, i64 208}
!18 = !{!"", !11, 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, !11, i64 72, !19, i64 76, !19, i64 77, !19, i64 78, !19, i64 79, !11, i64 80, !11, i64 84, !19, i64 88}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!17, !19, i64 287}
!23 = !{!17, !19, i64 285}
!24 = !{!17, !11, i64 192}
!25 = !{!17, !6, i64 256}
!26 = !{!17, !6, i64 248}
!27 = !{!17, !11, i64 200}


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

@FreeRTOS_errno = external local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @usb_open(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca [32 x i8], align 16
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 144
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 286
  %9 = load i8, ptr %8, align 2, !tbaa !15, !range !19, !noundef !20
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %11, label %16

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %7, i64 287
  %13 = load i8, ptr %12, align 1, !tbaa !21, !range !19, !noundef !20
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 13, ptr @FreeRTOS_errno, align 4, !tbaa !14
  br label %44

16:                                               ; preds = %11, %2
  %17 = getelementptr inbounds i8, ptr %7, i64 285
  %18 = load i8, ptr %17, align 1, !tbaa !22, !range !19, !noundef !20
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %44, label %20

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %7, i64 192
  %22 = load i32, ptr %21, align 8, !tbaa !23
  %23 = icmp slt i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i32 22, ptr @FreeRTOS_errno, align 4, !tbaa !14
  br label %44

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %7, i64 256
  %27 = load ptr, ptr %26, align 8, !tbaa !24
  %28 = icmp eq ptr %27, null
  br i1 %28, label %33, label %29

29:                                               ; preds = %25
  %30 = getelementptr inbounds i8, ptr %7, i64 248
  %31 = load ptr, ptr %30, align 8, !tbaa !25
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %29, %25
  store i32 12, ptr @FreeRTOS_errno, align 4, !tbaa !14
  br label %44

34:                                               ; preds = %29
  store i8 1, ptr %17, align 1, !tbaa !22
  store i8 1, ptr %8, align 2, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %35 = call i32 (ptr, i64, ptr, ...) @snprintf_(ptr noundef nonnull %3, i64 noundef 32, ptr noundef nonnull @.str.1, ptr noundef nonnull %7) #3
  %36 = getelementptr inbounds i8, ptr %7, i64 200
  %37 = load i32, ptr %36, align 8, !tbaa !26
  %38 = sext i32 %37 to i64
  %39 = call i64 @xTaskCreate(ptr noundef nonnull @usb_read_task, ptr noundef nonnull %3, i16 noundef zeroext 512, ptr noundef nonnull %7, i64 noundef %38, ptr noundef null) #3
  %40 = call i32 (ptr, i64, ptr, ...) @snprintf_(ptr noundef nonnull %3, i64 noundef 32, ptr noundef nonnull @.str.2, ptr noundef nonnull %7) #3
  %41 = load i32, ptr %36, align 8, !tbaa !26
  %42 = sext i32 %41 to i64
  %43 = call i64 @xTaskCreate(ptr noundef nonnull @usb_write_task, ptr noundef nonnull %3, i16 noundef zeroext 512, ptr noundef nonnull %7, i64 noundef %42, ptr noundef null) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  br label %44

44:                                               ; preds = %16, %34, %33, %24, %15
  %.0 = phi i32 [ -1, %24 ], [ -1, %33 ], [ 0, %34 ], [ -1, %15 ], [ 0, %16 ]
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @usb_read_task(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @usb_write_task(ptr noundef) #1

declare i32 @snprintf_(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #2

declare i64 @xTaskCreate(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !10, i64 8}
!6 = !{!"file", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 144}
!12 = !{!"node", !8, i64 0, !13, i64 64, !10, i64 152, !10, i64 160, !10, i64 168}
!13 = !{!"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}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !18, i64 286}
!16 = !{!"", !8, i64 0, !8, i64 32, !13, i64 64, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !7, i64 192, !7, i64 196, !7, i64 200, !7, i64 204, !17, i64 208}
!17 = !{!"", !7, 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, !7, i64 72, !18, i64 76, !18, i64 77, !18, i64 78, !18, i64 79, !7, i64 80, !7, i64 84, !18, i64 88}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !18, i64 287}
!22 = !{!16, !18, i64 285}
!23 = !{!16, !7, i64 192}
!24 = !{!16, !10, i64 256}
!25 = !{!16, !10, i64 248}
!26 = !{!16, !7, i64 200}


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