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

; 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._VARIABLE_INFO_ENTRY = type { ptr, %struct.GUID, ptr, i32, i32, i32, i32, i32, i8 }

@gEfiVariableGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [29 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [31 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [85 x i32], align 4
@.str.4 = external hidden unnamed_addr constant [39 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [34 x i32], align 4
@.str.7 = external hidden unnamed_addr constant [35 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiMain(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = 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
  %8 = call i64 @EfiGetSystemConfigurationTable(ptr noundef @gEfiVariableGuid, ptr noundef %7)
  store i64 %8, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %83, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %83

14:                                               ; preds = %11
  %15 = call i64 (ptr, ...) @Print(ptr noundef @.str)
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %45, %14
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %18, i32 0, i32 8
  %20 = load i8, ptr %19, align 4, !tbaa !11
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %41, label %22

22:                                               ; preds = %17
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %25, i32 0, i32 4
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %28, i32 0, i32 7
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %31, i32 0, i32 5
  %33 = load i32, ptr %32, align 8, !tbaa !18
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %34, i32 0, i32 6
  %36 = load i32, ptr %35, align 4, !tbaa !19
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = call i64 (ptr, ...) @Print(ptr noundef @.str.1, ptr noundef %24, i32 noundef %27, i32 noundef %30, i32 noundef %33, i32 noundef %36, ptr noundef %39)
  br label %41

41:                                               ; preds = %22, %17
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %41
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %17, label %48, !llvm.loop !22

48:                                               ; preds = %45
  %49 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %50, ptr %6, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %79, %48
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %52, i32 0, i32 8
  %54 = load i8, ptr %53, align 4, !tbaa !11
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %75

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %59, i32 0, i32 4
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %62, i32 0, i32 7
  %64 = load i32, ptr %63, align 8, !tbaa !17
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %65, i32 0, i32 5
  %67 = load i32, ptr %66, align 8, !tbaa !18
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %68, i32 0, i32 6
  %70 = load i32, ptr %69, align 4, !tbaa !19
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !20
  %74 = call i64 (ptr, ...) @Print(ptr noundef @.str.1, ptr noundef %58, i32 noundef %61, i32 noundef %64, i32 noundef %67, i32 noundef %70, ptr noundef %73)
  br label %75

75:                                               ; preds = %56, %51
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  store ptr %78, ptr %6, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %75
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %51, label %82, !llvm.loop !24

82:                                               ; preds = %79
  br label %89

83:                                               ; preds = %11, %2
  %84 = call i64 (ptr, ...) @Print(ptr noundef @.str.3)
  %85 = call i64 (ptr, ...) @Print(ptr noundef @.str.4)
  %86 = call i64 (ptr, ...) @Print(ptr noundef @.str.5)
  %87 = call i64 (ptr, ...) @Print(ptr noundef @.str.6)
  %88 = call i64 (ptr, ...) @Print(ptr noundef @.str.7)
  br label %89

89:                                               ; preds = %83, %82
  %90 = load i64, ptr %5, align 8, !tbaa !9
  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 i64 %90
}

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

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

declare i64 @Print(ptr noundef, ...) #2

; 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 = { "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, !7, i64 52}
!12 = !{!"_VARIABLE_INFO_ENTRY", !6, i64 0, !13, i64 8, !6, i64 24, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !14, i64 48, !7, i64 52}
!13 = !{!"", !14, i64 0, !15, i64 4, !15, i64 6, !7, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!12, !14, i64 36}
!17 = !{!12, !14, i64 48}
!18 = !{!12, !14, i64 40}
!19 = !{!12, !14, i64 44}
!20 = !{!12, !6, i64 24}
!21 = !{!12, !6, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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

@gEfiVariableGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [29 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [31 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [85 x i32], align 4
@.str.4 = external hidden unnamed_addr constant [39 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [34 x i32], align 4
@.str.7 = external hidden unnamed_addr constant [35 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiMain(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = call i64 @EfiGetSystemConfigurationTable(ptr noundef nonnull @gEfiVariableGuid, ptr noundef nonnull %3) #3
  %5 = icmp sgt i64 %4, -1
  %6 = load ptr, ptr %3, align 8
  %7 = icmp ne ptr %6, null
  %or.cond = select i1 %5, i1 %7, i1 false
  br i1 %or.cond, label %8, label %50

8:                                                ; preds = %2
  %9 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %27, %8
  %.0 = phi ptr [ %10, %8 ], [ %28, %27 ]
  %12 = getelementptr inbounds i8, ptr %.0, i64 52
  %13 = load i8, ptr %12, align 4, !tbaa !9
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %14, label %27

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %.0, i64 8
  %16 = getelementptr inbounds i8, ptr %.0, i64 36
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %.0, i64 48
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %.0, i64 40
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %.0, i64 44
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %.0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.1, ptr noundef nonnull %15, i32 noundef %17, i32 noundef %19, i32 noundef %21, i32 noundef %23, ptr noundef %25) #3
  br label %27

27:                                               ; preds = %14, %11
  %28 = load ptr, ptr %.0, align 8, !tbaa !19
  %.not22 = icmp eq ptr %28, null
  br i1 %.not22, label %29, label %11, !llvm.loop !20

29:                                               ; preds = %27
  %30 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.2) #3
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %48, %29
  %.1 = phi ptr [ %31, %29 ], [ %49, %48 ]
  %33 = getelementptr inbounds i8, ptr %.1, i64 52
  %34 = load i8, ptr %33, align 4, !tbaa !9
  %.not23 = icmp eq i8 %34, 0
  br i1 %.not23, label %48, label %35

35:                                               ; preds = %32
  %36 = getelementptr inbounds i8, ptr %.1, i64 8
  %37 = getelementptr inbounds i8, ptr %.1, i64 36
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = getelementptr inbounds i8, ptr %.1, i64 48
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds i8, ptr %.1, i64 40
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds i8, ptr %.1, i64 44
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %.1, i64 24
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.1, ptr noundef nonnull %36, i32 noundef %38, i32 noundef %40, i32 noundef %42, i32 noundef %44, ptr noundef %46) #3
  br label %48

48:                                               ; preds = %35, %32
  %49 = load ptr, ptr %.1, align 8, !tbaa !19
  %.not24 = icmp eq ptr %49, null
  br i1 %.not24, label %.loopexit, label %32, !llvm.loop !22

50:                                               ; preds = %2
  %51 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.3) #3
  %52 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.4) #3
  %53 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.5) #3
  %54 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.6) #3
  %55 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.7) #3
  br label %.loopexit

.loopexit:                                        ; preds = %48, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i64 %4
}

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

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

declare i64 @Print(ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 52}
!10 = !{!"_VARIABLE_INFO_ENTRY", !6, i64 0, !11, i64 8, !6, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !7, i64 52}
!11 = !{!"", !12, i64 0, !13, i64 4, !13, i64 6, !7, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !12, i64 36}
!15 = !{!10, !12, i64 48}
!16 = !{!10, !12, i64 40}
!17 = !{!10, !12, i64 44}
!18 = !{!10, !6, i64 24}
!19 = !{!10, !6, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass