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

; 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.boot_params = type { %struct.screen_info, [20 x i8], [4 x i8], i64, [16 x i8], [16 x i8], [16 x i8], [16 x i8], [16 x i8], [16 x i8], [128 x i8], [128 x i8], %struct.efi_info, i32, i32, i8, i8, i8, [6 x i8], %struct.setup_header, [40 x i8], [16 x i32], [128 x %struct.e820_entry], [48 x i8], [492 x i8], [276 x i8] }
%struct.screen_info = type <{ i8, i8, i16, i16, i8, i8, i8, i8, i16, i16, i8, i8, i16, i16, i16, i16, i32, i32, i16, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, i16, i16, i16, i16, i32, [6 x i8] }>
%struct.efi_info = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.setup_header = type <{ i8, i16, i32, i16, i16, i16, i16, i16, i32, i16, i16, i16, i16, i16, i8, i8, i16, i32, i32, i32, i32, i16, i8, i8, i32, i32, i32, i8, i8, i16, i32, i32, i64, i32, i32, i64, i64, i32, i32 }>
%struct.e820_entry = type <{ i64, i64, i32 }>

@.str.1 = external hidden unnamed_addr constant [48 x i8], align 1
@gImageHandle = external global ptr, align 8
@gST = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

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

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @LoadLinux(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call i64 @BasicKernelSetupCheck(ptr noundef %9)
  store i64 %10, ptr %6, align 8, !tbaa !9
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %14, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %99

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.boot_params, ptr %17, i32 0, i32 19
  %19 = getelementptr inbounds %struct.setup_header, ptr %18, i32 0, i32 9
  %20 = load i16, ptr %19, align 1, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = icmp slt i32 %21, 517
  br i1 %22, label %29, label %23

23:                                               ; preds = %15
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.boot_params, ptr %24, i32 0, i32 19
  %26 = getelementptr inbounds %struct.setup_header, ptr %25, i32 0, i32 27
  %27 = load i8, ptr %26, align 1, !tbaa !18
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %23, %15
  store i64 -9223372036854775805, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %99

30:                                               ; preds = %23
  call void @InitLinuxDescriptorTables()
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = ptrtoint ptr %31 to i64
  %33 = trunc i64 %32 to i32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.boot_params, ptr %34, i32 0, i32 19
  %36 = getelementptr inbounds %struct.setup_header, ptr %35, i32 0, i32 17
  store i32 %33, ptr %36, align 1, !tbaa !19
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.boot_params, ptr %37, i32 0, i32 19
  %39 = getelementptr inbounds %struct.setup_header, ptr %38, i32 0, i32 9
  %40 = load i16, ptr %39, align 1, !tbaa !11
  %41 = zext i16 %40 to i32
  %42 = icmp sge i32 %41, 524
  br i1 %42, label %43, label %80

43:                                               ; preds = %30
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.boot_params, ptr %44, i32 0, i32 19
  %46 = getelementptr inbounds %struct.setup_header, ptr %45, i32 0, i32 38
  %47 = load i32, ptr %46, align 1, !tbaa !20
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %80

49:                                               ; preds = %43
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.boot_params, ptr %50, i32 0, i32 19
  %52 = getelementptr inbounds %struct.setup_header, ptr %51, i32 0, i32 29
  %53 = load i16, ptr %52, align 1, !tbaa !21
  %54 = zext i16 %53 to i32
  %55 = and i32 %54, 8
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %80

57:                                               ; preds = %49
  br label %58

58:                                               ; preds = %57
  %59 = call zeroext i8 @DebugPrintEnabled()
  %60 = icmp ne i8 %59, 0
  br i1 %60, label %61, label %73

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  %63 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %62
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.boot_params, ptr %66, i32 0, i32 19
  %68 = getelementptr inbounds %struct.setup_header, ptr %67, i32 0, i32 38
  %69 = load i32, ptr %68, align 1, !tbaa !20
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.1, i32 noundef %69)
  br label %70

70:                                               ; preds = %65, %62
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72, %58
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  call void @DisableInterrupts()
  %76 = load ptr, ptr @gImageHandle, align 8, !tbaa !5
  %77 = load ptr, ptr @gST, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  call void @JumpToUefiKernel(ptr noundef %76, ptr noundef %77, ptr noundef %78, ptr noundef %79)
  br label %80

80:                                               ; preds = %75, %49, %43, %30
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = call i64 @SetupLinuxBootParams(ptr noundef %81)
  br label %83

