; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/SecurityPkg/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 }

@.str.5 = external hidden unnamed_addr constant [31 x i32], align 4
@gEfiVariableGuid = external global %struct.GUID, align 4
@gEfiAuthenticatedVariableGuid = external global %struct.GUID, align 4
@.str.7 = external hidden unnamed_addr constant [29 x i32], align 4
@.str.8 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.9 = external hidden unnamed_addr constant [85 x i32], align 4
@.str.10 = external hidden unnamed_addr constant [39 x i32], align 4
@.str.11 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.12 = external hidden unnamed_addr constant [34 x i32], align 4
@.str.13 = external hidden unnamed_addr constant [35 x i32], 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 @PrintInfoFromSmm() #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiMain(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 ptr, align 8
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = call i64 @EfiGetSystemConfigurationTable(ptr noundef @gEfiVariableGuid, ptr noundef %8)
  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 %16, label %13

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

16:                                               ; preds = %13, %2
  %17 = call i64 @EfiGetSystemConfigurationTable(ptr noundef @gEfiAuthenticatedVariableGuid, ptr noundef %8)
  store i64 %17, ptr %6, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %13
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %31

24:                                               ; preds = %21, %18
  %25 = call i64 @PrintInfoFromSmm()
  store i64 %25, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %30, label %28

28:                                               ; preds = %24
  %29 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %29, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %114

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30, %21
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %106, label %34

34:                                               ; preds = %31
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %106

37:                                               ; preds = %34
  %38 = call i64 (ptr, ...) @Print(ptr noundef @.str.7)
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %39, ptr %7, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %68, %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %41, i32 0, i32 8
  %43 = load i8, ptr %42, align 4, !tbaa !11
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %64, label %45

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %48, i32 0, i32 4
  %50 = load i32, ptr %49, align 4, !tbaa !16
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %51, i32 0, i32 7
  %53 = load i32, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 8, !tbaa !18
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %57, i32 0, i32 6
  %59 = load i32, ptr %58, align 4, !tbaa !19
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !20
  %63 = call i64 (ptr, ...) @Print(ptr noundef @.str.5, ptr noundef %47, i32 noundef %50, i32 noundef %53, i32 noundef %56, i32 noundef %59, ptr noundef %62)
  br label %64

64:                                               ; preds = %45, %40
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %64
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %40, label %71, !llvm.loop !22

71:                                               ; preds = %68
  %72 = call i64 (ptr, ...) @Print(ptr noundef @.str.8)
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %73, ptr %7, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %102, %71
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %75, i32 0, i32 8
  %77 = load i8, ptr %76, align 4, !tbaa !11
  %78 = icmp ne i8 %77, 0
  br i1 %78, label %79, label %98

79:                                               ; preds = %74
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %82, i32 0, i32 4
  %84 = load i32, ptr %83, align 4, !tbaa !16
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %85, i32 0, i32 7
  %87 = load i32, ptr %86, align 8, !tbaa !17
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %88, i32 0, i32 5
  %90 = load i32, ptr %89, align 8, !tbaa !18
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %91, i32 0, i32 6
  %93 = load i32, ptr %92, align 4, !tbaa !19
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !20
  %97 = call i64 (ptr, ...) @Print(ptr noundef @.str.5, ptr noundef %81, i32 noundef %84, i32 noundef %87, i32 noundef %90, i32 noundef %93, ptr noundef %96)
  br label %98

98:                                               ; preds = %79, %74
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._VARIABLE_INFO_ENTRY, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !21
  store ptr %101, ptr %7, align 8, !tbaa !5
  br label %102

102:                                              ; preds = %98
  %103 = load ptr, ptr %7, align 8, !tbaa !5
  %104 = icmp ne ptr %103, null
  br i1 %104, label %74, label %105, !llvm.loop !24

105:                                              ; preds = %102
  br label %112

106:                                              ; preds = %34, %31
  %107 = call i64 (ptr, ...) @Print(ptr noundef @.str.9)
  %108 = call i64 (ptr, ...) @Print(ptr noundef @.str.10)
  %109 = call i64 (ptr, ...) @Print(ptr noundef @.str.11)
  %110 = call i64 (ptr, ...) @Print(ptr noundef @.str.12)
  %111 = call i64 (ptr, ...) @Print(ptr noundef @.str.13)
  br label %112

112:                                              ; preds = %106, %105
  %113 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %113, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %114

114:                                              ; preds = %112, %28
  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
  %115 = load i64, ptr %3, align 8
  ret i64 %115
}

declare i64 @EfiGetSystemConfigurationTable(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, !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] }

