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

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

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

; 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
define dso_local void @USBD_GetString(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 1, ptr %9, align 4
  br label %60

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = call zeroext i8 @USBD_GetLen(ptr noundef %15)
  %17 = zext i8 %16 to i16
  %18 = zext i16 %17 to i32
  %19 = mul i32 %18, 2
  %20 = add i32 %19, 2
  %21 = trunc i32 %20 to i16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  store i16 %21, ptr %22, align 2, !tbaa !10
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i8, ptr %7, align 1, !tbaa !9
  %27 = zext i8 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  store i8 %24, ptr %28, align 1, !tbaa !9
  %29 = load i8, ptr %7, align 1, !tbaa !9
  %30 = add i8 %29, 1
  store i8 %30, ptr %7, align 1, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %7, align 1, !tbaa !9
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  store i8 3, ptr %34, align 1, !tbaa !9
  %35 = load i8, ptr %7, align 1, !tbaa !9
  %36 = add i8 %35, 1
  store i8 %36, ptr %7, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %42, %13
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %59

42:                                               ; preds = %37
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i8, ptr %7, align 1, !tbaa !9
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !9
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %8, align 8, !tbaa !5
  %51 = load i8, ptr %7, align 1, !tbaa !9
  %52 = add i8 %51, 1
  store i8 %52, ptr %7, align 1, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i8, ptr %7, align 1, !tbaa !9
  %55 = zext i8 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  store i8 0, ptr %56, align 1, !tbaa !9
  %57 = load i8, ptr %7, align 1, !tbaa !9
  %58 = add i8 %57, 1
  store i8 %58, ptr %7, align 1, !tbaa !9
  br label %37, !llvm.loop !12

59:                                               ; preds = %37
  store i32 0, ptr %9, align 4
  br label %60

60:                                               ; preds = %59, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  %61 = load i32, ptr %9, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @USBD_GetLen(ptr noundef) #1

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nounwind uwtable
define dso_local void @USBD_GetString(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = tail call zeroext i8 @USBD_GetLen(ptr noundef nonnull %0)
  %7 = zext i8 %6 to i16
  %8 = shl nuw nsw i16 %7, 1
  %9 = add nuw nsw i16 %8, 2
  store i16 %9, ptr %2, align 2, !tbaa !5
  %10 = trunc i16 %9 to i8
  store i8 %10, ptr %1, align 1, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 3, ptr %11, align 1, !tbaa !9
  %12 = load i8, ptr %0, align 1, !tbaa !9
  %.not21 = icmp eq i8 %12, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %13 = phi i8 [ %21, %.lr.ph ], [ %12, %5 ]
  %.023 = phi ptr [ %16, %.lr.ph ], [ %0, %5 ]
  %.01922 = phi i8 [ %20, %.lr.ph ], [ 2, %5 ]
  %14 = zext i8 %.01922 to i64
  %15 = getelementptr inbounds i8, ptr %1, i64 %14
  store i8 %13, ptr %15, align 1, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %.023, i64 1
  %17 = or disjoint i8 %.01922, 1
  %18 = zext i8 %17 to i64
  %19 = getelementptr inbounds i8, ptr %1, i64 %18
  store i8 0, ptr %19, align 1, !tbaa !9
  %20 = add i8 %.01922, 2
  %21 = load i8, ptr %16, align 1, !tbaa !9
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph, %5, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @USBD_GetLen(ptr noundef) local_unnamed_addr #0

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

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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