83:                                               ; preds = %80
  %84 = call zeroext i8 @DebugPrintEnabled()
  %85 = icmp ne i8 %84, 0
  br i1 %85, label %86, label %94

86:                                               ; preds = %83
  br label %87

87:                                               ; preds = %86
  %88 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %89 = icmp ne i8 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %87
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.2)
  br label %91

91:                                               ; preds = %90, %87
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93, %83
  br label %95

95:                                               ; preds = %94
  br label %96

96:                                               ; preds = %95
  call void @DisableInterrupts()
  call void @SetLinuxDescriptorTables()
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  call void @JumpToKernel(ptr noundef %97, ptr noundef %98)
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %99

99:                                               ; preds = %96, %29, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %100 = load i64, ptr %3, align 8
  ret i64 %100
}

declare void @InitLinuxDescriptorTables() #2

declare void @DisableInterrupts() #2

declare void @JumpToUefiKernel(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @SetupLinuxBootParams(ptr noundef) #1

declare void @SetLinuxDescriptorTables() #2

declare void @JumpToKernel(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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !14, i64 518}
!12 = !{!"boot_params", !13, i64 0, !7, i64 64, !7, i64 84, !10, i64 88, !7, i64 96, !7, i64 112, !7, i64 128, !7, i64 144, !7, i64 160, !7, i64 176, !7, i64 192, !7, i64 320, !16, i64 448, !15, i64 480, !15, i64 484, !7, i64 488, !7, i64 489, !7, i64 490, !7, i64 491, !17, i64 497, !7, i64 616, !7, i64 656, !7, i64 720, !7, i64 3280, !7, i64 3328, !7, i64 3820}
!13 = !{!"screen_info", !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !14, i64 10, !14, i64 12, !7, i64 14, !7, i64 15, !14, i64 16, !14, i64 18, !14, i64 20, !14, i64 22, !15, i64 24, !15, i64 28, !14, i64 32, !14, i64 34, !14, i64 36, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !14, i64 46, !14, i64 48, !14, i64 50, !14, i64 52, !15, i64 54, !7, i64 58}
!14 = !{!"short", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"efi_info", !15, i64 0, !15, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !15, i64 28}
!17 = !{!"setup_header", !7, i64 0, !14, i64 1, !15, i64 3, !14, i64 7, !14, i64 9, !14, i64 11, !14, i64 13, !14, i64 15, !15, i64 17, !14, i64 21, !14, i64 23, !14, i64 25, !14, i64 27, !14, i64 29, !7, i64 31, !7, i64 32, !14, i64 33, !15, i64 35, !15, i64 39, !15, i64 43, !15, i64 47, !14, i64 51, !7, i64 53, !7, i64 54, !15, i64 55, !15, i64 59, !15, i64 63, !7, i64 67, !7, i64 68, !14, i64 69, !15, i64 71, !15, i64 75, !10, i64 79, !15, i64 87, !15, i64 91, !10, i64 95, !10, i64 103, !15, i64 111, !15, i64 115}
!18 = !{!12, !7, i64 564}
!19 = !{!12, !15, i64 532}
!20 = !{!12, !15, i64 612}
!21 = !{!12, !14, i64 566}


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

@.str.1 = external hidden unnamed_addr constant [48 x i8], align 1
@gImageHandle = external local_unnamed_addr global ptr, align 8
@gST = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @LoadLinux(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @BasicKernelSetupCheck(ptr noundef %1)
  %4 = icmp slt i64 %3, 0
  br i1 %4, label %41, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 518
  %7 = load i16, ptr %6, align 1, !tbaa !5
  %8 = icmp ult i16 %7, 517
  br i1 %8, label %41, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %1, i64 564
  %11 = load i8, ptr %10, align 1, !tbaa !15
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %41, label %12

12:                                               ; preds = %9
  tail call void @InitLinuxDescriptorTables() #2
  %13 = ptrtoint ptr %0 to i64
  %14 = trunc i64 %13 to i32
  %15 = getelementptr inbounds i8, ptr %1, i64 532
  store i32 %14, ptr %15, align 1, !tbaa !16
  %16 = load i16, ptr %6, align 1, !tbaa !5
  %17 = icmp ugt i16 %16, 523
  br i1 %17, label %18, label %34

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %1, i64 612
  %20 = load i32, ptr %19, align 1, !tbaa !17
  %.not18 = icmp eq i32 %20, 0
  br i1 %.not18, label %34, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %1, i64 566
  %23 = load i16, ptr %22, align 1, !tbaa !18
  %24 = and i16 %23, 8
  %.not19 = icmp eq i16 %24, 0
  br i1 %.not19, label %34, label %25

25:                                               ; preds = %21
  %26 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not20 = icmp eq i8 %26, 0
  br i1 %.not20, label %31, label %27

27:                                               ; preds = %25
  %28 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #2
  %.not21 = icmp eq i8 %28, 0
  br i1 %.not21, label %31, label %29

29:                                               ; preds = %27
  %30 = load i32, ptr %19, align 1, !tbaa !17
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.1, i32 noundef %30) #2
  br label %31

31:                                               ; preds = %27, %29, %25
  tail call void @DisableInterrupts() #2
  %32 = load ptr, ptr @gImageHandle, align 8, !tbaa !19
  %33 = load ptr, ptr @gST, align 8, !tbaa !19
  tail call void @JumpToUefiKernel(ptr noundef %32, ptr noundef %33, ptr noundef nonnull %1, ptr noundef %0) #2
  br label %34

34:                                               ; preds = %31, %21, %18, %12
  %35 = tail call i64 @SetupLinuxBootParams(ptr noundef nonnull %1)
  %36 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not22 = icmp eq i8 %36, 0
  br i1 %.not22, label %40, label %37

37:                                               ; preds = %34
  %38 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #2
  %.not23 = icmp eq i8 %38, 0
  br i1 %.not23, label %40, label %39

39:                                               ; preds = %37
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.2) #2
  br label %40

