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

; 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._EFI_MTFTP4_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP4_GETINFO_STATE = type { ptr, ptr, i64 }

; 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 @Mtftp4GetInfoCheckPacket(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @EfiMtftp4ReadFile(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiMtftp4GetInfo(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #1 {
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i8, align 1
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca %struct._EFI_MTFTP4_TOKEN, align 8
  %19 = alloca %struct.MTFTP4_GETINFO_STATE, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i8 %4, ptr %14, align 1, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 104, ptr %18) #2
  call void @llvm.lifetime.start.p0(i64 24, ptr %19) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #2
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %37, label %24

24:                                               ; preds = %8
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %37, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr %16, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %37, label %30

30:                                               ; preds = %27
  %31 = load i8, ptr %14, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %27, %24, %8
  store i64 -9223372036854775806, ptr %9, align 8
  store i32 1, ptr %21, align 4
  br label %78

38:                                               ; preds = %34, %30
  %39 = load ptr, ptr %17, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr null, ptr %42, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %41, %38
  %44 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 0, ptr %44, align 4, !tbaa !10
  %45 = load ptr, ptr %17, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %19, i32 0, i32 0
  store ptr %45, ptr %46, align 8, !tbaa !12
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %19, i32 0, i32 1
  store ptr %47, ptr %48, align 8, !tbaa !15
  %49 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %19, i32 0, i32 2
  store i64 0, ptr %49, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 0
  store i64 0, ptr %50, align 8, !tbaa !17
  %51 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 1
  store ptr null, ptr %51, align 8, !tbaa !19
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 2
  store ptr %52, ptr %53, align 8, !tbaa !20
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 3
  store ptr %54, ptr %55, align 8, !tbaa !21
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 4
  store ptr %56, ptr %57, align 8, !tbaa !22
  %58 = load i8, ptr %14, align 1, !tbaa !9
  %59 = zext i8 %58 to i32
  %60 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 5
  store i32 %59, ptr %60, align 8, !tbaa !23
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 6
  store ptr %61, ptr %62, align 8, !tbaa !24
  %63 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 7
  store i64 0, ptr %63, align 8, !tbaa !25
  %64 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 8
  store ptr null, ptr %64, align 8, !tbaa !26
  %65 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 9
  store ptr %19, ptr %65, align 8, !tbaa !27
  %66 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 10
  store ptr @Mtftp4GetInfoCheckPacket, ptr %66, align 8, !tbaa !28
  %67 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 11
  store ptr null, ptr %67, align 8, !tbaa !29
  %68 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %18, i32 0, i32 12
  store ptr null, ptr %68, align 8, !tbaa !30
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = call i64 @EfiMtftp4ReadFile(ptr noundef %69, ptr noundef %18)
  store i64 %70, ptr %20, align 8, !tbaa !31
  %71 = load i64, ptr %20, align 8, !tbaa !31
  %72 = icmp eq i64 -9223372036854775787, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %43
  %74 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %19, i32 0, i32 2
  %75 = load i64, ptr %74, align 8, !tbaa !16
  store i64 %75, ptr %9, align 8
  store i32 1, ptr %21, align 4
  br label %78

76:                                               ; preds = %43
  %77 = load i64, ptr %20, align 8, !tbaa !31
  store i64 %77, ptr %9, align 8
  store i32 1, ptr %21, align 4
  br label %78

78:                                               ; preds = %76, %73, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 24, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 104, ptr %18) #2
  %79 = load i64, ptr %9, align 8
  ret i64 %79
}

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 = { 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 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !14, i64 16}
!14 = !{!"long long", !7, i64 0}
!15 = !{!13, !6, i64 8}
!16 = !{!13, !14, i64 16}
!17 = !{!18, !14, i64 0}
!18 = !{!"_EFI_MTFTP4_TOKEN", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !14, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !6, i64 16}
!21 = !{!18, !6, i64 24}
!22 = !{!18, !6, i64 32}
!23 = !{!18, !11, i64 40}
!24 = !{!18, !6, i64 48}
!25 = !{!18, !14, i64 56}
!26 = !{!18, !6, i64 64}
!27 = !{!18, !6, i64 72}
!28 = !{!18, !6, i64 80}
!29 = !{!18, !6, i64 88}
!30 = !{!18, !6, i64 96}
!31 = !{!14, !14, 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"

%struct._EFI_MTFTP4_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP4_GETINFO_STATE = type { ptr, ptr, i64 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @Mtftp4GetInfoCheckPacket(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @EfiMtftp4ReadFile(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiMtftp4GetInfo(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i8 noundef zeroext %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #1 {
  %9 = alloca %struct._EFI_MTFTP4_TOKEN, align 8
  %10 = alloca %struct.MTFTP4_GETINFO_STATE, align 8
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #3
  %11 = icmp eq ptr %0, null
  %12 = icmp eq ptr %2, null
  %or.cond = or i1 %11, %12
  %13 = icmp eq ptr %6, null
  %or.cond3 = or i1 %or.cond, %13
  br i1 %or.cond3, label %35, label %14

14:                                               ; preds = %8
  %15 = zext i8 %4 to i32
  %16 = icmp ne i8 %4, 0
  %17 = icmp eq ptr %5, null
  %or.cond5 = and i1 %16, %17
  br i1 %or.cond5, label %35, label %18

18:                                               ; preds = %14
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %20, label %19

19:                                               ; preds = %18
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %19, %18
  store i32 0, ptr %6, align 4, !tbaa !9
  store ptr %7, ptr %10, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %6, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %10, i64 16
  store i64 0, ptr %22, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %9, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %9, i8 0, i64 16, i1 false)
  store ptr %1, ptr %23, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %2, ptr %24, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr %3, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %9, i64 40
  store i32 %15, ptr %26, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %9, i64 48
  store ptr %5, ptr %27, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %9, i64 56
  %29 = getelementptr inbounds i8, ptr %9, i64 72
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %28, i8 0, i64 16, i1 false)
  store ptr %10, ptr %29, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %9, i64 80
  store ptr @Mtftp4GetInfoCheckPacket, ptr %30, align 8, !tbaa !23
  %31 = getelementptr inbounds i8, ptr %9, i64 88
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %31, i8 0, i64 16, i1 false)
  %32 = call i64 @EfiMtftp4ReadFile(ptr noundef nonnull %0, ptr noundef nonnull %9)
  %33 = icmp eq i64 %32, -9223372036854775787
  %34 = load i64, ptr %22, align 8
  %spec.select = select i1 %33, i64 %34, i64 %32
  br label %35

35:                                               ; preds = %20, %8, %14
  %.0 = phi i64 [ -9223372036854775806, %14 ], [ -9223372036854775806, %8 ], [ %spec.select, %20 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %9) #3
  ret i64 %.0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !13, i64 16}
!16 = !{!17, !6, i64 16}
!17 = !{!"_EFI_MTFTP4_TOKEN", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!18 = !{!17, !6, i64 24}
!19 = !{!17, !6, i64 32}
!20 = !{!17, !10, i64 40}
!21 = !{!17, !6, i64 48}
!22 = !{!17, !6, i64 72}
!23 = !{!17, !6, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass