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

; 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._ISCSI_NOP_IN = type { i8, [3 x i8], i8, [3 x i8], [8 x i8], i32, i32, i32, i32, i32, [3 x i32] }
%struct._ISCSI_TCB = type { %struct._LIST_ENTRY, i8, i32, i8, i8, i32, i32, ptr, i32, i32, i32, %struct._ISCSI_XFER_CONTEXT, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._ISCSI_XFER_CONTEXT = type { i32, i32, i32, i32 }
%struct._ISCSI_CONNECTION = type { i32, %struct._LIST_ENTRY, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i16, i32, %struct.NET_BUF_QUEUE, %struct._TCP4_IO, i32, i32, i32 }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }
%struct._TCP4_IO = type { ptr, ptr, ptr, ptr, %struct.EFI_TCP4_CONNECTION_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_CLOSE_TOKEN, i8, i8, i8, i8 }
%struct.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%struct.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon }
%union.anon = type { ptr }
%struct.EFI_TCP4_CLOSE_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, i8 }

; Function Attrs: nounwind uwtable
declare dso_local i64 @IScsiCheckSN(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @IScsiUpdateCmdSN(ptr noundef, i32 noundef, i32 noundef) #0

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

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

declare ptr @NetbufGetByte(ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @SwapBytes32(i32 noundef) #2

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

13:                                               ; preds = %2
  store i64 -9223372036854775784, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %75

14:                                               ; preds = %2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %15, i32 0, i32 7
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = call i32 @SwapBytes32(i32 noundef %17)
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %19, i32 0, i32 7
  store i32 %18, ptr %20, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %21, i32 0, i32 8
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = call i32 @SwapBytes32(i32 noundef %23)
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %25, i32 0, i32 8
  store i32 %24, ptr %26, align 4, !tbaa !12
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %27, i32 0, i32 9
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = call i32 @SwapBytes32(i32 noundef %29)
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %31, i32 0, i32 9
  store i32 %30, ptr %32, align 4, !tbaa !13
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %33, i32 0, i32 5
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %49

37:                                               ; preds = %14
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %38, i32 0, i32 7
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._ISCSI_TCB, ptr %41, i32 0, i32 12
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %43, i32 0, i32 12
  %45 = load i32, ptr %44, align 4, !tbaa !19
  %46 = icmp ne i32 %40, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %37
  store i64 -9223372036854775784, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %75

48:                                               ; preds = %37
  br label %63

49:                                               ; preds = %14
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._ISCSI_TCB, ptr %50, i32 0, i32 12
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %52, i32 0, i32 12
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %54, i32 0, i32 7
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = call i64 @IScsiCheckSN(ptr noundef %53, i32 noundef %56)
  store i64 %57, ptr %7, align 8, !tbaa !28
  %58 = load i64, ptr %7, align 8, !tbaa !28
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %49
  %61 = load i64, ptr %7, align 8, !tbaa !28
  store i64 %61, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %75

62:                                               ; preds = %49
  br label %63

63:                                               ; preds = %62, %48
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._ISCSI_TCB, ptr %64, i32 0, i32 12
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !29
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %69, i32 0, i32 9
  %71 = load i32, ptr %70, align 4, !tbaa !13
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._ISCSI_NOP_IN, ptr %72, i32 0, i32 8
  %74 = load i32, ptr %73, align 4, !tbaa !12
  call void @IScsiUpdateCmdSN(ptr noundef %68, i32 noundef %71, i32 noundef %74)
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %75

75:                                               ; preds = %63, %60, %47, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %76 = load i64, ptr %3, align 8
  ret i64 %76
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 24}
!10 = !{!"_ISCSI_NOP_IN", !7, i64 0, !7, i64 1, !7, i64 4, !7, i64 5, !7, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !7, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 28}
!13 = !{!10, !11, i64 32}
!14 = !{!10, !11, i64 16}
!15 = !{!16, !6, i64 80}
!16 = !{!"_ISCSI_TCB", !17, i64 0, !7, i64 16, !11, i64 20, !7, i64 24, !7, i64 25, !11, i64 28, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !18, i64 60, !6, i64 80}
!17 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!18 = !{!"_ISCSI_XFER_CONTEXT", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!19 = !{!20, !11, i64 52}
!20 = !{!"_ISCSI_CONNECTION", !11, i64 0, !17, i64 8, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !7, i64 46, !21, i64 48, !11, i64 52, !22, i64 56, !24, i64 112, !11, i64 240, !11, i64 244, !11, i64 248}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !11, i64 0, !23, i64 8, !17, i64 16, !17, i64 32, !11, i64 48, !11, i64 52}
!23 = !{!"long long", !7, i64 0}
!24 = !{!"_TCP4_IO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !25, i64 32, !27, i64 48, !27, i64 72, !27, i64 96, !7, i64 120, !7, i64 121, !7, i64 122, !7, i64 123}
!25 = !{!"", !26, i64 0}
!26 = !{!"", !6, i64 0, !23, i64 8}
!27 = !{!"", !26, i64 0, !7, i64 16}
!28 = !{!23, !23, i64 0}
!29 = !{!20, !6, i64 32}


; 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 @IScsiCheckSN(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @IScsiUpdateCmdSN(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @NetbufGetByte(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @IScsiOnNopInRcvd(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call ptr @NetbufGetByte(ptr noundef %0, i32 noundef 0, ptr noundef null) #2
  %4 = icmp eq ptr %3, null
  br i1 %4, label %37, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 24
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = tail call i32 @SwapBytes32(i32 noundef %7) #2
  store i32 %8, ptr %6, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %3, i64 28
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = tail call i32 @SwapBytes32(i32 noundef %10) #2
  store i32 %11, ptr %9, align 4, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %3, i64 32
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = tail call i32 @SwapBytes32(i32 noundef %13) #2
  store i32 %14, ptr %12, align 4, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %3, i64 16
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %24

18:                                               ; preds = %5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %21, i64 52
  %23 = load i32, ptr %22, align 4, !tbaa !18
  %.not = icmp eq i32 %19, %23
  br i1 %.not, label %31, label %37

24:                                               ; preds = %5
  %25 = getelementptr inbounds i8, ptr %1, i64 80
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %26, i64 52
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = tail call i64 @IScsiCheckSN(ptr noundef nonnull %27, i32 noundef %28)
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %37, label %._crit_edge

._crit_edge:                                      ; preds = %24
  %.pre = load ptr, ptr %25, align 8, !tbaa !13
  %.pre20 = load i32, ptr %12, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %._crit_edge, %18
  %32 = phi i32 [ %.pre20, %._crit_edge ], [ %14, %18 ]
  %33 = phi ptr [ %.pre, %._crit_edge ], [ %21, %18 ]
  %34 = getelementptr inbounds i8, ptr %33, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !27
  %36 = load i32, ptr %9, align 4, !tbaa !10
  tail call void @IScsiUpdateCmdSN(ptr noundef %35, i32 noundef %32, i32 noundef %36)
  br label %37

37:                                               ; preds = %24, %18, %2, %31
  %.0 = phi i64 [ 0, %31 ], [ -9223372036854775784, %2 ], [ -9223372036854775784, %18 ], [ %29, %24 ]
  ret i64 %.0
}

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, !9, i64 24}
!6 = !{!"_ISCSI_NOP_IN", !7, i64 0, !7, i64 1, !7, i64 4, !7, i64 5, !7, i64 8, !9, i64 16, !9, i64 20, !9, i64 24, !9, i64 28, !9, i64 32, !7, i64 36}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 28}
!11 = !{!6, !9, i64 32}
!12 = !{!6, !9, i64 16}
!13 = !{!14, !16, i64 80}
!14 = !{!"_ISCSI_TCB", !15, i64 0, !7, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !9, i64 28, !9, i64 32, !16, i64 40, !9, i64 48, !9, i64 52, !9, i64 56, !17, i64 60, !16, i64 80}
!15 = !{!"_LIST_ENTRY", !16, i64 0, !16, i64 8}
!16 = !{!"any pointer", !7, i64 0}
!17 = !{!"_ISCSI_XFER_CONTEXT", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12}
!18 = !{!19, !9, i64 52}
!19 = !{!"_ISCSI_CONNECTION", !9, i64 0, !15, i64 8, !16, i64 24, !16, i64 32, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !7, i64 46, !20, i64 48, !9, i64 52, !21, i64 56, !23, i64 112, !9, i64 240, !9, i64 244, !9, i64 248}
!20 = !{!"short", !7, i64 0}
!21 = !{!"", !9, i64 0, !22, i64 8, !15, i64 16, !15, i64 32, !9, i64 48, !9, i64 52}
!22 = !{!"long long", !7, i64 0}
!23 = !{!"_TCP4_IO", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !24, i64 32, !26, i64 48, !26, i64 72, !26, i64 96, !7, i64 120, !7, i64 121, !7, i64 122, !7, i64 123}
!24 = !{!"", !25, i64 0}
!25 = !{!"", !16, i64 0, !22, i64 8}
!26 = !{!"", !25, i64 0, !7, i64 16}
!27 = !{!19, !16, i64 32}


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