; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (DhcpFillOption)

; 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.DHCP_OPTION_CONTEXT = type { ptr, ptr, ptr }
%struct.DHCP_OPTION_COUNT = type { i8, i16 }
%struct.DHCP_OPTION = type { i8, i16, ptr }

; 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
define dso_local i64 @DhcpFillOption(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  store i8 %0, ptr %5, align 1, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !8
  store ptr %3, ptr %8, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, 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
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  %14 = load ptr, ptr %8, align 8, !tbaa !8
  store ptr %14, ptr %9, align 8, !tbaa !8
  %15 = load ptr, ptr %9, align 8, !tbaa !8
  %16 = getelementptr inbounds %struct.DHCP_OPTION_CONTEXT, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  store ptr %17, ptr %10, align 8, !tbaa !8
  %18 = load ptr, ptr %10, align 8, !tbaa !8
  %19 = load i8, ptr %5, align 1, !tbaa !5
  %20 = zext i8 %19 to i64
  %21 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %18, i64 %20
  %22 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %21, i32 0, i32 0
  %23 = load i8, ptr %22, align 2, !tbaa !12
  store i8 %23, ptr %13, align 1, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !8
  %25 = getelementptr inbounds %struct.DHCP_OPTION_CONTEXT, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  store ptr %26, ptr %11, align 8, !tbaa !8
  %27 = load ptr, ptr %9, align 8, !tbaa !8
  %28 = getelementptr inbounds %struct.DHCP_OPTION_CONTEXT, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  store ptr %29, ptr %12, align 8, !tbaa !8
  %30 = load ptr, ptr %11, align 8, !tbaa !8
  %31 = load i8, ptr %13, align 1, !tbaa !5
  %32 = zext i8 %31 to i64
  %33 = getelementptr inbounds %struct.DHCP_OPTION, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.DHCP_OPTION, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %59

37:                                               ; preds = %4
  %38 = load i8, ptr %5, align 1, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !8
  %40 = load i8, ptr %13, align 1, !tbaa !5
  %41 = zext i8 %40 to i64
  %42 = getelementptr inbounds %struct.DHCP_OPTION, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.DHCP_OPTION, ptr %42, i32 0, i32 0
  store i8 %38, ptr %43, align 8, !tbaa !19
  %44 = load ptr, ptr %12, align 8, !tbaa !8
  %45 = load ptr, ptr %10, align 8, !tbaa !8
  %46 = load i8, ptr %5, align 1, !tbaa !5
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %48, i32 0, i32 1
  %50 = load i16, ptr %49, align 2, !tbaa !20
  %51 = zext i16 %50 to i32
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %44, i64 %52
  %54 = load ptr, ptr %11, align 8, !tbaa !8
  %55 = load i8, ptr %13, align 1, !tbaa !5
  %56 = zext i8 %55 to i64
  %57 = getelementptr inbounds %struct.DHCP_OPTION, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.DHCP_OPTION, ptr %57, i32 0, i32 2
  store ptr %53, ptr %58, align 8, !tbaa !17
  br label %59

59:                                               ; preds = %37, %4
  %60 = load ptr, ptr %12, align 8, !tbaa !8
  %61 = load ptr, ptr %10, align 8, !tbaa !8
  %62 = load i8, ptr %5, align 1, !tbaa !5
  %63 = zext i8 %62 to i64
  %64 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %61, i64 %63
  %65 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %64, i32 0, i32 1
  %66 = load i16, ptr %65, align 2, !tbaa !20
  %67 = zext i16 %66 to i32
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %60, i64 %68
  %70 = load ptr, ptr %7, align 8, !tbaa !8
  %71 = load i8, ptr %6, align 1, !tbaa !5
  %72 = zext i8 %71 to i64
  %73 = call ptr @CopyMem(ptr noundef %69, ptr noundef %70, i64 noundef %72)
  %74 = load ptr, ptr %10, align 8, !tbaa !8
  %75 = load i8, ptr %5, align 1, !tbaa !5
  %76 = zext i8 %75 to i64
  %77 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %74, i64 %76
  %78 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %77, i32 0, i32 1
  %79 = load i16, ptr %78, align 2, !tbaa !20
  %80 = zext i16 %79 to i32
  %81 = load i8, ptr %6, align 1, !tbaa !5
  %82 = zext i8 %81 to i32
  %83 = add nsw i32 %80, %82
  %84 = trunc i32 %83 to i16
  %85 = load ptr, ptr %10, align 8, !tbaa !8
  %86 = load i8, ptr %5, align 1, !tbaa !5
  %87 = zext i8 %86 to i64
  %88 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %88, i32 0, i32 1
  store i16 %84, ptr %89, align 2, !tbaa !20
  %90 = load ptr, ptr %11, align 8, !tbaa !8
  %91 = load i8, ptr %13, align 1, !tbaa !5
  %92 = zext i8 %91 to i64
  %93 = getelementptr inbounds %struct.DHCP_OPTION, ptr %90, i64 %92
  %94 = getelementptr inbounds %struct.DHCP_OPTION, ptr %93, i32 0, i32 1
  %95 = load i16, ptr %94, align 2, !tbaa !21
  %96 = zext i16 %95 to i32
  %97 = load i8, ptr %6, align 1, !tbaa !5
  %98 = zext i8 %97 to i32
  %99 = add nsw i32 %96, %98
  %100 = trunc i32 %99 to i16
  %101 = load ptr, ptr %11, align 8, !tbaa !8
  %102 = load i8, ptr %13, align 1, !tbaa !5
  %103 = zext i8 %102 to i64
  %104 = getelementptr inbounds %struct.DHCP_OPTION, ptr %101, i64 %103
  %105 = getelementptr inbounds %struct.DHCP_OPTION, ptr %104, i32 0, i32 1
  store i16 %100, ptr %105, align 2, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  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 8, ptr %9) #3
  ret i64 0
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #2

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"", !9, i64 0, !9, i64 8, !9, i64 16}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !14, i64 2}
!14 = !{!"short", !6, i64 0}
!15 = !{!11, !9, i64 8}
!16 = !{!11, !9, i64 16}
!17 = !{!18, !9, i64 8}
!18 = !{!"", !6, i64 0, !14, i64 2, !9, i64 8}
!19 = !{!18, !6, i64 0}
!20 = !{!13, !14, i64 2}
!21 = !{!18, !14, i64 2}


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

