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

; 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 = external hidden unnamed_addr constant [162 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1

; 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

declare zeroext i8 @DebugAssertEnabled() #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiDecompressGetInfo(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br label %12

12:                                               ; preds = %4
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str, i64 noundef 688, ptr noundef @.str.3)
  br label %19

19:                                               ; preds = %18, %15
  br label %20

20:                                               ; preds = %19, %12
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = call zeroext i8 @DebugAssertEnabled()
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  call void @DebugAssert(ptr noundef @.str, i64 noundef 689, ptr noundef @.str.4)
  br label %30

30:                                               ; preds = %29, %26
  br label %31

31:                                               ; preds = %30, %23
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = call zeroext i8 @DebugAssertEnabled()
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %37, label %42

37:                                               ; preds = %34
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  call void @DebugAssert(ptr noundef @.str, i64 noundef 690, ptr noundef @.str.5)
  br label %41

41:                                               ; preds = %40, %37
  br label %42

42:                                               ; preds = %41, %34
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = icmp ult i32 %45, 8
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %62

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i32 @ReadUnaligned32(ptr noundef %49)
  store i32 %50, ptr %10, align 4, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = add i32 %52, 8
  %54 = icmp ult i32 %51, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %62

56:                                               ; preds = %48
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 13376, ptr %57, align 4, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds i32, ptr %58, i64 1
  %60 = call i32 @ReadUnaligned32(ptr noundef %59)
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %60, ptr %61, align 4, !tbaa !9
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %62

62:                                               ; preds = %56, %55, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %63 = load i64, ptr %5, align 8
  ret i64 %63
}

declare i32 @ReadUnaligned32(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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}


; 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 = external hidden unnamed_addr constant [162 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [28 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @UefiDecompressGetInfo(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %6 = icmp eq i8 %5, 0
  %7 = icmp ne ptr %0, null
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 688, ptr noundef nonnull @.str.3) #2
  br label %9

9:                                                ; preds = %4, %8
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %11 = icmp eq i8 %10, 0
  %12 = icmp ne ptr %2, null
  %or.cond3 = or i1 %12, %11
  br i1 %or.cond3, label %14, label %13

13:                                               ; preds = %9
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 689, ptr noundef nonnull @.str.4) #2
  br label %14

14:                                               ; preds = %9, %13
  %15 = tail call zeroext i8 @DebugAssertEnabled() #2
  %16 = icmp eq i8 %15, 0
  %17 = icmp ne ptr %3, null
  %or.cond5 = or i1 %17, %16
  br i1 %or.cond5, label %19, label %18

18:                                               ; preds = %14
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 690, ptr noundef nonnull @.str.5) #2
  br label %19

19:                                               ; preds = %18, %14
  %20 = icmp ult i32 %1, 8
  br i1 %20, label %28, label %21

21:                                               ; preds = %19
  %22 = tail call i32 @ReadUnaligned32(ptr noundef %0) #2
  %23 = add i32 %22, 8
  %24 = icmp ugt i32 %23, %1
  br i1 %24, label %28, label %25

25:                                               ; preds = %21
  store i32 13376, ptr %3, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 4
  %27 = tail call i32 @ReadUnaligned32(ptr noundef nonnull %26) #2
  store i32 %27, ptr %2, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %21, %19, %25
  %.0 = phi i64 [ 0, %25 ], [ -9223372036854775806, %19 ], [ -9223372036854775806, %21 ]
  ret i64 %.0
}

declare i32 @ReadUnaligned32(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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"}


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