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

; 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.EFI_RUNTIME_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@gRT = external global ptr, align 8
@gShellVariableGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [142 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @IsVolatileEnv(ptr noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = 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 4, ptr %7) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  store ptr null, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr @gRT, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %9, i32 0, i32 7
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call i64 %11(ptr noundef %12, ptr noundef @gShellVariableGuid, ptr noundef %7, ptr noundef %5, ptr noundef %13)
  store i64 %14, ptr %4, align 8, !tbaa !9
  %15 = load i64, ptr %4, align 8, !tbaa !9
  %16 = icmp eq i64 %15, -9223372036854775803
  br i1 %16, label %17, label %38

17:                                               ; preds = %1
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = call ptr @AllocateZeroPool(i64 noundef %18)
  store ptr %19, ptr %6, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %17
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @DebugAssert(ptr noundef @.str, i64 noundef 52, ptr noundef @.str.1)
  br label %27

27:                                               ; preds = %26, %23
  br label %28

28:                                               ; preds = %27, %20
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @gRT, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %31, i32 0, i32 7
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call i64 %33(ptr noundef %34, ptr noundef @gShellVariableGuid, ptr noundef %7, ptr noundef %5, ptr noundef %35)
  store i64 %36, ptr %4, align 8, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %37)
  br label %38

38:                                               ; preds = %30, %1
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = icmp eq i64 %39, -9223372036854775794
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i8 1, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %74

42:                                               ; preds = %38
  br label %43

43:                                               ; preds = %42
  %44 = call zeroext i8 @DebugAssertEnabled()
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %46, label %66

46:                                               ; preds = %43
  %47 = load i64, ptr %4, align 8, !tbaa !9
  %48 = icmp slt i64 %47, 0
  br i1 %48, label %49, label %65

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  %51 = call zeroext i8 @DebugPrintEnabled()
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %53, label %62

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  %55 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %56 = icmp ne i8 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load i64, ptr %4, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.2, i64 noundef %58)
  br label %59

59:                                               ; preds = %57, %54
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61, %50
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  call void @DebugAssert(ptr noundef @.str, i64 noundef 66, ptr noundef @.str.3)
  br label %65

65:                                               ; preds = %64, %46
  br label %66

66:                                               ; preds = %65, %43
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %7, align 4, !tbaa !15
  %70 = and i32 %69, 1
  %71 = icmp eq i32 %70, 1
  br i1 %71, label %72, label %73

72:                                               ; preds = %68
  store i8 0, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %74

73:                                               ; preds = %68
  store i8 1, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %74

74:                                               ; preds = %73, %72, %41
  call void @llvm.lifetime.end.p0(i64 4, 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
  %75 = load i8, ptr %2, align 1
  ret i8 %75
}

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

declare ptr @AllocateZeroPool(i64 noundef) #2

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare void @FreePool(ptr noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, 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, !6, i64 72}
!12 = !{!"", !13, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!13 = !{!"", !10, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}


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

@gRT = external local_unnamed_addr global ptr, align 8
@gShellVariableGuid = external global %struct.GUID, align 4
@.str = external hidden unnamed_addr constant [142 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @IsVolatileEnv(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr @gRT, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %4, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = call i64 %6(ptr noundef %0, ptr noundef nonnull @gShellVariableGuid, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef null) #3
  %8 = icmp eq i64 %7, -9223372036854775803
  br i1 %8, label %9, label %21

9:                                                ; preds = %1
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = call ptr @AllocateZeroPool(i64 noundef %10) #3
  %12 = call zeroext i8 @DebugAssertEnabled() #3
  %13 = icmp eq i8 %12, 0
  %14 = icmp ne ptr %11, null
  %or.cond = select i1 %13, i1 true, i1 %14
  br i1 %or.cond, label %16, label %15

15:                                               ; preds = %9
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 52, ptr noundef nonnull @.str.1) #3
  br label %16

16:                                               ; preds = %15, %9
  %17 = load ptr, ptr @gRT, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 72
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = call i64 %19(ptr noundef %0, ptr noundef nonnull @gShellVariableGuid, ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef %11) #3
  call void @FreePool(ptr noundef %11) #3
  br label %21

21:                                               ; preds = %16, %1
  %.0 = phi i64 [ %20, %16 ], [ %7, %1 ]
  %22 = icmp eq i64 %.0, -9223372036854775794
  br i1 %22, label %37, label %23

23:                                               ; preds = %21
  %24 = call zeroext i8 @DebugAssertEnabled() #3
  %25 = icmp ne i8 %24, 0
  %26 = icmp slt i64 %.0, 0
  %or.cond3 = and i1 %26, %25
  br i1 %or.cond3, label %27, label %33

27:                                               ; preds = %23
  %28 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %28, 0
  br i1 %.not, label %32, label %29

29:                                               ; preds = %27
  %30 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not15 = icmp eq i8 %30, 0
  br i1 %.not15, label %32, label %31

31:                                               ; preds = %29
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.2, i64 noundef %.0) #3
  br label %32

32:                                               ; preds = %29, %31, %27
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 66, ptr noundef nonnull @.str.3) #3
  br label %33

33:                                               ; preds = %32, %23
  %34 = load i32, ptr %3, align 4, !tbaa !15
  %35 = trunc i32 %34 to i8
  %36 = and i8 %35, 1
  %. = xor i8 %36, 1
  br label %37

37:                                               ; preds = %33, %21
  %.013 = phi i8 [ 1, %21 ], [ %., %33 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i8 %.013
}

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #2

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #2

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

declare void @DebugPrint(i64 noundef, 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 72}
!12 = !{!"", !13, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}


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