%struct.DHCP_OPTION_COUNT = type { i8, i16 }
%struct.DHCP_OPTION = type { i8, i16, ptr }

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @DhcpFillOption(i8 noundef zeroext %0, i8 noundef zeroext %1, ptr noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = zext i8 %0 to i64
  %7 = getelementptr inbounds %struct.DHCP_OPTION_COUNT, ptr %5, i64 %6
  %8 = load i8, ptr %7, align 2, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = zext i8 %8 to i64
  %14 = getelementptr inbounds %struct.DHCP_OPTION, ptr %10, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.phi.trans.insert = getelementptr inbounds i8, ptr %7, i64 2
  %.pre = load i16, ptr %.phi.trans.insert, align 2, !tbaa !17
  %.pre30 = zext i16 %.pre to i64
  br label %23

18:                                               ; preds = %4
  store i8 %0, ptr %14, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %7, i64 2
  %20 = load i16, ptr %19, align 2, !tbaa !17
  %21 = zext i16 %20 to i64
  %22 = getelementptr inbounds i8, ptr %12, i64 %21
  store ptr %22, ptr %15, align 8, !tbaa !15
  br label %23

23:                                               ; preds = %._crit_edge, %18
  %.pre-phi = phi i64 [ %.pre30, %._crit_edge ], [ %21, %18 ]
  %24 = getelementptr inbounds i8, ptr %7, i64 2
  %25 = getelementptr inbounds i8, ptr %12, i64 %.pre-phi
  %26 = zext i8 %1 to i64
  %27 = tail call ptr @CopyMem(ptr noundef %25, ptr noundef %2, i64 noundef %26) #2
  %28 = load i16, ptr %24, align 2, !tbaa !17
  %29 = zext i8 %1 to i16
  %30 = add i16 %28, %29
  store i16 %30, ptr %24, align 2, !tbaa !17
  %31 = getelementptr inbounds i8, ptr %14, i64 2
  %32 = load i16, ptr %31, align 2, !tbaa !19
  %33 = add i16 %32, %29
  store i16 %33, ptr %31, align 2, !tbaa !19
  ret i64 0
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 0}
!11 = !{!"", !8, i64 0, !12, i64 2}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!16, !7, i64 8}
!16 = !{!"", !8, i64 0, !12, i64 2, !7, i64 8}
!17 = !{!11, !12, i64 2}
!18 = !{!16, !8, i64 0}
!19 = !{!16, !12, i64 2}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass