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

; 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] }
%union.SMBIOS_STRUCTURE_POINTER = type { ptr }
%struct.SMBIOS_TABLE_ENTRY_POINT = type <{ [4 x i8], i8, i8, i8, i8, i16, i8, [5 x i8], [5 x i8], i8, i16, i32, i16, i8 }>
%struct.SMBIOS_STRUCTURE = type { i8, i8, i16 }
%struct.SMBIOS_TABLE_TYPE1 = type <{ %struct.SMBIOS_STRUCTURE, i8, i8, i8, i8, %struct.GUID, i8, i8, i8 }>

@gEfiSmbiosTableGuid = 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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @NetLibGetSystemGuid(ptr noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %union.SMBIOS_STRUCTURE_POINTER, align 1
  %7 = alloca %union.SMBIOS_STRUCTURE_POINTER, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  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
  store ptr null, ptr %5, align 8, !tbaa !5
  %10 = call i64 @EfiGetSystemConfigurationTable(ptr noundef @gEfiSmbiosTableGuid, ptr noundef %5)
  store i64 %10, ptr %4, align 8, !tbaa !9
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %1
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %1
  store i64 -9223372036854775794, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %86

17:                                               ; preds = %13
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SMBIOS_TABLE_ENTRY_POINT, ptr %18, i32 0, i32 11
  %20 = load i32, ptr %19, align 1, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = inttoptr i64 %21 to ptr
  store ptr %22, ptr %6, align 1, !tbaa !15
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SMBIOS_TABLE_ENTRY_POINT, ptr %23, i32 0, i32 11
  %25 = load i32, ptr %24, align 1, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SMBIOS_TABLE_ENTRY_POINT, ptr %26, i32 0, i32 10
  %28 = load i16, ptr %27, align 1, !tbaa !16
  %29 = zext i16 %28 to i32
  %30 = add i32 %25, %29
  %31 = zext i32 %30 to i64
  %32 = inttoptr i64 %31 to ptr
  store ptr %32, ptr %7, align 1, !tbaa !15
  br label %33

33:                                               ; preds = %81, %17
  %34 = load ptr, ptr %6, align 1, !tbaa !15
  %35 = getelementptr inbounds %struct.SMBIOS_STRUCTURE, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 1, !tbaa !17
  %37 = zext i8 %36 to i32
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %51

39:                                               ; preds = %33
  %40 = load ptr, ptr %6, align 1, !tbaa !15
  %41 = getelementptr inbounds %struct.SMBIOS_STRUCTURE, ptr %40, i32 0, i32 1
  %42 = load i8, ptr %41, align 1, !tbaa !19
  %43 = zext i8 %42 to i32
  %44 = icmp slt i32 %43, 25
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  store i64 -9223372036854775794, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %86

46:                                               ; preds = %39
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 1, !tbaa !15
  %49 = getelementptr inbounds %struct.SMBIOS_TABLE_TYPE1, ptr %48, i32 0, i32 5
  %50 = call ptr @CopyMem(ptr noundef %47, ptr noundef %49, i64 noundef 16)
  store i64 0, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %86

51:                                               ; preds = %33
  %52 = load ptr, ptr %6, align 1, !tbaa !15
  %53 = load ptr, ptr %6, align 1, !tbaa !15
  %54 = getelementptr inbounds %struct.SMBIOS_STRUCTURE, ptr %53, i32 0, i32 1
  %55 = load i8, ptr %54, align 1, !tbaa !19
  %56 = zext i8 %55 to i32
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %52, i64 %57
  store ptr %58, ptr %8, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %79, %51
  br label %60

60:                                               ; preds = %66, %59
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !15
  %63 = sext i8 %62 to i32
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %69

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i32 1
  store ptr %68, ptr %8, align 8, !tbaa !5
  br label %60, !llvm.loop !20

69:                                               ; preds = %60
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i32 1
  store ptr %71, ptr %8, align 8, !tbaa !5
  %72 = load i8, ptr %71, align 1, !tbaa !15
  %73 = zext i8 %72 to i32
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %78

75:                                               ; preds = %69
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %8, align 8, !tbaa !5
  store ptr %77, ptr %6, align 1, !tbaa !15
  br label %80

78:                                               ; preds = %69
  br label %79

79:                                               ; preds = %78
  br i1 true, label %59, label %80

80:                                               ; preds = %79, %75
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %6, align 1, !tbaa !15
  %83 = load ptr, ptr %7, align 1, !tbaa !15
  %84 = icmp ult ptr %82, %83
  br i1 %84, label %33, label %85, !llvm.loop !22

85:                                               ; preds = %81
  store i64 -9223372036854775794, ptr %2, align 8
  store i32 1, ptr %9, align 4
  br label %86

86:                                               ; preds = %85, %46, %45, %16
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %87 = load i64, ptr %2, align 8
  ret i64 %87
}

