; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg (E100bGetEepromAddrLen)

; 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.s_data_instance = type { i16, i16, i8, i8, i16, i16, i16, i16, i16, [32 x i8], [32 x i8], [32 x i8], [64 x i32], [128 x i32], i32, i32, i16, i16, i8, i8, i8, i8, i16, i16, i16, i16, i32, i32, i16, i16, [2 x i16], i8, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, [64 x i64], i16, i16, i16, i16, i8, i8, i8, i8, i8, [3 x i8], %struct.mc, i64, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.mc = type { [3 x i16], i16, [8 x [32 x i8]] }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @InByte(ptr noundef, i32 noundef) #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 void @OutByte(ptr noundef, i8 noundef zeroext, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @E100bGetEepromAddrLen(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.s_data_instance, ptr %7, i32 0, i32 14
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = add i32 %9, 14
  store i32 %10, ptr %5, align 4, !tbaa !15
  store i16 384, ptr %6, align 2, !tbaa !16
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call zeroext i8 @E100bSetEepromLockOut(ptr noundef %11)
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !15
  %15 = call zeroext i8 @InByte(ptr noundef %13, i32 noundef %14)
  %16 = zext i8 %15 to i32
  %17 = and i32 %16, 242
  %18 = trunc i32 %17 to i8
  store i8 %18, ptr %3, align 1, !tbaa !17
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i8, ptr %3, align 1, !tbaa !17
  %21 = zext i8 %20 to i32
  %22 = or i32 %21, 2
  %23 = trunc i32 %22 to i8
  %24 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %19, i8 noundef zeroext %23, i32 noundef %24)
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = load i16, ptr %6, align 2, !tbaa !16
  call void @shift_bits_out(ptr noundef %25, i16 noundef zeroext %26, i8 noundef zeroext 9)
  store i8 6, ptr %4, align 1, !tbaa !17
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !15
  %29 = call zeroext i8 @InByte(ptr noundef %27, i32 noundef %28)
  store i8 %29, ptr %3, align 1, !tbaa !17
  br label %30

30:                                               ; preds = %41, %1
  %31 = load i8, ptr %4, align 1, !tbaa !17
  %32 = zext i8 %31 to i32
  %33 = icmp slt i32 %32, 8
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i8, ptr %3, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = and i32 %36, 8
  %38 = icmp ne i32 %37, 0
  br label %39

39:                                               ; preds = %34, %30
  %40 = phi i1 [ false, %30 ], [ %38, %34 ]
  br i1 %40, label %41, label %68

41:                                               ; preds = %39
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load i8, ptr %3, align 1, !tbaa !17
  %44 = zext i8 %43 to i32
  %45 = and i32 %44, -5
  %46 = trunc i32 %45 to i8
  %47 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %42, i8 noundef zeroext %46, i32 noundef %47)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %48, i16 noundef zeroext 100)
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load i8, ptr %3, align 1, !tbaa !17
  %51 = zext i8 %50 to i32
  %52 = or i32 %51, 1
  %53 = trunc i32 %52 to i8
  %54 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %49, i8 noundef zeroext %53, i32 noundef %54)
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %55, i16 noundef zeroext 150)
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = load i8, ptr %3, align 1, !tbaa !17
  %58 = zext i8 %57 to i32
  %59 = and i32 %58, -2
  %60 = trunc i32 %59 to i8
  %61 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %56, i8 noundef zeroext %60, i32 noundef %61)
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %62, i16 noundef zeroext 150)
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !15
  %65 = call zeroext i8 @InByte(ptr noundef %63, i32 noundef %64)
  store i8 %65, ptr %3, align 1, !tbaa !17
  %66 = load i8, ptr %4, align 1, !tbaa !17
  %67 = add i8 %66, 1
  store i8 %67, ptr %4, align 1, !tbaa !17
  br label %30, !llvm.loop !18

