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

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

; Function Attrs: nounwind uwtable
declare dso_local void @QemuFwCfgSelectItem(i32 noundef) #0

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

declare zeroext i8 @InternalQemuFwCfgIsAvailable() #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @QemuFwCfgRead16() #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @QemuFwCfgRead32() #0

; Function Attrs: nounwind uwtable
define dso_local i64 @QemuFwCfgFindFile(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i16, align 2
  %13 = alloca i16, align 2
  %14 = alloca [56 x i8], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %15 = call zeroext i8 @InternalQemuFwCfgIsAvailable()
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  store i64 -9223372036854775805, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %51

18:                                               ; preds = %3
  call void @QemuFwCfgSelectItem(i32 noundef 25)
  %19 = call i32 @QemuFwCfgRead32()
  %20 = call i32 @SwapBytes32(i32 noundef %19)
  store i32 %20, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %47, %18
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = icmp ult i32 %22, %23
  br i1 %24, label %25, label %50

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 56, ptr %14) #3
  %26 = call i32 @QemuFwCfgRead32()
  store i32 %26, ptr %11, align 4, !tbaa !9
  %27 = call zeroext i16 @QemuFwCfgRead16()
  store i16 %27, ptr %12, align 2, !tbaa !11
  %28 = call zeroext i16 @QemuFwCfgRead16()
  store i16 %28, ptr %13, align 2, !tbaa !11
  %29 = getelementptr inbounds [56 x i8], ptr %14, i64 0, i64 0
  call void @InternalQemuFwCfgReadBytes(i64 noundef 56, ptr noundef %29)
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds [56 x i8], ptr %14, i64 0, i64 0
  %32 = call i64 @AsciiStrCmp(ptr noundef %30, ptr noundef %31)
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %43

34:                                               ; preds = %25
  %35 = load i16, ptr %12, align 2, !tbaa !11
  %36 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %35)
  %37 = zext i16 %36 to i32
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %37, ptr %38, align 4, !tbaa !9
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = call i32 @SwapBytes32(i32 noundef %39)
  %41 = zext i32 %40 to i64
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %41, ptr %42, align 8, !tbaa !13
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %44

43:                                               ; preds = %25
  store i32 0, ptr %10, align 4
  br label %44

44:                                               ; preds = %43, %34
  call void @llvm.lifetime.end.p0(i64 56, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %45 = load i32, ptr %10, align 4
  switch i32 %45, label %51 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %21, !llvm.loop !15

50:                                               ; preds = %21
  store i64 -9223372036854775794, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %51

51:                                               ; preds = %50, %44, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %52 = load i64, ptr %4, align 8
  ret i64 %52
}

declare i32 @SwapBytes32(i32 noundef) #1

declare i64 @AsciiStrCmp(ptr noundef, ptr noundef) #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local void @QemuFwCfgSelectItem(i32 noundef) local_unnamed_addr #0

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

declare zeroext i8 @InternalQemuFwCfgIsAvailable() local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @QemuFwCfgRead16() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @QemuFwCfgRead32() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @QemuFwCfgFindFile(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca [56 x i8], align 16
  %5 = tail call zeroext i8 @InternalQemuFwCfgIsAvailable() #3
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %3
  tail call void @QemuFwCfgSelectItem(i32 noundef 25)
  %7 = tail call i32 @QemuFwCfgRead32()
  %8 = tail call i32 @SwapBytes32(i32 noundef %7) #3
  %.not14 = icmp eq i32 %8, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.critedge
  %.0913 = phi i32 [ %18, %.critedge ], [ 0, %6 ]
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %4) #3
  %9 = call i32 @QemuFwCfgRead32()
  %10 = call zeroext i16 @QemuFwCfgRead16()
  %11 = call zeroext i16 @QemuFwCfgRead16()
  call void @InternalQemuFwCfgReadBytes(i64 noundef 56, ptr noundef nonnull %4)
  %12 = call i64 @AsciiStrCmp(ptr noundef %0, ptr noundef nonnull %4) #3
  %.not11 = icmp eq i64 %12, 0
  br i1 %.not11, label %13, label %.critedge

13:                                               ; preds = %.lr.ph
  %14 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %10) #3
  %15 = zext i16 %14 to i32
  store i32 %15, ptr %1, align 4, !tbaa !5
  %16 = call i32 @SwapBytes32(i32 noundef %9) #3
  %17 = zext i32 %16 to i64
  store i64 %17, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #3
  br label %.loopexit

.critedge:                                        ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %4) #3
  %18 = add nuw i32 %.0913, 1
  %exitcond.not = icmp eq i32 %18, %8
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit:                                        ; preds = %.critedge, %6, %13, %3
  %.2 = phi i64 [ 0, %13 ], [ -9223372036854775805, %3 ], [ -9223372036854775794, %6 ], [ -9223372036854775794, %.critedge ]
  ret i64 %.2
}

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass