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

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

@.str.7 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @GetNvVarsFile(ptr noundef, i8 noundef zeroext, ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileHandleEmpty(ptr noundef) #0

declare ptr @AllocatePool(i64 noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

declare i64 @FileHandleClose(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @SetNvVarsVariable() #0

; Function Attrs: nounwind uwtable
define dso_local i64 @SaveNvVarsToFs(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = 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 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  %11 = call i64 @SerializeVariablesNewInstance(ptr noundef %9)
  store i64 %11, ptr %4, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %1
  %15 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %15, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

16:                                               ; preds = %1
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = call i64 @SerializeVariablesIterateSystemVariables(ptr noundef @IterateVariablesCallbackAddAllNvVariables, ptr noundef %17)
  store i64 %18, ptr %4, align 8, !tbaa !9
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %22, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

23:                                               ; preds = %16
  store ptr null, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !9
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = call i64 @SerializeVariablesToBuffer(ptr noundef %24, ptr noundef null, ptr noundef %7)
  store i64 %25, ptr %4, align 8, !tbaa !9
  %26 = load i64, ptr %4, align 8, !tbaa !9
  %27 = icmp eq i64 %26, -9223372036854775803
  br i1 %27, label %28, label %39

28:                                               ; preds = %23
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = call ptr @AllocatePool(i64 noundef %29)
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i64 -9223372036854775799, ptr %4, align 8, !tbaa !9
  br label %38

34:                                               ; preds = %28
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i64 @SerializeVariablesToBuffer(ptr noundef %35, ptr noundef %36, ptr noundef %7)
  store i64 %37, ptr %4, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %34, %33
  br label %39

39:                                               ; preds = %38, %23
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = call i64 @SerializeVariablesFreeInstance(ptr noundef %40)
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = icmp slt i64 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %39
  %45 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %45, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

46:                                               ; preds = %39
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = call i64 @GetNvVarsFile(ptr noundef %47, i8 noundef zeroext 0, ptr noundef %5)
  store i64 %48, ptr %4, align 8, !tbaa !9
  %49 = load i64, ptr %4, align 8, !tbaa !9
  %50 = icmp slt i64 %49, 0
  br i1 %50, label %51, label %67

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51
  %53 = call zeroext i8 @DebugPrintEnabled()
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %63

55:                                               ; preds = %52
  br label %56

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

59:                                               ; preds = %56
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.7)
  br label %60

60:                                               ; preds = %59, %56
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %52
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %66, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

67:                                               ; preds = %46
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = call i64 @FileHandleEmpty(ptr noundef %68)
  store i64 %69, ptr %4, align 8, !tbaa !9
  %70 = load i64, ptr %4, align 8, !tbaa !9
  %71 = icmp slt i64 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %67
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = call i64 @FileHandleClose(ptr noundef %73)
  %75 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %75, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

76:                                               ; preds = %67
  %77 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %77, ptr %6, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = call i64 @FileHandleWrite(ptr noundef %78, ptr noundef %6, ptr noundef %79)
  store i64 %80, ptr %4, align 8, !tbaa !9
  %81 = load i64, ptr %4, align 8, !tbaa !9
  %82 = icmp slt i64 %81, 0
  br i1 %82, label %83, label %85

83:                                               ; preds = %76
  %84 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %84, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

85:                                               ; preds = %76
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i64 @FileHandleClose(ptr noundef %86)
  %88 = load i64, ptr %4, align 8, !tbaa !9
  %89 = icmp slt i64 %88, 0
  br i1 %89, label %105, label %90

90:                                               ; preds = %85
  call void @SetNvVarsVariable()
  br label %91

91:                                               ; preds = %90
  %92 = call zeroext i8 @DebugPrintEnabled()
  %93 = icmp ne i8 %92, 0
  br i1 %93, label %94, label %102

94:                                               ; preds = %91
  br label %95

95:                                               ; preds = %94
  %96 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %97 = icmp ne i8 %96, 0
  br i1 %97, label %98, label %99

98:                                               ; preds = %95
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.8)
  br label %99

99:                                               ; preds = %98, %95
  br label %100

100:                                              ; preds = %99
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101, %91
  br label %103

103:                                              ; preds = %102
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104, %85
  %106 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %106, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %107

107:                                              ; preds = %105, %83, %72, %65, %44, %21, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %108 = load i64, ptr %2, align 8
  ret i64 %108
}

declare i64 @SerializeVariablesNewInstance(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @IterateVariablesCallbackAddAllNvVariables(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef) #0

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

declare i64 @SerializeVariablesFreeInstance(ptr noundef) #2

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

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}


; 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.7 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @GetNvVarsFile(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

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

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

declare ptr @AllocatePool(i64 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

declare i64 @FileHandleClose(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @SetNvVarsVariable() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @SaveNvVarsToFs(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = call i64 @SerializeVariablesNewInstance(ptr noundef nonnull %5) #3
  %7 = icmp slt i64 %6, 0
  br i1 %7, label %55, label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call i64 @SerializeVariablesIterateSystemVariables(ptr noundef nonnull @IterateVariablesCallbackAddAllNvVariables, ptr noundef %9) #3
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %55, label %12

12:                                               ; preds = %8
  store i64 0, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i64 @SerializeVariablesToBuffer(ptr noundef %13, ptr noundef null, ptr noundef nonnull %4) #3
  %15 = icmp eq i64 %14, -9223372036854775803
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = call ptr @AllocatePool(i64 noundef %17) #3
  %19 = icmp eq ptr %18, null
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  br i1 %19, label %.thread, label %22

.thread:                                          ; preds = %16
  %21 = call i64 @SerializeVariablesFreeInstance(ptr noundef %20) #3
  br label %55

22:                                               ; preds = %16
  %23 = call i64 @SerializeVariablesToBuffer(ptr noundef %20, ptr noundef nonnull %18, ptr noundef nonnull %4) #3
  br label %24

24:                                               ; preds = %22, %12
  %.019 = phi i64 [ %23, %22 ], [ %14, %12 ]
  %.0 = phi ptr [ %18, %22 ], [ null, %12 ]
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i64 @SerializeVariablesFreeInstance(ptr noundef %25) #3
  %27 = icmp slt i64 %.019, 0
  br i1 %27, label %55, label %28

28:                                               ; preds = %24
  %29 = call i64 @GetNvVarsFile(ptr noundef %0, i8 noundef zeroext 0, ptr noundef nonnull %2)
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = call zeroext i8 @DebugPrintEnabled() #3
  %.not30 = icmp eq i8 %32, 0
  br i1 %.not30, label %55, label %33

33:                                               ; preds = %31
  %34 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not31 = icmp eq i8 %34, 0
  br i1 %.not31, label %55, label %35

35:                                               ; preds = %33
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.7) #3
  br label %55

36:                                               ; preds = %28
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = call i64 @FileHandleEmpty(ptr noundef %37)
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %36
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = call i64 @FileHandleClose(ptr noundef %41) #3
  br label %55

43:                                               ; preds = %36
  %44 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %44, ptr %3, align 8, !tbaa !9
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call i64 @FileHandleWrite(ptr noundef %45, ptr noundef nonnull %3, ptr noundef %.0) #3
  %47 = icmp slt i64 %46, 0
  br i1 %47, label %55, label %48

48:                                               ; preds = %43
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = call i64 @FileHandleClose(ptr noundef %49) #3
  call void @SetNvVarsVariable()
  %51 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %51, 0
  br i1 %.not, label %55, label %52

52:                                               ; preds = %48
  %53 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not29 = icmp eq i8 %53, 0
  br i1 %.not29, label %55, label %54

54:                                               ; preds = %52
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.8) #3
  br label %55

55:                                               ; preds = %.thread, %52, %54, %48, %43, %31, %35, %33, %24, %8, %1, %40
  %.020 = phi i64 [ %38, %40 ], [ %6, %1 ], [ %10, %8 ], [ %.019, %24 ], [ %29, %33 ], [ %29, %35 ], [ %29, %31 ], [ %46, %43 ], [ %46, %48 ], [ %46, %54 ], [ %46, %52 ], [ -9223372036854775799, %.thread ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i64 %.020
}

declare i64 @SerializeVariablesNewInstance(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @IterateVariablesCallbackAddAllNvVariables(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef) #0

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

declare i64 @SerializeVariablesFreeInstance(ptr noundef) local_unnamed_addr #2

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

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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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