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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.VENDOR_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID }
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }
%struct.SAS_DEVICE_PATH = type <{ %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.GUID, i32, i64, i64, i16, i16 }>

@gEfiSasDevicePathGuid = external global %struct.GUID, align 4

; 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 i64 @AppendCSDNum(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @DevPathSerialVendor(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 i32, align 4
  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
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %2
  store i32 1, ptr %7, align 4
  br label %49

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %17, i32 0, i32 1
  %19 = call i64 @AppendCSDGuid(ptr noundef %16, ptr noundef %18)
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.VENDOR_DEVICE_PATH, ptr %20, i32 0, i32 1
  %22 = call zeroext i8 @CompareGuid(ptr noundef @gEfiSasDevicePathGuid, ptr noundef %21)
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %48

24:                                               ; preds = %14
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SAS_DEVICE_PATH, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 1, !tbaa !9
  %30 = call i64 @AppendCSDNum(ptr noundef %26, i64 noundef %29)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SAS_DEVICE_PATH, ptr %32, i32 0, i32 4
  %34 = load i64, ptr %33, align 1, !tbaa !16
  %35 = call i64 @AppendCSDNum(ptr noundef %31, i64 noundef %34)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SAS_DEVICE_PATH, ptr %37, i32 0, i32 5
  %39 = load i16, ptr %38, align 1, !tbaa !17
  %40 = zext i16 %39 to i64
  %41 = call i64 @AppendCSDNum(ptr noundef %36, i64 noundef %40)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SAS_DEVICE_PATH, ptr %43, i32 0, i32 6
  %45 = load i16, ptr %44, align 1, !tbaa !18
  %46 = zext i16 %45 to i64
  %47 = call i64 @AppendCSDNum(ptr noundef %42, i64 noundef %46)
  br label %48

48:                                               ; preds = %24, %14
  store i32 0, ptr %7, align 4
  br label %49

49:                                               ; preds = %48, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %50 = load i32, ptr %7, align 4
  switch i32 %50, label %52 [
    i32 0, label %51
    i32 1, label %51
  ]

51:                                               ; preds = %49, %49
  ret void

52:                                               ; preds = %49
  unreachable
}

declare zeroext i8 @CompareGuid(ptr 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, !15, i64 24}
!10 = !{!"", !11, i64 0, !12, i64 4, !13, i64 20, !15, i64 24, !15, i64 32, !14, i64 40, !14, i64 42}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!12 = !{!"", !13, i64 0, !14, i64 4, !14, i64 6, !7, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!10, !15, i64 32}
!17 = !{!10, !14, i64 40}
!18 = !{!10, !14, i64 42}


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

%struct.GUID = type { i32, i16, i16, [8 x i8] }

@gEfiSasDevicePathGuid = external global %struct.GUID, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local void @DevPathSerialVendor(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %24, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = tail call i64 @AppendCSDGuid(ptr noundef nonnull %1, ptr noundef nonnull %6)
  %8 = tail call zeroext i8 @CompareGuid(ptr noundef nonnull @gEfiSasDevicePathGuid, ptr noundef nonnull %6) #2
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %24, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i64, ptr %10, align 1, !tbaa !5
  %12 = tail call i64 @AppendCSDNum(ptr noundef nonnull %1, i64 noundef %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load i64, ptr %13, align 1, !tbaa !14
  %15 = tail call i64 @AppendCSDNum(ptr noundef nonnull %1, i64 noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load i16, ptr %16, align 1, !tbaa !15
  %18 = zext i16 %17 to i64
  %19 = tail call i64 @AppendCSDNum(ptr noundef nonnull %1, i64 noundef %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 42
  %21 = load i16, ptr %20, align 1, !tbaa !16
  %22 = zext i16 %21 to i64
  %23 = tail call i64 @AppendCSDNum(ptr noundef nonnull %1, i64 noundef %22)
  br label %24

24:                                               ; preds = %5, %9, %2
  ret void
}

declare zeroext i8 @CompareGuid(ptr noundef, ptr noundef) 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 = { 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, !13, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 4, !11, i64 20, !13, i64 24, !13, i64 32, !12, i64 40, !12, i64 42}
!7 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !12, i64 4, !12, i64 6, !8, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!6, !13, i64 32}
!15 = !{!6, !12, i64 40}
!16 = !{!6, !12, i64 42}


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