@.str.5 = external hidden unnamed_addr constant [31 x i32], align 4
@gEfiVariableGuid = external global %struct.GUID, align 4
@gEfiAuthenticatedVariableGuid = external global %struct.GUID, align 4
@.str.7 = external hidden unnamed_addr constant [29 x i32], align 4
@.str.8 = external hidden unnamed_addr constant [25 x i32], align 4
@.str.9 = external hidden unnamed_addr constant [85 x i32], align 4
@.str.10 = external hidden unnamed_addr constant [39 x i32], align 4
@.str.11 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.12 = external hidden unnamed_addr constant [34 x i32], align 4
@.str.13 = external hidden unnamed_addr constant [35 x i32], 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @PrintInfoFromSmm() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiMain(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %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 slt i64 %4, 0
  %6 = load ptr, ptr %3, align 8
  %7 = icmp eq ptr %6, null
  %or.cond = select i1 %5, i1 true, i1 %7
  br i1 %or.cond, label %8, label %11

8:                                                ; preds = %2
  %9 = call i64 @EfiGetSystemConfigurationTable(ptr noundef nonnull @gEfiAuthenticatedVariableGuid, ptr noundef nonnull %3) #3
  %.pre = load ptr, ptr %3, align 8
  %10 = icmp eq ptr %.pre, null
  br label %11

11:                                               ; preds = %2, %8
  %12 = phi i1 [ %10, %8 ], [ false, %2 ]
  %.029 = phi i64 [ %9, %8 ], [ %4, %2 ]
  %13 = icmp slt i64 %.029, 0
  %or.cond3 = select i1 %13, i1 true, i1 %12
  br i1 %or.cond3, label %14, label %17

14:                                               ; preds = %11
  %15 = call i64 @PrintInfoFromSmm()
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %.thread, label %.loopexit

17:                                               ; preds = %11
  %18 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.7) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %36, %17
  %.0 = phi ptr [ %19, %17 ], [ %37, %36 ]
  %21 = getelementptr inbounds i8, ptr %.0, i64 52
  %22 = load i8, ptr %21, align 4, !tbaa !9
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %23, label %36

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %.0, i64 8
  %25 = getelementptr inbounds i8, ptr %.0, i64 36
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %.0, i64 48
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %.0, i64 40
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %.0, i64 44
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = getelementptr inbounds i8, ptr %.0, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.5, ptr noundef nonnull %24, i32 noundef %26, i32 noundef %28, i32 noundef %30, i32 noundef %32, ptr noundef %34) #3
  br label %36

36:                                               ; preds = %23, %20
  %37 = load ptr, ptr %.0, align 8, !tbaa !19
  %.not37 = icmp eq ptr %37, null
  br i1 %.not37, label %38, label %20, !llvm.loop !20

38:                                               ; preds = %36
  %39 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.8) #3
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %57, %38
  %.1 = phi ptr [ %40, %38 ], [ %58, %57 ]
  %42 = getelementptr inbounds i8, ptr %.1, i64 52
  %43 = load i8, ptr %42, align 4, !tbaa !9
  %.not38 = icmp eq i8 %43, 0
  br i1 %.not38, label %57, label %44

44:                                               ; preds = %41
  %45 = getelementptr inbounds i8, ptr %.1, i64 8
  %46 = getelementptr inbounds i8, ptr %.1, i64 36
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = getelementptr inbounds i8, ptr %.1, i64 48
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = getelementptr inbounds i8, ptr %.1, i64 40
  %51 = load i32, ptr %50, align 8, !tbaa !16
  %52 = getelementptr inbounds i8, ptr %.1, i64 44
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = getelementptr inbounds i8, ptr %.1, i64 24
  %55 = load ptr, ptr %54, align 8, !tbaa !18
  %56 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.5, ptr noundef nonnull %45, i32 noundef %47, i32 noundef %49, i32 noundef %51, i32 noundef %53, ptr noundef %55) #3
  br label %57

57:                                               ; preds = %44, %41
  %58 = load ptr, ptr %.1, align 8, !tbaa !19
  %.not39 = icmp eq ptr %58, null
  br i1 %.not39, label %.loopexit, label %41, !llvm.loop !22

.thread:                                          ; preds = %14
  %59 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.9) #3
  %60 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.10) #3
  %61 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.11) #3
  %62 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.12) #3
  %63 = call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.13) #3
  br label %.loopexit

.loopexit:                                        ; preds = %57, %.thread, %14
  %.031 = phi i64 [ %15, %14 ], [ %15, %.thread ], [ %.029, %57 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i64 %.031
}

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

attributes #0 = { mustprogress 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, !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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass