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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @GetBits(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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @DecodeC(ptr noundef %0) #0 {
  %2 = alloca i16, align 2
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %7, i32 0, i32 7
  %9 = load i16, ptr %8, align 4, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %45

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 @GetBits(ptr noundef %13, i16 noundef zeroext 16)
  %15 = trunc i32 %14 to i16
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %16, i32 0, i32 7
  store i16 %15, ptr %17, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call zeroext i16 @ReadPTLen(ptr noundef %18, i16 noundef zeroext 19, i16 noundef zeroext 5, i16 noundef zeroext 3)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %20, i32 0, i32 10
  store i16 %19, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %22, i32 0, i32 10
  %24 = load i16, ptr %23, align 8, !tbaa !13
  %25 = zext i16 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %12
  store i16 0, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %102

28:                                               ; preds = %12
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ReadCLen(ptr noundef %29)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %31, i32 0, i32 17
  %33 = load i8, ptr %32, align 4, !tbaa !14
  %34 = zext i8 %33 to i16
  %35 = call zeroext i16 @ReadPTLen(ptr noundef %30, i16 noundef zeroext 31, i16 noundef zeroext %34, i16 noundef zeroext -1)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %36, i32 0, i32 10
  store i16 %35, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %38, i32 0, i32 10
  %40 = load i16, ptr %39, align 8, !tbaa !13
  %41 = zext i16 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %28
  store i16 0, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %102

44:                                               ; preds = %28
  br label %45

45:                                               ; preds = %44, %1
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %46, i32 0, i32 7
  %48 = load i16, ptr %47, align 4, !tbaa !9
  %49 = add i16 %48, -1
  store i16 %49, ptr %47, align 4, !tbaa !9
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %50, i32 0, i32 15
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %52, i32 0, i32 5
  %54 = load i32, ptr %53, align 4, !tbaa !15
  %55 = lshr i32 %54, 20
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [4096 x i16], ptr %51, i64 0, i64 %56
  %58 = load i16, ptr %57, align 2, !tbaa !16
  store i16 %58, ptr %4, align 2, !tbaa !16
  %59 = load i16, ptr %4, align 2, !tbaa !16
  %60 = zext i16 %59 to i32
  %61 = icmp sge i32 %60, 510
  br i1 %61, label %62, label %92

62:                                               ; preds = %45
  store i32 524288, ptr %5, align 4, !tbaa !17
  br label %63

63:                                               ; preds = %87, %62
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %64, i32 0, i32 5
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = load i32, ptr %5, align 4, !tbaa !17
  %68 = and i32 %66, %67
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %77

70:                                               ; preds = %63
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %71, i32 0, i32 12
  %73 = load i16, ptr %4, align 2, !tbaa !16
  %74 = zext i16 %73 to i64
  %75 = getelementptr inbounds [1019 x i16], ptr %72, i64 0, i64 %74
  %76 = load i16, ptr %75, align 2, !tbaa !16
  store i16 %76, ptr %4, align 2, !tbaa !16
  br label %84

77:                                               ; preds = %63
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %78, i32 0, i32 11
  %80 = load i16, ptr %4, align 2, !tbaa !16
  %81 = zext i16 %80 to i64
  %82 = getelementptr inbounds [1019 x i16], ptr %79, i64 0, i64 %81
  %83 = load i16, ptr %82, align 2, !tbaa !16
  store i16 %83, ptr %4, align 2, !tbaa !16
  br label %84

84:                                               ; preds = %77, %70
  %85 = load i32, ptr %5, align 4, !tbaa !17
  %86 = lshr i32 %85, 1
  store i32 %86, ptr %5, align 4, !tbaa !17
  br label %87

87:                                               ; preds = %84
  %88 = load i16, ptr %4, align 2, !tbaa !16
  %89 = zext i16 %88 to i32
  %90 = icmp sge i32 %89, 510
  br i1 %90, label %63, label %91, !llvm.loop !18

91:                                               ; preds = %87
  br label %92

92:                                               ; preds = %91, %45
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.SCRATCH_DATA, ptr %94, i32 0, i32 13
  %96 = load i16, ptr %4, align 2, !tbaa !16
  %97 = zext i16 %96 to i64
  %98 = getelementptr inbounds [510 x i8], ptr %95, i64 0, i64 %97
  %99 = load i8, ptr %98, align 1, !tbaa !20
  %100 = zext i8 %99 to i16
  call void @FillBuf(ptr noundef %93, i16 noundef zeroext %100)
  %101 = load i16, ptr %4, align 2, !tbaa !16
  store i16 %101, ptr %2, align 2
  store i32 1, ptr %6, align 4
  br label %102

102:                                              ; preds = %92, %43, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  %103 = load i16, ptr %2, align 2
  ret i16 %103
}

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @DecodeC(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i16, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i16 %3, 0
  br i1 %4, label %5, label %15

5:                                                ; preds = %1
  %6 = tail call i32 @GetBits(ptr noundef nonnull %0, i16 noundef zeroext 16)
  %7 = trunc i32 %6 to i16
  store i16 %7, ptr %2, align 4, !tbaa !5
  %8 = tail call zeroext i16 @ReadPTLen(ptr noundef nonnull %0, i16 noundef zeroext 19, i16 noundef zeroext 5, i16 noundef zeroext 3)
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  store i16 %8, ptr %9, align 8, !tbaa !12
  %.not = icmp eq i16 %8, 0
  br i1 %.not, label %10, label %40

10:                                               ; preds = %5
  tail call void @ReadCLen(ptr noundef nonnull %0)
  %11 = getelementptr inbounds i8, ptr %0, i64 13372
  %12 = load i8, ptr %11, align 4, !tbaa !13
  %13 = zext i8 %12 to i16
  %14 = tail call zeroext i16 @ReadPTLen(ptr noundef nonnull %0, i16 noundef zeroext 31, i16 noundef zeroext %13, i16 noundef zeroext -1)
  store i16 %14, ptr %9, align 8, !tbaa !12
  %.not29 = icmp eq i16 %14, 0
  br i1 %.not29, label %._crit_edge, label %40

._crit_edge:                                      ; preds = %10
  %.pre = load i16, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %._crit_edge, %1
  %16 = phi i16 [ %.pre, %._crit_edge ], [ %3, %1 ]
  %17 = add i16 %16, -1
  store i16 %17, ptr %2, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 4668
  %19 = getelementptr inbounds i8, ptr %0, i64 28
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = lshr i32 %20, 20
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [4096 x i16], ptr %18, i64 0, i64 %22
  %24 = load i16, ptr %23, align 2, !tbaa !15
  %25 = icmp ugt i16 %24, 509
  br i1 %25, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %15
  %26 = getelementptr inbounds i8, ptr %0, i64 2088
  %27 = getelementptr inbounds i8, ptr %0, i64 50
  br label %28

28:                                               ; preds = %.preheader, %28
  %.027 = phi i16 [ %.1, %28 ], [ %24, %.preheader ]
  %.0 = phi i32 [ %33, %28 ], [ 524288, %.preheader ]
  %29 = and i32 %.0, %20
  %.not30 = icmp eq i32 %29, 0
  %30 = zext i16 %.027 to i64
  %31 = getelementptr inbounds [1019 x i16], ptr %26, i64 0, i64 %30
  %32 = getelementptr inbounds [1019 x i16], ptr %27, i64 0, i64 %30
  %.1.in = select i1 %.not30, ptr %32, ptr %31
  %.1 = load i16, ptr %.1.in, align 2, !tbaa !15
  %33 = lshr i32 %.0, 1
  %34 = icmp ugt i16 %.1, 509
  br i1 %34, label %28, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %28, %15
  %.2 = phi i16 [ %24, %15 ], [ %.1, %28 ]
  %35 = getelementptr inbounds i8, ptr %0, i64 4126
  %36 = zext nneg i16 %.2 to i64
  %37 = getelementptr inbounds [510 x i8], ptr %35, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !18
  %39 = zext i8 %38 to i16
  tail call void @FillBuf(ptr noundef %0, i16 noundef zeroext %39)
  br label %40

40:                                               ; preds = %10, %5, %.loopexit
  %.028 = phi i16 [ %.2, %.loopexit ], [ 0, %5 ], [ 0, %10 ]
  ret i16 %.028
}

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 36}
!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, !11, i64 48}
!13 = !{!6, !8, i64 13372}
!14 = !{!6, !10, i64 28}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!8, !8, i64 0}


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