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

; 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_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct._ISCSI_CONNECTION = type { i32, %struct._LIST_ENTRY, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, i8, i16, i32, %struct.NET_BUF_QUEUE, i8, %struct.TCP_IO, i32, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }
%struct.TCP_IO = type { i8, ptr, ptr, ptr, %union.TCP_IO_PROTOCOL, %union.TCP_IO_PROTOCOL, %union.TCP_IO_CONNECTION_TOKEN, %union.TCP_IO_IO_TOKEN, %union.TCP_IO_IO_TOKEN, %union.TCP_IO_CLOSE_TOKEN, %union.TCP_IO_LISTEN_TOKEN, i8, i8, i8, i8, i8 }
%union.TCP_IO_PROTOCOL = type { ptr }
%union.TCP_IO_CONNECTION_TOKEN = type { %struct.EFI_TCP4_CONNECTION_TOKEN }
%struct.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%union.TCP_IO_IO_TOKEN = type { %struct.EFI_TCP4_IO_TOKEN }
%struct.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon.0 }
%union.anon.0 = type { ptr }
%union.TCP_IO_CLOSE_TOKEN = type { %struct.EFI_TCP4_CLOSE_TOKEN }
%struct.EFI_TCP4_CLOSE_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, i8 }
%union.TCP_IO_LISTEN_TOKEN = type { %struct.EFI_TCP4_LISTEN_TOKEN }
%struct.EFI_TCP4_LISTEN_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, ptr }

@gBS = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiConnLogin(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr @gBS, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %8, i32 0, i32 9
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = load i16, ptr %5, align 2, !tbaa !9
  %15 = zext i16 %14 to i32
  %16 = mul i32 %15, 10000
  %17 = zext i32 %16 to i64
  %18 = call i64 %10(ptr noundef %13, i32 noundef 2, i64 noundef %17)
  store i64 %18, ptr %6, align 8, !tbaa !21
  %19 = load i64, ptr %6, align 8, !tbaa !21
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %2
  %22 = load i64, ptr %6, align 8, !tbaa !21
  store i64 %22, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %65

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %24, i32 0, i32 16
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = call i64 @TcpIoConnect(ptr noundef %25, ptr noundef %28)
  store i64 %29, ptr %6, align 8, !tbaa !21
  %30 = load ptr, ptr @gBS, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %30, i32 0, i32 9
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = call i64 %32(ptr noundef %35, i32 noundef 0, i64 noundef 0)
  %37 = load i64, ptr %6, align 8, !tbaa !21
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %23
  %40 = load i64, ptr %6, align 8, !tbaa !21
  store i64 %40, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %65

41:                                               ; preds = %23
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %42, i32 0, i32 4
  store i8 2, ptr %43, align 8, !tbaa !22
  br label %44

44:                                               ; preds = %57, %41
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call i64 @IScsiSendLoginReq(ptr noundef %45)
  store i64 %46, ptr %6, align 8, !tbaa !21
  %47 = load i64, ptr %6, align 8, !tbaa !21
  %48 = icmp slt i64 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  br label %63

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call i64 @IScsiReceiveLoginRsp(ptr noundef %51)
  store i64 %52, ptr %6, align 8, !tbaa !21
  %53 = load i64, ptr %6, align 8, !tbaa !21
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %50
  br label %63

56:                                               ; preds = %50
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._ISCSI_CONNECTION, ptr %58, i32 0, i32 5
  %60 = load i8, ptr %59, align 1, !tbaa !23
  %61 = zext i8 %60 to i32
  %62 = icmp ne i32 %61, 3
  br i1 %62, label %44, label %63, !llvm.loop !24

63:                                               ; preds = %57, %55, %49
  %64 = load i64, ptr %6, align 8, !tbaa !21
  store i64 %64, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %63, %39, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %66 = load i64, ptr %3, align 8
  ret i64 %66
}

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

declare i64 @TcpIoConnect(ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 88}
!12 = !{!"", !13, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!13 = !{!"", !14, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 24}
!17 = !{!"_ISCSI_CONNECTION", !15, i64 0, !18, 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, !7, i64 47, !10, i64 48, !15, i64 52, !19, i64 56, !7, i64 112, !20, i64 120, !15, i64 288, !15, i64 292, !15, i64 296}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"", !15, i64 0, !14, i64 8, !18, i64 16, !18, i64 32, !15, i64 48, !15, i64 52}
!20 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 64, !7, i64 88, !7, i64 112, !7, i64 136, !7, i64 160, !7, i64 161, !7, i64 162, !7, i64 163, !7, i64 164}
!21 = !{!14, !14, i64 0}
!22 = !{!17, !7, i64 40}
!23 = !{!17, !7, i64 41}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiConnLogin(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @gBS, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 88
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = zext i16 %1 to i64
  %9 = mul nuw nsw i64 %8, 10000
  %10 = tail call i64 %5(ptr noundef %7, i32 noundef 2, i64 noundef %9) #2
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 120
  %14 = load ptr, ptr %6, align 8, !tbaa !14
  %15 = tail call i64 @TcpIoConnect(ptr noundef nonnull %13, ptr noundef %14) #2
  %16 = load ptr, ptr @gBS, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 88
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !14
  %20 = tail call i64 %18(ptr noundef %19, i32 noundef 0, i64 noundef 0) #2
  %21 = icmp slt i64 %15, 0
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %12
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 2, ptr %23, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %0, i64 41
  br label %25

25:                                               ; preds = %31, %22
  %26 = tail call i64 @IScsiSendLoginReq(ptr noundef nonnull %0)
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %.loopexit, label %28

28:                                               ; preds = %25
  %29 = tail call i64 @IScsiReceiveLoginRsp(ptr noundef nonnull %0)
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %.loopexit, label %31

31:                                               ; preds = %28
  %32 = load i8, ptr %24, align 1, !tbaa !21
  %.not = icmp eq i8 %32, 3
  br i1 %.not, label %.loopexit, label %25, !llvm.loop !22

.loopexit:                                        ; preds = %31, %25, %28, %12, %2
  %.016 = phi i64 [ %10, %2 ], [ %15, %12 ], [ %29, %31 ], [ %29, %28 ], [ %26, %25 ]
  ret i64 %.016
}

declare i64 @TcpIoConnect(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @IScsiSendLoginReq(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @IScsiReceiveLoginRsp(ptr noundef) local_unnamed_addr #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 88}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 24}
!15 = !{!"_ISCSI_CONNECTION", !13, i64 0, !16, 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, !7, i64 47, !17, i64 48, !13, i64 52, !18, i64 56, !7, i64 112, !19, i64 120, !13, i64 288, !13, i64 292, !13, i64 296}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !13, i64 0, !12, i64 8, !16, i64 16, !16, i64 32, !13, i64 48, !13, i64 52}
!19 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 64, !7, i64 88, !7, i64 112, !7, i64 136, !7, i64 160, !7, i64 161, !7, i64 162, !7, i64 163, !7, i64 164}
!20 = !{!15, !7, i64 40}
!21 = !{!15, !7, i64 41}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass