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

; 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.SCRATCH_DATA = type { ptr, ptr, i32, i32, i16, i32, i32, i16, i32, i32, i16, [1019 x i16], [1019 x i16], [510 x i8], [31 x i8], [4096 x i16], [256 x i16], i8 }

@.str = external hidden unnamed_addr constant [162 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @FillBuf(ptr noundef, i16 noundef zeroext) #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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @UefiDecompress(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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  br label %14

14:                                               ; preds = %3
  %15 = call zeroext i8 @DebugAssertEnabled()
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @DebugAssert(ptr noundef @.str, i64 noundef 750, ptr noundef @.str.3)
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %21, %14
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = call zeroext i8 @DebugAssertEnabled()
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %25
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @DebugAssert(ptr noundef @.str, i64 noundef 751, ptr noundef @.str.6)
  br label %32

32:                                               ; preds = %31, %28
  br label %33

33:                                               ; preds = %32, %25
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = call zeroext i8 @DebugAssertEnabled()
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %36
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  call void @DebugAssert(ptr noundef @.str, i64 noundef 752, ptr noundef @.str.7)
  br label %43

43:                                               ; preds = %42, %39
  br label %44

44:                                               ; preds = %43, %36
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %47, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %48, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %49, ptr %10, align 8, !tbaa !5
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 0
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = zext i8 %52 to i32
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = zext i8 %56 to i32
  %58 = shl i32 %57, 8
  %59 = add nsw i32 %53, %58
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 2
  %62 = load i8, ptr %61, align 1, !tbaa !9
  %63 = zext i8 %62 to i32
  %64 = shl i32 %63, 16
  %65 = add nsw i32 %59, %64
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 3
  %68 = load i8, ptr %67, align 1, !tbaa !9
  %69 = zext i8 %68 to i32
  %70 = shl i32 %69, 24
  %71 = add nsw i32 %65, %70
  store i32 %71, ptr %8, align 4, !tbaa !10
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 4
  %74 = load i8, ptr %73, align 1, !tbaa !9
  %75 = zext i8 %74 to i32
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 5
  %78 = load i8, ptr %77, align 1, !tbaa !9
  %79 = zext i8 %78 to i32
  %80 = shl i32 %79, 8
  %81 = add nsw i32 %75, %80
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 6
  %84 = load i8, ptr %83, align 1, !tbaa !9
  %85 = zext i8 %84 to i32
  %86 = shl i32 %85, 16
  %87 = add nsw i32 %81, %86
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = getelementptr inbounds i8, ptr %88, i64 7
  %90 = load i8, ptr %89, align 1, !tbaa !9
  %91 = zext i8 %90 to i32
  %92 = shl i32 %91, 24
  %93 = add nsw i32 %87, %92
  store i32 %93, ptr %9, align 4, !tbaa !10
  %94 = load i32, ptr %9, align 4, !tbaa !10
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %46
  store i64 0, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %125

97:                                               ; preds = %46
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i64 8
  store ptr %99, ptr %11, align 8, !tbaa !5
  %100 = load ptr, ptr %10, align 8, !tbaa !5
  %101 = call ptr @SetMem(ptr noundef %100, i64 noundef 13376, i8 noundef zeroext 0)
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %102, i32 0, i32 17
  store i8 4, ptr %103, align 4, !tbaa !12
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %105, i32 0, i32 0
  store ptr %104, ptr %106, align 8, !tbaa !15
  %107 = load ptr, ptr %12, align 8, !tbaa !5
  %108 = load ptr, ptr %10, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %108, i32 0, i32 1
  store ptr %107, ptr %109, align 8, !tbaa !16
  %110 = load i32, ptr %8, align 4, !tbaa !10
  %111 = load ptr, ptr %10, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %111, i32 0, i32 8
  store i32 %110, ptr %112, align 8, !tbaa !17
  %113 = load i32, ptr %9, align 4, !tbaa !10
  %114 = load ptr, ptr %10, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %114, i32 0, i32 9
  store i32 %113, ptr %115, align 4, !tbaa !18
  %116 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FillBuf(ptr noundef %116, i16 noundef zeroext 32)
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  call void @Decode(ptr noundef %117)
  %118 = load ptr, ptr %10, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %118, i32 0, i32 10
  %120 = load i16, ptr %119, align 8, !tbaa !19
  %121 = zext i16 %120 to i32
  %122 = icmp ne i32 %121, 0
  br i1 %122, label %123, label %124

123:                                              ; preds = %97
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %125

124:                                              ; preds = %97
  store i64 0, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %125

125:                                              ; preds = %124, %123, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %126 = load i64, ptr %4, align 8
  ret i64 %126
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 13372}
!13 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !14, i64 24, !11, i64 28, !11, i64 32, !14, i64 36, !11, i64 40, !11, i64 44, !14, i64 48, !7, i64 50, !7, i64 2088, !7, i64 4126, !7, i64 4636, !7, i64 4668, !7, i64 12860, !7, i64 13372}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 0}
!16 = !{!13, !6, i64 8}
!17 = !{!13, !11, i64 40}
!18 = !{!13, !11, i64 44}
!19 = !{!13, !14, i64 48}


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