declare i64 @EfiGetSystemConfigurationTable(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !14, i64 24}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !7, i64 10, !7, i64 11, !7, i64 16, !7, i64 21, !13, i64 22, !14, i64 24, !13, i64 28, !7, i64 30}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !13, i64 22}
!17 = !{!18, !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2}
!19 = !{!18, !7, i64 1}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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] }

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

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

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @NetLibGetSystemGuid(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  %3 = call i64 @EfiGetSystemConfigurationTable(ptr noundef nonnull @gEfiSmbiosTableGuid, ptr noundef nonnull %2) #3
  %4 = icmp slt i64 %3, 0
  %5 = load ptr, ptr %2, align 8
  %6 = icmp eq ptr %5, null
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %.loopexit, label %7

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  %9 = load i32, ptr %8, align 1, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  %12 = getelementptr inbounds i8, ptr %5, i64 22
  %13 = load i16, ptr %12, align 1, !tbaa !13
  %14 = zext i16 %13 to i32
  %15 = add i32 %9, %14
  %16 = zext i32 %15 to i64
  %17 = inttoptr i64 %16 to ptr
  br label %18

18:                                               ; preds = %37, %7
  %.sroa.05.0 = phi ptr [ %11, %7 ], [ %38, %37 ]
  %19 = load i8, ptr %.sroa.05.0, align 1, !tbaa !14
  %20 = icmp eq i8 %19, 1
  %21 = getelementptr inbounds i8, ptr %.sroa.05.0, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !16
  br i1 %20, label %23, label %28

23:                                               ; preds = %18
  %24 = icmp ult i8 %22, 25
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %.sroa.05.0, i64 8
  %27 = call ptr @CopyMem(ptr noundef %0, ptr noundef nonnull %26, i64 noundef 16) #3
  br label %.loopexit

28:                                               ; preds = %18
  %29 = zext i8 %22 to i64
  %30 = getelementptr inbounds i8, ptr %.sroa.05.0, i64 %29
  br label %31

31:                                               ; preds = %.backedge, %28
  %.1 = phi ptr [ %30, %28 ], [ %33, %.backedge ]
  %32 = load i8, ptr %.1, align 1, !tbaa !17
  %.not = icmp eq i8 %32, 0
  %33 = getelementptr inbounds i8, ptr %.1, i64 1
  br i1 %.not, label %34, label %.backedge

.backedge:                                        ; preds = %31, %34
  br label %31, !llvm.loop !18

34:                                               ; preds = %31
  %35 = load i8, ptr %33, align 1, !tbaa !17
  %36 = icmp eq i8 %35, 0
  br i1 %36, label %37, label %.backedge

37:                                               ; preds = %34
  %38 = getelementptr inbounds i8, ptr %.1, i64 2
  %39 = icmp ult ptr %38, %17
  br i1 %39, label %18, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %37, %23, %1, %25
  %.013 = phi i64 [ 0, %25 ], [ -9223372036854775794, %1 ], [ -9223372036854775794, %23 ], [ -9223372036854775794, %37 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i64 %.013
}

declare i64 @EfiGetSystemConfigurationTable(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !12, i64 24}
!10 = !{!"", !7, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !11, i64 8, !7, i64 10, !7, i64 11, !7, i64 16, !7, i64 21, !11, i64 22, !12, i64 24, !11, i64 28, !7, i64 30}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 22}
!14 = !{!15, !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 1, !11, i64 2}
!16 = !{!15, !7, i64 1}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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