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

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

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1

; 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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

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

11:                                               ; preds = %4
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  %15 = load i16, ptr %7, align 2, !tbaa !10
  %16 = zext i16 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 750, ptr noundef @.str.4)
  br label %19

19:                                               ; preds = %18, %14
  br label %20

20:                                               ; preds = %19, %11
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  store i64 0, ptr %9, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %64, %22
  %24 = load i64, ptr %9, align 8, !tbaa !12
  %25 = load i16, ptr %7, align 2, !tbaa !10
  %26 = zext i16 %25 to i32
  %27 = add nsw i32 %26, 254
  %28 = sdiv i32 %27, 255
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %24, %29
  br i1 %30, label %31, label %67

31:                                               ; preds = %23
  %32 = load i16, ptr %7, align 2, !tbaa !10
  %33 = zext i16 %32 to i64
  %34 = load i64, ptr %9, align 8, !tbaa !12
  %35 = mul nsw i64 %34, 255
  %36 = sub nsw i64 %33, %35
  %37 = icmp slt i64 255, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %31
  br label %45

39:                                               ; preds = %31
  %40 = load i16, ptr %7, align 2, !tbaa !10
  %41 = zext i16 %40 to i64
  %42 = load i64, ptr %9, align 8, !tbaa !12
  %43 = mul nsw i64 %42, 255
  %44 = sub nsw i64 %41, %43
  br label %45

45:                                               ; preds = %39, %38
  %46 = phi i64 [ 255, %38 ], [ %44, %39 ]
  store i64 %46, ptr %10, align 8, !tbaa !12
  %47 = load i8, ptr %6, align 1, !tbaa !9
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %5, align 8, !tbaa !5
  store i8 %47, ptr %48, align 1, !tbaa !9
  %50 = load i64, ptr %10, align 8, !tbaa !12
  %51 = trunc i64 %50 to i8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %5, align 8, !tbaa !5
  store i8 %51, ptr %52, align 1, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !12
  %57 = mul nsw i64 %56, 255
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i64, ptr %10, align 8, !tbaa !12
  %60 = call ptr @CopyMem(ptr noundef %54, ptr noundef %58, i64 noundef %59)
  %61 = load i64, ptr %10, align 8, !tbaa !12
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 %61
  store ptr %63, ptr %5, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %45
  %65 = load i64, ptr %9, align 8, !tbaa !12
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %9, align 8, !tbaa !12
  br label %23, !llvm.loop !14

67:                                               ; preds = %23
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @DhcpAppendOption(ptr noundef %0, i8 noundef zeroext %1, i16 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %6 = icmp eq i8 %5, 0
  %7 = icmp ne i16 %2, 0
  %or.cond = or i1 %7, %6
  br i1 %or.cond, label %8, label %.thread

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

8:                                                ; preds = %4
  %9 = zext i16 %2 to i32
  %10 = add nuw nsw i32 %9, 254
  %11 = udiv i32 %10, 255
  %12 = zext nneg i32 %11 to i64
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %13 = zext i16 %2 to i64
  br label %14

14:                                               ; preds = %.lr.ph, %14
  %.023 = phi ptr [ %0, %.lr.ph ], [ %22, %14 ]
  %.02022 = phi i64 [ 0, %.lr.ph ], [ %23, %14 ]
  %15 = mul nuw nsw i64 %.02022, 255
  %16 = sub nsw i64 %13, %15
  %spec.select = tail call i64 @llvm.smin.i64(i64 %16, i64 255)
  %17 = getelementptr inbounds i8, ptr %.023, i64 1
  store i8 %1, ptr %.023, align 1, !tbaa !5
  %18 = trunc i64 %spec.select to i8
  %19 = getelementptr inbounds i8, ptr %.023, i64 2
  store i8 %18, ptr %17, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %3, i64 %15
  %21 = tail call ptr @CopyMem(ptr noundef nonnull %19, ptr noundef %20, i64 noundef %spec.select) #3
  %22 = getelementptr inbounds i8, ptr %19, i64 %spec.select
  %23 = add nuw nsw i64 %.02022, 1
  %exitcond.not = icmp eq i64 %23, %12
  br i1 %exitcond.not, label %._crit_edge, label %14, !llvm.loop !8

._crit_edge:                                      ; preds = %14, %.thread, %8
  %.0.lcssa = phi ptr [ %0, %8 ], [ %0, %.thread ], [ %22, %14 ]
  ret ptr %.0.lcssa
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #2

attributes #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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