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

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

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

10:                                               ; preds = %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

11:                                               ; preds = %2
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = icmp ult i64 %12, 4096
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i64 -9223372036854775805, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, 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 6
  %20 = load i16, ptr %19, align 1, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = icmp ne i32 %21, 43605
  br i1 %22, label %42, label %23

23:                                               ; preds = %15
  %24 = load ptr, ptr %6, 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 8
  %27 = load i32, ptr %26, align 1, !tbaa !18
  %28 = icmp ne i32 %27, 1400005704
  br i1 %28, label %42, label %29

29:                                               ; preds = %23
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.boot_params, ptr %30, i32 0, i32 19
  %32 = getelementptr inbounds %struct.setup_header, ptr %31, i32 0, i32 9
  %33 = load i16, ptr %32, align 1, !tbaa !19
  %34 = zext i16 %33 to i32
  %35 = icmp slt i32 %34, 517
  br i1 %35, label %42, label %36

36:                                               ; preds = %29
  %37 = load ptr, ptr %6, 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 27
  %40 = load i8, ptr %39, align 1, !tbaa !20
  %41 = icmp ne i8 %40, 0
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %36
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %44

44:                                               ; preds = %43, %42, %14, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %45 = load i64, ptr %3, align 8
  ret i64 %45
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !14, i64 510}
!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, !15, i64 514}
!19 = !{!12, !14, i64 518}
!20 = !{!12, !7, i64 564}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @LoadLinuxCheckKernelSetup(ptr noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %19, label %4

4:                                                ; preds = %2
  %5 = icmp ult i64 %1, 4096
  br i1 %5, label %19, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 510
  %8 = load i16, ptr %7, align 1, !tbaa !5
  %.not = icmp eq i16 %8, -21931
  br i1 %.not, label %9, label %19

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 514
  %11 = load i32, ptr %10, align 1, !tbaa !15
  %.not8 = icmp eq i32 %11, 1400005704
  br i1 %.not8, label %12, label %19

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 518
  %14 = load i16, ptr %13, align 1, !tbaa !16
  %15 = icmp ult i16 %14, 517
  br i1 %15, label %19, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 564
  %18 = load i8, ptr %17, align 1, !tbaa !17
  %.not9 = icmp eq i8 %18, 0
  %spec.select = select i1 %.not9, i64 -9223372036854775805, i64 0
  br label %19

19:                                               ; preds = %16, %6, %9, %12, %4, %2
  %.0 = phi i64 [ -9223372036854775806, %2 ], [ -9223372036854775805, %4 ], [ -9223372036854775805, %12 ], [ -9223372036854775805, %9 ], [ -9223372036854775805, %6 ], [ %spec.select, %16 ]
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !10, i64 510}
!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, !11, i64 514}
!16 = !{!6, !10, i64 518}
!17 = !{!6, !8, i64 564}


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