40:                                               ; preds = %37, %39, %34
  tail call void @DisableInterrupts() #2
  tail call void @SetLinuxDescriptorTables() #2
  tail call void @JumpToKernel(ptr noundef %0, ptr noundef nonnull %1) #2
  br label %41

41:                                               ; preds = %5, %9, %2, %40
  %.0 = phi i64 [ 0, %40 ], [ %3, %2 ], [ -9223372036854775805, %9 ], [ -9223372036854775805, %5 ]
  ret i64 %.0
}

declare void @InitLinuxDescriptorTables() local_unnamed_addr #1

declare void @DisableInterrupts() local_unnamed_addr #1

declare void @JumpToUefiKernel(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare void @SetLinuxDescriptorTables() local_unnamed_addr #1

declare void @JumpToKernel(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, !10, i64 518}
!6 = !{!"boot_params", !7, i64 0, !8, i64 64, !8, i64 84, !12, i64 88, !8, i64 96, !8, i64 112, !8, i64 128, !8, i64 144, !8, i64 160, !8, i64 176, !8, i64 192, !8, i64 320, !13, i64 448, !11, i64 480, !11, i64 484, !8, i64 488, !8, i64 489, !8, i64 490, !8, i64 491, !14, i64 497, !8, i64 616, !8, i64 656, !8, i64 720, !8, i64 3280, !8, i64 3328, !8, i64 3820}
!7 = !{!"screen_info", !8, i64 0, !8, i64 1, !10, i64 2, !10, i64 4, !8, i64 6, !8, i64 7, !8, i64 8, !8, i64 9, !10, i64 10, !10, i64 12, !8, i64 14, !8, i64 15, !10, i64 16, !10, i64 18, !10, i64 20, !10, i64 22, !11, i64 24, !11, i64 28, !10, i64 32, !10, i64 34, !10, i64 36, !8, i64 38, !8, i64 39, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 43, !8, i64 44, !8, i64 45, !10, i64 46, !10, i64 48, !10, i64 50, !10, i64 52, !11, i64 54, !8, i64 58}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"efi_info", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!14 = !{!"setup_header", !8, i64 0, !10, i64 1, !11, i64 3, !10, i64 7, !10, i64 9, !10, i64 11, !10, i64 13, !10, i64 15, !11, i64 17, !10, i64 21, !10, i64 23, !10, i64 25, !10, i64 27, !10, i64 29, !8, i64 31, !8, i64 32, !10, i64 33, !11, i64 35, !11, i64 39, !11, i64 43, !11, i64 47, !10, i64 51, !8, i64 53, !8, i64 54, !11, i64 55, !11, i64 59, !11, i64 63, !8, i64 67, !8, i64 68, !10, i64 69, !11, i64 71, !11, i64 75, !12, i64 79, !11, i64 87, !11, i64 91, !12, i64 95, !12, i64 103, !11, i64 111, !11, i64 115}
!15 = !{!6, !8, i64 564}
!16 = !{!6, !11, i64 532}
!17 = !{!6, !11, i64 612}
!18 = !{!6, !10, i64 566}
!19 = !{!20, !20, i64 0}
!20 = !{!"any pointer", !8, i64 0}


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