68:                                               ; preds = %39
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = call zeroext i16 @shift_bits_in(ptr noundef %69)
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !15
  %73 = call zeroext i8 @InByte(ptr noundef %71, i32 noundef %72)
  store i8 %73, ptr %3, align 1, !tbaa !17
  %74 = load i8, ptr %3, align 1, !tbaa !17
  %75 = zext i8 %74 to i32
  %76 = and i32 %75, -7
  %77 = trunc i32 %76 to i8
  store i8 %77, ptr %3, align 1, !tbaa !17
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = load i8, ptr %3, align 1, !tbaa !17
  %80 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %78, i8 noundef zeroext %79, i32 noundef %80)
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = load i8, ptr %3, align 1, !tbaa !17
  %83 = zext i8 %82 to i32
  %84 = or i32 %83, 1
  %85 = trunc i32 %84 to i8
  %86 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %81, i8 noundef zeroext %85, i32 noundef %86)
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %87, i16 noundef zeroext 100)
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = load i8, ptr %3, align 1, !tbaa !17
  %90 = zext i8 %89 to i32
  %91 = and i32 %90, -2
  %92 = trunc i32 %91 to i8
  %93 = load i32, ptr %5, align 4, !tbaa !15
  call void @OutByte(ptr noundef %88, i8 noundef zeroext %92, i32 noundef %93)
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  call void @DelayIt(ptr noundef %94, i16 noundef zeroext 100)
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  call void @E100bReSetEepromLockOut(ptr noundef %95)
  %96 = load i8, ptr %4, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i8 %96
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @E100bSetEepromLockOut(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @E100bReSetEepromLockOut(ptr noundef) #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 = { 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 880}
!10 = !{!"s_data_instance", !11, i64 0, !11, i64 2, !7, i64 4, !7, i64 5, !11, i64 6, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !7, i64 16, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 368, !12, i64 880, !12, i64 884, !11, i64 888, !11, i64 890, !7, i64 892, !7, i64 893, !7, i64 894, !7, i64 895, !11, i64 896, !11, i64 898, !11, i64 900, !11, i64 902, !12, i64 904, !12, i64 908, !11, i64 912, !11, i64 914, !7, i64 916, !7, i64 920, !7, i64 921, !11, i64 922, !12, i64 924, !6, i64 928, !6, i64 936, !6, i64 944, !6, i64 952, !6, i64 960, !6, i64 968, !13, i64 976, !13, i64 984, !13, i64 992, !13, i64 1000, !13, i64 1008, !7, i64 1016, !11, i64 1528, !11, i64 1530, !11, i64 1532, !11, i64 1534, !7, i64 1536, !7, i64 1537, !7, i64 1538, !7, i64 1539, !7, i64 1540, !7, i64 1541, !14, i64 1544, !13, i64 1808, !6, i64 1816, !13, i64 1824, !6, i64 1832, !6, i64 1840, !6, i64 1848, !6, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888, !6, i64 1896, !6, i64 1904, !6, i64 1912}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"mc", !7, i64 0, !11, i64 6, !7, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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 zeroext i8 @InByte(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @OutByte(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @E100bGetEepromAddrLen(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 880
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = add i32 %3, 14
  %5 = tail call zeroext i8 @E100bSetEepromLockOut(ptr noundef %0)
  %6 = tail call zeroext i8 @InByte(ptr noundef %0, i32 noundef %4)
  %7 = and i8 %6, -16
  %8 = or disjoint i8 %7, 2
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %8, i32 noundef %4)
  tail call void @shift_bits_out(ptr noundef %0, i16 noundef zeroext 384, i8 noundef zeroext 9)
  %9 = tail call zeroext i8 @InByte(ptr noundef %0, i32 noundef %4)
  %10 = and i8 %9, 8
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.046 = phi i8 [ %14, %.lr.ph ], [ %9, %1 ]
  %.04445 = phi i8 [ %15, %.lr.ph ], [ 6, %1 ]
  %11 = and i8 %.046, -5
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %11, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 100)
  %12 = or i8 %.046, 1
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %12, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 150)
  %13 = and i8 %.046, -2
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %13, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 150)
  %14 = tail call zeroext i8 @InByte(ptr noundef %0, i32 noundef %4)
  %15 = add nuw nsw i8 %.04445, 1
  %16 = icmp ult i8 %.04445, 7
  %17 = and i8 %14, 8
  %18 = icmp ne i8 %17, 0
  %19 = select i1 %16, i1 %18, i1 false
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.044.lcssa = phi i8 [ 6, %1 ], [ %15, %.lr.ph ]
  %20 = tail call zeroext i16 @shift_bits_in(ptr noundef %0)
  %21 = tail call zeroext i8 @InByte(ptr noundef %0, i32 noundef %4)
  %22 = and i8 %21, -7
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %22, i32 noundef %4)
  %23 = or i8 %22, 1
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %23, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 100)
  %24 = and i8 %21, -8
  tail call void @OutByte(ptr noundef %0, i8 noundef zeroext %24, i32 noundef %4)
  tail call void @DelayIt(ptr noundef %0, i16 noundef zeroext 100)
  tail call void @E100bReSetEepromLockOut(ptr noundef %0)
  ret i8 %.044.lcssa
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @E100bReSetEepromLockOut(ptr noundef) local_unnamed_addr #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" }

!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, !10, i64 880}
!6 = !{!"s_data_instance", !7, i64 0, !7, i64 2, !8, i64 4, !8, i64 5, !7, i64 6, !7, i64 8, !7, i64 10, !7, i64 12, !7, i64 14, !8, i64 16, !8, i64 48, !8, i64 80, !8, i64 112, !8, i64 368, !10, i64 880, !10, i64 884, !7, i64 888, !7, i64 890, !8, i64 892, !8, i64 893, !8, i64 894, !8, i64 895, !7, i64 896, !7, i64 898, !7, i64 900, !7, i64 902, !10, i64 904, !10, i64 908, !7, i64 912, !7, i64 914, !8, i64 916, !8, i64 920, !8, i64 921, !7, i64 922, !10, i64 924, !11, i64 928, !11, i64 936, !11, i64 944, !11, i64 952, !11, i64 960, !11, i64 968, !12, i64 976, !12, i64 984, !12, i64 992, !12, i64 1000, !12, i64 1008, !8, i64 1016, !7, i64 1528, !7, i64 1530, !7, i64 1532, !7, i64 1534, !8, i64 1536, !8, i64 1537, !8, i64 1538, !8, i64 1539, !8, i64 1540, !8, i64 1541, !13, i64 1544, !12, i64 1808, !11, i64 1816, !12, i64 1824, !11, i64 1832, !11, i64 1840, !11, i64 1848, !11, i64 1856, !11, i64 1864, !11, i64 1872, !11, i64 1880, !11, i64 1888, !11, i64 1896, !11, i64 1904, !11, i64 1912}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"mc", !8, i64 0, !7, i64 6, !8, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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