; Function Attrs: nounwind uwtable
declare dso_local void @FillBuf(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

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

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

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

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

12:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 751, ptr noundef nonnull @.str.6) #2
  br label %13

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

17:                                               ; preds = %13
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 752, ptr noundef nonnull @.str.7) #2
  br label %18

18:                                               ; preds = %17, %13
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i16, ptr %19, align 1
  %21 = zext i16 %20 to i32
  %22 = getelementptr inbounds i8, ptr %0, i64 6
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = shl nuw nsw i32 %24, 16
  %26 = or disjoint i32 %25, %21
  %27 = getelementptr inbounds i8, ptr %0, i64 7
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = zext i8 %28 to i32
  %30 = shl nuw i32 %29, 24
  %31 = or disjoint i32 %26, %30
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %43, label %33

33:                                               ; preds = %18
  %34 = load i32, ptr %0, align 1
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  %36 = tail call ptr @SetMem(ptr noundef %2, i64 noundef 13376, i8 noundef zeroext 0) #2
  %37 = getelementptr inbounds i8, ptr %2, i64 13372
  store i8 4, ptr %37, align 4, !tbaa !8
  store ptr %35, ptr %2, align 8, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %1, ptr %38, align 8, !tbaa !14
  %39 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 %34, ptr %39, align 8, !tbaa !15
  %40 = getelementptr inbounds i8, ptr %2, i64 44
  store i32 %31, ptr %40, align 4, !tbaa !16
  tail call void @FillBuf(ptr noundef nonnull %2, i16 noundef zeroext 32)
  tail call void @Decode(ptr noundef nonnull %2)
  %41 = getelementptr inbounds i8, ptr %2, i64 48
  %42 = load i16, ptr %41, align 8, !tbaa !17
  %.not = icmp eq i16 %42, 0
  %. = select i1 %.not, i64 0, i64 -9223372036854775806
  br label %43

43:                                               ; preds = %33, %18
  %.0 = phi i64 [ 0, %18 ], [ %., %33 ]
  ret i64 %.0
}

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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 13372}
!9 = !{!"", !10, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !11, i64 28, !11, i64 32, !12, i64 36, !11, i64 40, !11, i64 44, !12, i64 48, !6, i64 50, !6, i64 2088, !6, i64 4126, !6, i64 4636, !6, i64 4668, !6, i64 12860, !6, i64 13372}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!9, !10, i64 0}
!14 = !{!9, !10, i64 8}
!15 = !{!9, !11, i64 40}
!16 = !{!9, !11, i64 44}
!17 = !{!9, !12, i64 48}


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