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

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

@SeedString = external dso_local constant [47 x i8], align 16
@PreviousRandomBuffer = external dso_local global [256 x i8], align 16
@RandomBuffer = external dso_local global [256 x i8], align 16
@.str = external hidden unnamed_addr constant [37 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [23 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [8 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @ValidateCryptPrng() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %5 = call i64 (ptr, ...) @Print(ptr noundef @.str)
  %6 = call i64 (ptr, ...) @Print(ptr noundef @.str.1)
  %7 = call zeroext i8 @RandomSeed(ptr noundef @SeedString, i64 noundef 47)
  store i8 %7, ptr %3, align 1, !tbaa !5
  %8 = load i8, ptr %3, align 1, !tbaa !5
  %9 = icmp ne i8 %8, 0
  br i1 %9, label %12, label %10

10:                                               ; preds = %0
  %11 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  store i64 -9223372036854775787, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %34

12:                                               ; preds = %0
  store i64 0, ptr %2, align 8, !tbaa !8
  br label %13

13:                                               ; preds = %29, %12
  %14 = load i64, ptr %2, align 8, !tbaa !8
  %15 = icmp ult i64 %14, 10
  br i1 %15, label %16, label %32

16:                                               ; preds = %13
  %17 = call zeroext i8 @RandomBytes(ptr noundef @RandomBuffer, i64 noundef 256)
  store i8 %17, ptr %3, align 1, !tbaa !5
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %22, label %20

20:                                               ; preds = %16
  %21 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  store i64 -9223372036854775787, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %34

22:                                               ; preds = %16
  %23 = call i64 @CompareMem(ptr noundef @PreviousRandomBuffer, ptr noundef @RandomBuffer, i64 noundef 256)
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = call i64 (ptr, ...) @Print(ptr noundef @.str.2)
  store i64 -9223372036854775787, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %34

27:                                               ; preds = %22
  %28 = call ptr @CopyMem(ptr noundef @PreviousRandomBuffer, ptr noundef @RandomBuffer, i64 noundef 256)
  br label %29

29:                                               ; preds = %27
  %30 = load i64, ptr %2, align 8, !tbaa !8
  %31 = add i64 %30, 1
  store i64 %31, ptr %2, align 8, !tbaa !8
  br label %13, !llvm.loop !10

32:                                               ; preds = %13
  %33 = call i64 (ptr, ...) @Print(ptr noundef @.str.3)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %34

34:                                               ; preds = %32, %25, %20, %10
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %35 = load i64, ptr %1, align 8
  ret i64 %35
}

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

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

declare zeroext i8 @RandomSeed(ptr noundef, i64 noundef) #2

declare zeroext i8 @RandomBytes(ptr noundef, i64 noundef) #2

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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

@SeedString = external dso_local constant [47 x i8], align 16
@PreviousRandomBuffer = external dso_local global [256 x i8], align 16
@RandomBuffer = external dso_local global [256 x i8], align 16
@.str = external hidden unnamed_addr constant [37 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [23 x i32], align 4
@.str.2 = external hidden unnamed_addr constant [7 x i32], align 4
@.str.3 = external hidden unnamed_addr constant [8 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775787, 1) i64 @ValidateCryptPrng() local_unnamed_addr #0 {
  %1 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str) #2
  %2 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull @.str.1) #2
  %3 = tail call zeroext i8 @RandomSeed(ptr noundef nonnull @SeedString, i64 noundef 47) #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %55, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %4 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6 = icmp eq i8 %4, 0
  br i1 %.not6, label %55, label %5

5:                                                ; preds = %.preheader.preheader
  %6 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %55, label %.preheader.1

.preheader.1:                                     ; preds = %5
  %8 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %9 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.1 = icmp eq i8 %9, 0
  br i1 %.not6.1, label %55, label %10

10:                                               ; preds = %.preheader.1
  %11 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %55, label %.preheader.2

.preheader.2:                                     ; preds = %10
  %13 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %14 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.2 = icmp eq i8 %14, 0
  br i1 %.not6.2, label %55, label %15

15:                                               ; preds = %.preheader.2
  %16 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %55, label %.preheader.3

.preheader.3:                                     ; preds = %15
  %18 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %19 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.3 = icmp eq i8 %19, 0
  br i1 %.not6.3, label %55, label %20

20:                                               ; preds = %.preheader.3
  %21 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %55, label %.preheader.4

.preheader.4:                                     ; preds = %20
  %23 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %24 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.4 = icmp eq i8 %24, 0
  br i1 %.not6.4, label %55, label %25

25:                                               ; preds = %.preheader.4
  %26 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %55, label %.preheader.5

.preheader.5:                                     ; preds = %25
  %28 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %29 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.5 = icmp eq i8 %29, 0
  br i1 %.not6.5, label %55, label %30

30:                                               ; preds = %.preheader.5
  %31 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %55, label %.preheader.6

.preheader.6:                                     ; preds = %30
  %33 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %34 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.6 = icmp eq i8 %34, 0
  br i1 %.not6.6, label %55, label %35

35:                                               ; preds = %.preheader.6
  %36 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %55, label %.preheader.7

.preheader.7:                                     ; preds = %35
  %38 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %39 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.7 = icmp eq i8 %39, 0
  br i1 %.not6.7, label %55, label %40

40:                                               ; preds = %.preheader.7
  %41 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %42 = icmp eq i64 %41, 0
  br i1 %42, label %55, label %.preheader.8

.preheader.8:                                     ; preds = %40
  %43 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %44 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.8 = icmp eq i8 %44, 0
  br i1 %.not6.8, label %55, label %45

45:                                               ; preds = %.preheader.8
  %46 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %47 = icmp eq i64 %46, 0
  br i1 %47, label %55, label %.preheader.9

.preheader.9:                                     ; preds = %45
  %48 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %49 = tail call zeroext i8 @RandomBytes(ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %.not6.9 = icmp eq i8 %49, 0
  br i1 %.not6.9, label %55, label %50

50:                                               ; preds = %.preheader.9
  %51 = tail call i64 @CompareMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %55, label %53

53:                                               ; preds = %50
  %54 = tail call ptr @CopyMem(ptr noundef nonnull @PreviousRandomBuffer, ptr noundef nonnull @RandomBuffer, i64 noundef 256) #2
  br label %55

55:                                               ; preds = %5, %10, %15, %20, %25, %30, %35, %40, %45, %50, %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %.preheader.9, %0, %53
  %.str.3.sink = phi ptr [ @.str.3, %53 ], [ @.str.2, %0 ], [ @.str.2, %.preheader.9 ], [ @.str.2, %.preheader.8 ], [ @.str.2, %.preheader.7 ], [ @.str.2, %.preheader.6 ], [ @.str.2, %.preheader.5 ], [ @.str.2, %.preheader.4 ], [ @.str.2, %.preheader.3 ], [ @.str.2, %.preheader.2 ], [ @.str.2, %.preheader.1 ], [ @.str.2, %.preheader.preheader ], [ @.str.2, %50 ], [ @.str.2, %45 ], [ @.str.2, %40 ], [ @.str.2, %35 ], [ @.str.2, %30 ], [ @.str.2, %25 ], [ @.str.2, %20 ], [ @.str.2, %15 ], [ @.str.2, %10 ], [ @.str.2, %5 ]
  %.05 = phi i64 [ 0, %53 ], [ -9223372036854775787, %0 ], [ -9223372036854775787, %.preheader.9 ], [ -9223372036854775787, %.preheader.8 ], [ -9223372036854775787, %.preheader.7 ], [ -9223372036854775787, %.preheader.6 ], [ -9223372036854775787, %.preheader.5 ], [ -9223372036854775787, %.preheader.4 ], [ -9223372036854775787, %.preheader.3 ], [ -9223372036854775787, %.preheader.2 ], [ -9223372036854775787, %.preheader.1 ], [ -9223372036854775787, %.preheader.preheader ], [ -9223372036854775787, %50 ], [ -9223372036854775787, %45 ], [ -9223372036854775787, %40 ], [ -9223372036854775787, %35 ], [ -9223372036854775787, %30 ], [ -9223372036854775787, %25 ], [ -9223372036854775787, %20 ], [ -9223372036854775787, %15 ], [ -9223372036854775787, %10 ], [ -9223372036854775787, %5 ]
  %56 = tail call i64 (ptr, ...) @Print(ptr noundef nonnull %.str.3.sink) #2
  ret i64 %.05
}

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

declare zeroext i8 @RandomSeed(ptr noundef, i64 noundef) local_unnamed_addr #1

declare zeroext i8 @RandomBytes(ptr noundef, i64 noundef) local_unnamed_addr #1

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { "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 = { 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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass