; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Mtftp6Dxe (Mtftp6ParseStart)

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp6ParseStart(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 i32, ptr %7, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

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

21:                                               ; preds = %17
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %22, align 4, !tbaa !9
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %25, %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i16, ptr %28, align 1, !tbaa !11
  %30 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %29)
  %31 = zext i16 %30 to i32
  %32 = icmp ne i32 %31, 6
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

34:                                               ; preds = %27
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = getelementptr inbounds i8, ptr %38, i64 -1
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %34
  store i64 -9223372036854775784, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

44:                                               ; preds = %34
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = call i64 @Mtftp6ParsePacketOption(ptr noundef %45, i32 noundef %46, ptr noundef %47, ptr noundef null)
  store i64 %48, ptr %10, align 8, !tbaa !12
  %49 = load i64, ptr %10, align 8, !tbaa !12
  %50 = icmp ne i64 %49, -9223372036854775803
  br i1 %50, label %51, label %53

51:                                               ; preds = %44
  %52 = load i64, ptr %10, align 8, !tbaa !12
  store i64 %52, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

53:                                               ; preds = %44
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  store i64 -9223372036854775794, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

58:                                               ; preds = %53
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

62:                                               ; preds = %58
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = mul i64 %65, 16
  %67 = call ptr @AllocateZeroPool(i64 noundef %66)
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %67, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %73

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

73:                                               ; preds = %62
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = call i64 @Mtftp6ParsePacketOption(ptr noundef %74, i32 noundef %75, ptr noundef %76, ptr noundef %78)
  store i64 %79, ptr %10, align 8, !tbaa !12
  %80 = load i64, ptr %10, align 8, !tbaa !12
  %81 = icmp slt i64 %80, 0
  br i1 %81, label %82, label %84

82:                                               ; preds = %73
  %83 = load i64, ptr %10, align 8, !tbaa !12
  store i64 %83, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

84:                                               ; preds = %73
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %85

85:                                               ; preds = %84, %82, %72, %61, %57, %51, %43, %33, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %86 = load i64, ptr %5, align 8
  ret i64 %86
}

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

declare ptr @AllocateZeroPool(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 @Mtftp6ParsePacketOption(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp6ParseStart(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %1, 0
  %6 = icmp eq ptr %0, null
  %or.cond = or i1 %6, %5
  %7 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %7
  br i1 %or.cond3, label %30, label %8

8:                                                ; preds = %4
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %10, label %9

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

10:                                               ; preds = %9, %8
  %11 = load i16, ptr %0, align 1, !tbaa !11
  %12 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %11) #3
  %.not36 = icmp eq i16 %12, 6
  br i1 %.not36, label %13, label %30

13:                                               ; preds = %10
  %14 = zext i32 %1 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 -1
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %.not37 = icmp eq i8 %17, 0
  br i1 %.not37, label %18, label %30

18:                                               ; preds = %13
  %19 = tail call i64 @Mtftp6ParsePacketOption(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef null)
  %.not38 = icmp eq i64 %19, -9223372036854775803
  br i1 %.not38, label %20, label %30

20:                                               ; preds = %18
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 0
  %brmerge = or i1 %.not, %22
  %.mux = select i1 %22, i64 -9223372036854775794, i64 0
  br i1 %brmerge, label %30, label %23

23:                                               ; preds = %20
  %24 = zext i32 %21 to i64
  %25 = shl nuw nsw i64 %24, 4
  %26 = tail call ptr @AllocateZeroPool(i64 noundef %25) #3
  store ptr %26, ptr %3, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %30, label %28

28:                                               ; preds = %23
  %29 = tail call i64 @Mtftp6ParsePacketOption(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2, ptr noundef nonnull %26)
  %. = tail call i64 @llvm.smin.i64(i64 %29, i64 0)
  br label %30

30:                                               ; preds = %20, %28, %23, %18, %13, %10, %4
  %.0 = phi i64 [ -9223372036854775806, %4 ], [ -9223372036854775806, %10 ], [ -9223372036854775784, %13 ], [ %19, %18 ], [ %.mux, %20 ], [ -9223372036854775799, %23 ], [ %., %28 ]
  ret i64 %.0
}

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

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

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 = { 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 = !{!"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