; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Device_Library/Core/Src (GetString)

; 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
  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
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %51

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

31:                                               ; preds = %36, %10
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %50

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !5
  %39 = load i8, ptr %37, align 1, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i8, ptr %7, align 1, !tbaa !9
  %42 = add i8 %41, 1
  store i8 %42, ptr %7, align 1, !tbaa !9
  %43 = zext i8 %41 to i64
  %44 = getelementptr inbounds i8, ptr %40, i64 %43
  store i8 %39, ptr %44, align 1, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i8, ptr %7, align 1, !tbaa !9
  %47 = add i8 %46, 1
  store i8 %47, ptr %7, align 1, !tbaa !9
  %48 = zext i8 %46 to i64
  %49 = getelementptr inbounds i8, ptr %45, i64 %48
  store i8 0, ptr %49, align 1, !tbaa !9
  br label %31, !llvm.loop !12

50:                                               ; preds = %31
  br label %51

51:                                               ; preds = %50, %3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret void
}

; 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 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %4

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

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

.loopexit:                                        ; preds = %.lr.ph, %4, %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