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

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

; 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 i64 @Mtftp4FillOptions(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4ExtractOptions(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i16, ptr %18, align 1, !tbaa !11
  %20 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %19)
  %21 = zext i16 %20 to i32
  %22 = icmp ne i32 %21, 6
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

24:                                               ; preds = %17
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

28:                                               ; preds = %24
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %29, i64 %31
  %33 = getelementptr inbounds i8, ptr %32, i64 -1
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %28
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

38:                                               ; preds = %28
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call i64 @Mtftp4FillOptions(ptr noundef %39, i32 noundef %40, ptr noundef %41, ptr noundef null)
  store i64 %42, ptr %10, align 8, !tbaa !12
  %43 = load i64, ptr %10, align 8, !tbaa !12
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %48, label %45

45:                                               ; preds = %38
  %46 = load i64, ptr %10, align 8, !tbaa !12
  %47 = icmp ne i64 %46, -9223372036854775803
  br i1 %47, label %48, label %50

48:                                               ; preds = %45, %38
  %49 = load i64, ptr %10, align 8, !tbaa !12
  store i64 %49, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

50:                                               ; preds = %45
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %54

53:                                               ; preds = %50
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

54:                                               ; preds = %50
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = mul i64 %57, 16
  %59 = call ptr @AllocatePool(i64 noundef %58)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %54
  store i64 -9223372036854775799, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

65:                                               ; preds = %54
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = call i64 @Mtftp4FillOptions(ptr noundef %66, i32 noundef %67, ptr noundef %68, ptr noundef %70)
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %65, %64, %53, %48, %37, %27, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %73 = load i64, ptr %5, align 8
  ret i64 %73
}

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #2

declare ptr @AllocatePool(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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !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 i64 @Mtftp4FillOptions(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775802, -9223372036854775803) i64 @Mtftp4ExtractOptions(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %4
  store ptr null, ptr %3, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %5, %4
  %7 = load i16, ptr %0, align 1, !tbaa !11
  %8 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %7) #2
  %.not26 = icmp eq i16 %8, 6
  br i1 %.not26, label %9, label %26

9:                                                ; preds = %6
  %10 = icmp eq i32 %1, 2
  br i1 %10, label %26, label %11

11:                                               ; preds = %9
  %12 = zext i32 %1 to i64
  %13 = getelementptr inbounds i8, ptr %0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 -1
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %.not27 = icmp eq i8 %15, 0
  br i1 %.not27, label %16, label %26

16:                                               ; preds = %11
  %17 = tail call i64 @Mtftp4FillOptions(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef null)
  %.not28 = icmp ne i64 %17, -9223372036854775803
  %brmerge = or i1 %.not, %.not28
  %.mux = select i1 %.not28, i64 %17, i64 0
  br i1 %brmerge, label %26, label %18

18:                                               ; preds = %16
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = zext i32 %19 to i64
  %21 = shl nuw nsw i64 %20, 4
  %22 = tail call ptr @AllocatePool(i64 noundef %21) #2
  store ptr %22, ptr %3, align 8, !tbaa !9
  %23 = icmp eq ptr %22, null
  br i1 %23, label %26, label %24

24:                                               ; preds = %18
  %25 = tail call i64 @Mtftp4FillOptions(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %22)
  br label %26

26:                                               ; preds = %16, %18, %11, %9, %6, %24
  %.0 = phi i64 [ 0, %24 ], [ -9223372036854775806, %6 ], [ 0, %9 ], [ -9223372036854775806, %11 ], [ %.mux, %16 ], [ -9223372036854775799, %18 ]
  ret i64 %.0
}

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #1

declare ptr @AllocatePool(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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass