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

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

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @DecodeP(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @DecodeC(ptr noundef) #1

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

6:                                                ; preds = %90, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call zeroext i16 @DecodeC(ptr noundef %7)
  store i16 %8, ptr %5, align 2, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %9, i32 0, i32 10
  %11 = load i16, ptr %10, align 8, !tbaa !13
  %12 = zext i16 %11 to i32
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %6
  br label %91

15:                                               ; preds = %6
  %16 = load i16, ptr %5, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = icmp slt i32 %17, 256
  br i1 %18, label %19, label %41

19:                                               ; preds = %15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %23, i32 0, i32 9
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = icmp uge i32 %22, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %19
  br label %91

28:                                               ; preds = %19
  %29 = load i16, ptr %5, align 2, !tbaa !9
  %30 = trunc i16 %29 to i8
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !15
  %37 = add i32 %36, 1
  store i32 %37, ptr %35, align 8, !tbaa !15
  %38 = zext i32 %36 to i64
  %39 = getelementptr inbounds i8, ptr %33, i64 %38
  store i8 %30, ptr %39, align 1, !tbaa !18
  br label %40

40:                                               ; preds = %28
  br label %90

41:                                               ; preds = %15
  %42 = load i16, ptr %5, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = sub nsw i32 %43, 253
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %5, align 2, !tbaa !9
  %46 = load i16, ptr %5, align 2, !tbaa !9
  store i16 %46, ptr %3, align 2, !tbaa !9
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = call i32 @DecodeP(ptr noundef %50)
  %52 = sub i32 %49, %51
  %53 = sub i32 %52, 1
  store i32 %53, ptr %4, align 4, !tbaa !11
  %54 = load i16, ptr %3, align 2, !tbaa !9
  %55 = add i16 %54, -1
  store i16 %55, ptr %3, align 2, !tbaa !9
  br label %56

56:                                               ; preds = %86, %41
  %57 = load i16, ptr %3, align 2, !tbaa !9
  %58 = sext i16 %57 to i32
  %59 = icmp sge i32 %58, 0
  br i1 %59, label %60, label %89

60:                                               ; preds = %56
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load i32, ptr %4, align 4, !tbaa !11
  %65 = add i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !11
  %66 = zext i32 %64 to i64
  %67 = getelementptr inbounds i8, ptr %63, i64 %66
  %68 = load i8, ptr %67, align 1, !tbaa !18
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 8, !tbaa !15
  %75 = add i32 %74, 1
  store i32 %75, ptr %73, align 8, !tbaa !15
  %76 = zext i32 %74 to i64
  %77 = getelementptr inbounds i8, ptr %71, i64 %76
  store i8 %68, ptr %77, align 1, !tbaa !18
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %79, align 8, !tbaa !15
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %81, i32 0, i32 9
  %83 = load i32, ptr %82, align 4, !tbaa !16
  %84 = icmp uge i32 %80, %83
  br i1 %84, label %85, label %86

85:                                               ; preds = %60
  br label %91

86:                                               ; preds = %60
  %87 = load i16, ptr %3, align 2, !tbaa !9
  %88 = add i16 %87, -1
  store i16 %88, ptr %3, align 2, !tbaa !9
  br label %56, !llvm.loop !19

89:                                               ; preds = %56
  br label %90

90:                                               ; preds = %89, %40
  br label %6

91:                                               ; preds = %85, %27, %14
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 48}
!14 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !10, i64 24, !12, i64 28, !12, i64 32, !10, i64 36, !12, i64 40, !12, i64 44, !10, i64 48, !7, i64 50, !7, i64 2088, !7, i64 4126, !7, i64 4636, !7, i64 4668, !7, i64 12860, !7, i64 13372}
!15 = !{!14, !12, i64 16}
!16 = !{!14, !12, i64 44}
!17 = !{!14, !6, i64 8}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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 i32 @DecodeP(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @Decode(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i16 @DecodeC(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %.not29 = icmp eq i16 %4, 0
  br i1 %.not29, label %.lr.ph30, label %.loopexit25

.lr.ph30:                                         ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 44
  br label %8

8:                                                ; preds = %.lr.ph30, %.loopexit
  %9 = phi i16 [ %2, %.lr.ph30 ], [ %40, %.loopexit ]
  %10 = icmp ult i16 %9, 256
  %11 = load i32, ptr %5, align 8, !tbaa !12
  br i1 %10, label %12, label %20

12:                                               ; preds = %8
  %13 = load i32, ptr %7, align 4, !tbaa !13
  %.not24 = icmp ult i32 %11, %13
  br i1 %.not24, label %14, label %.loopexit25

14:                                               ; preds = %12
  %15 = trunc nuw i16 %9 to i8
  %16 = load ptr, ptr %6, align 8, !tbaa !14
  %17 = add nuw i32 %11, 1
  store i32 %17, ptr %5, align 8, !tbaa !12
  %18 = zext i32 %11 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  store i8 %15, ptr %19, align 1, !tbaa !15
  br label %.loopexit

20:                                               ; preds = %8
  %21 = tail call i32 @DecodeP(ptr noundef nonnull %0)
  %22 = add i16 %9, -254
  %23 = icmp sgt i16 %22, -1
  br i1 %23, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %20
  %24 = xor i32 %21, -1
  %25 = add i32 %11, %24
  %.pre = load i32, ptr %5, align 8, !tbaa !12
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %36
  %26 = phi i32 [ %34, %36 ], [ %.pre, %.lr.ph.preheader ]
  %.028 = phi i32 [ %37, %36 ], [ %25, %.lr.ph.preheader ]
  %.02027 = phi i16 [ %38, %36 ], [ %22, %.lr.ph.preheader ]
  %27 = load ptr, ptr %6, align 8, !tbaa !14
  %28 = zext i32 %.028 to i64
  %29 = getelementptr inbounds i8, ptr %27, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = add i32 %26, 1
  store i32 %31, ptr %5, align 8, !tbaa !12
  %32 = zext i32 %26 to i64
  %33 = getelementptr inbounds i8, ptr %27, i64 %32
  store i8 %30, ptr %33, align 1, !tbaa !15
  %34 = load i32, ptr %5, align 8, !tbaa !12
  %35 = load i32, ptr %7, align 4, !tbaa !13
  %.not23 = icmp ult i32 %34, %35
  br i1 %.not23, label %36, label %.loopexit25

36:                                               ; preds = %.lr.ph
  %37 = add i32 %.028, 1
  %38 = add nsw i16 %.02027, -1
  %39 = icmp sgt i16 %.02027, 0
  br i1 %39, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %36, %20, %14
  %40 = tail call zeroext i16 @DecodeC(ptr noundef nonnull %0)
  %41 = load i16, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i16 %41, 0
  br i1 %.not, label %8, label %.loopexit25

.loopexit25:                                      ; preds = %.loopexit, %12, %.lr.ph, %1
  ret void
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass