; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library (ConvertFromTextUsbClass)

; 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_CLASS_TEXT = type { i8, i8, i8, i8 }
%struct.USB_CLASS_DEVICE_PATH = type <{ %struct.EFI_DEVICE_PATH_PROTOCOL, i16, i16, i8, i8, i8 }>
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }

; 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
declare dso_local ptr @GetNextParamStr(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Strtoi(ptr noundef) #1

declare ptr @CreateDeviceNode(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @ConvertFromTextUsbClass(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = call ptr @CreateDeviceNode(i8 noundef zeroext 3, i8 noundef zeroext 15, i16 noundef zeroext 11)
  store ptr %11, ptr %10, align 8, !tbaa !5
  %12 = call ptr @GetNextParamStr(ptr noundef %3)
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = call ptr @GetNextParamStr(ptr noundef %3)
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.USB_CLASS_TEXT, ptr %14, i32 0, i32 0
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %2
  %19 = call ptr @GetNextParamStr(ptr noundef %3)
  store ptr %19, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call i64 @Strtoi(ptr noundef %20)
  %22 = trunc i64 %21 to i8
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %23, i32 0, i32 3
  store i8 %22, ptr %24, align 1, !tbaa !11
  br label %31

25:                                               ; preds = %2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.USB_CLASS_TEXT, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %29, i32 0, i32 3
  store i8 %28, ptr %30, align 1, !tbaa !11
  br label %31

31:                                               ; preds = %25, %18
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.USB_CLASS_TEXT, ptr %32, i32 0, i32 2
  %34 = load i8, ptr %33, align 1, !tbaa !16
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %31
  %37 = call ptr @GetNextParamStr(ptr noundef %3)
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = call i64 @Strtoi(ptr noundef %38)
  %40 = trunc i64 %39 to i8
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %41, i32 0, i32 4
  store i8 %40, ptr %42, align 1, !tbaa !17
  br label %49

43:                                               ; preds = %31
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.USB_CLASS_TEXT, ptr %44, i32 0, i32 3
  %46 = load i8, ptr %45, align 1, !tbaa !18
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %47, i32 0, i32 4
  store i8 %46, ptr %48, align 1, !tbaa !17
  br label %49

49:                                               ; preds = %43, %36
  %50 = call ptr @GetNextParamStr(ptr noundef %3)
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = call i64 @Strtoi(ptr noundef %51)
  %53 = trunc i64 %52 to i16
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %54, i32 0, i32 1
  store i16 %53, ptr %55, align 1, !tbaa !19
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = call i64 @Strtoi(ptr noundef %56)
  %58 = trunc i64 %57 to i16
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %59, i32 0, i32 2
  store i16 %58, ptr %60, align 1, !tbaa !20
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = call i64 @Strtoi(ptr noundef %61)
  %63 = trunc i64 %62 to i8
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.USB_CLASS_DEVICE_PATH, ptr %64, i32 0, i32 5
  store i8 %63, ptr %65, align 1, !tbaa !21
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %66
}

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, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!11 = !{!12, !7, i64 8}
!12 = !{!"", !13, i64 0, !14, i64 4, !14, i64 6, !7, i64 8, !7, i64 9, !7, i64 10}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !7, i64 1}
!16 = !{!10, !7, i64 2}
!17 = !{!12, !7, i64 9}
!18 = !{!10, !7, i64 3}
!19 = !{!12, !14, i64 4}
!20 = !{!12, !14, i64 6}
!21 = !{!12, !7, i64 10}


; 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 ptr @GetNextParamStr(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @Strtoi(ptr noundef) local_unnamed_addr #0

declare ptr @CreateDeviceNode(i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @ConvertFromTextUsbClass(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = tail call ptr @CreateDeviceNode(i8 noundef zeroext 3, i8 noundef zeroext 15, i16 noundef zeroext 11) #2
  %5 = call ptr @GetNextParamStr(ptr noundef nonnull %3)
  %6 = call ptr @GetNextParamStr(ptr noundef nonnull %3)
  %7 = load i8, ptr %1, align 1, !tbaa !9
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %12, label %8

8:                                                ; preds = %2
  %9 = call ptr @GetNextParamStr(ptr noundef nonnull %3)
  %10 = call i64 @Strtoi(ptr noundef %9)
  %11 = trunc i64 %10 to i8
  br label %15

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %1, i64 1
  %14 = load i8, ptr %13, align 1, !tbaa !11
  br label %15

15:                                               ; preds = %12, %8
  %.sink = phi i8 [ %14, %12 ], [ %11, %8 ]
  %16 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 %.sink, ptr %16, align 1
  %17 = getelementptr inbounds i8, ptr %1, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !12
  %.not17 = icmp eq i8 %18, 0
  br i1 %.not17, label %23, label %19

19:                                               ; preds = %15
  %20 = call ptr @GetNextParamStr(ptr noundef nonnull %3)
  %21 = call i64 @Strtoi(ptr noundef %20)
  %22 = trunc i64 %21 to i8
  br label %26

23:                                               ; preds = %15
  %24 = getelementptr inbounds i8, ptr %1, i64 3
  %25 = load i8, ptr %24, align 1, !tbaa !13
  br label %26

26:                                               ; preds = %23, %19
  %.sink18 = phi i8 [ %25, %23 ], [ %22, %19 ]
  %27 = getelementptr inbounds i8, ptr %4, i64 9
  store i8 %.sink18, ptr %27, align 1
  %28 = call ptr @GetNextParamStr(ptr noundef nonnull %3)
  %29 = call i64 @Strtoi(ptr noundef %5)
  %30 = trunc i64 %29 to i16
  %31 = getelementptr inbounds i8, ptr %4, i64 4
  store i16 %30, ptr %31, align 1, !tbaa !14
  %32 = call i64 @Strtoi(ptr noundef %6)
  %33 = trunc i64 %32 to i16
  %34 = getelementptr inbounds i8, ptr %4, i64 6
  store i16 %33, ptr %34, align 1, !tbaa !18
  %35 = call i64 @Strtoi(ptr noundef %28)
  %36 = trunc i64 %35 to i8
  %37 = getelementptr inbounds i8, ptr %4, i64 10
  store i8 %36, ptr %37, align 1, !tbaa !19
  ret ptr %4
}

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 = { 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, !7, i64 0}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!11 = !{!10, !7, i64 1}
!12 = !{!10, !7, i64 2}
!13 = !{!10, !7, i64 3}
!14 = !{!15, !17, i64 4}
!15 = !{!"", !16, i64 0, !17, i64 4, !17, i64 6, !7, i64 8, !7, i64 9, !7, i64 10}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = !{!15, !17, i64 6}
!19 = !{!15, !7, i64 10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass