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

; 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_SESSION = type { i32, %struct._ISCSI_SESSION_CONFIG_DATA, %struct._ISCSI_CHAP_AUTH_DATA, [224 x i8], i64, i8, [6 x i8], i16, i32, i32, i32, i32, i16, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, i16, i32, i8, i8, i32, i32, i32, i32, i16, i8, i8, i8 }
%struct._ISCSI_SESSION_CONFIG_DATA = type { %struct.ISCSI_SESSION_CONFIG_NVDATA, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS }
%struct.ISCSI_SESSION_CONFIG_NVDATA = type <{ i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, [224 x i8], %struct.EFI_IPv4_ADDRESS, i16, [8 x i8], [6 x i8] }>
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._ISCSI_CHAP_AUTH_DATA = type { %struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA, i32, [1024 x i8], i32, [16 x i8], i32, [1024 x i8], i32 }
%struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA = type { i8, [127 x i8], [17 x i8], [127 x i8], [17 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; 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
define dso_local i64 @IScsiUpdateTargetAddress(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = call ptr @IScsiBuildKeyValueList(ptr noundef %14, i32 noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %3
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %111

20:                                               ; preds = %3
  store i64 -9223372036854775794, ptr %11, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %106, %82, %68, %40, %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @IScsiGetValueByKeyFromList(ptr noundef %23, ptr noundef @.str.3)
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %108

28:                                               ; preds = %22
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 0
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = sext i8 %31 to i32
  %33 = icmp sle i32 48, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %28
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = sext i8 %37 to i32
  %39 = icmp sle i32 %38, 57
  br i1 %39, label %41, label %40

40:                                               ; preds = %34, %28
  br label %21

41:                                               ; preds = %34
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %42, ptr %10, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %60, %41
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %43
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load i8, ptr %49, align 1, !tbaa !13
  %51 = sext i8 %50 to i32
  %52 = icmp ne i32 %51, 58
  br i1 %52, label %53, label %58

53:                                               ; preds = %48
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i8, ptr %54, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  %57 = icmp ne i32 %56, 44
  br label %58

58:                                               ; preds = %53, %48, %43
  %59 = phi i1 [ false, %48 ], [ false, %43 ], [ %57, %53 ]
  br i1 %59, label %60, label %63

60:                                               ; preds = %58
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %9, align 8, !tbaa !5
  br label %43, !llvm.loop !14

63:                                               ; preds = %58
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !13
  %66 = sext i8 %65 to i32
  %67 = icmp eq i32 %66, 44
  br i1 %67, label %68, label %69

68:                                               ; preds = %63
  br label %21

69:                                               ; preds = %63
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load i8, ptr %70, align 1, !tbaa !13
  %72 = sext i8 %71 to i32
  %73 = icmp eq i32 %72, 58
  br i1 %73, label %74, label %91

74:                                               ; preds = %69
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %75, align 1, !tbaa !13
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = call i64 @AsciiStrDecimalToUintn(ptr noundef %78)
  store i64 %79, ptr %12, align 8, !tbaa !11
  %80 = load i64, ptr %12, align 8, !tbaa !11
  %81 = icmp ugt i64 %80, 65535
  br i1 %81, label %82, label %83

82:                                               ; preds = %74
  br label %21

83:                                               ; preds = %74
  %84 = load i64, ptr %12, align 8, !tbaa !11
  %85 = trunc i64 %84 to i16
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %86, i32 0, i32 1
  %88 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %87, i32 0, i32 0
  %89 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %88, i32 0, i32 8
  store i16 %85, ptr %89, align 1, !tbaa !16
  br label %90

90:                                               ; preds = %83
  br label %96

91:                                               ; preds = %69
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %92, i32 0, i32 1
  %94 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %93, i32 0, i32 0
  %95 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %94, i32 0, i32 8
  store i16 3260, ptr %95, align 1, !tbaa !16
  br label %96

96:                                               ; preds = %91, %90
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds %struct._ISCSI_SESSION_CONFIG_DATA, ptr %100, i32 0, i32 0
  %102 = getelementptr inbounds %struct.ISCSI_SESSION_CONFIG_NVDATA, ptr %101, i32 0, i32 7
  %103 = call i64 @IScsiAsciiStrToIp(ptr noundef %98, ptr noundef %102)
  store i64 %103, ptr %11, align 8, !tbaa !11
  %104 = load i64, ptr %11, align 8, !tbaa !11
  %105 = icmp slt i64 %104, 0
  br i1 %105, label %106, label %107

106:                                              ; preds = %97
  br label %21

107:                                              ; preds = %97
  br label %108

108:                                              ; preds = %107, %27
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  call void @IScsiFreeKeyValueList(ptr noundef %109)
  %110 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %110, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %111

111:                                              ; preds = %108, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %112 = load i64, ptr %4, align 8
  ret i64 %112
}

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

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

declare i64 @AsciiStrDecimalToUintn(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @IScsiFreeKeyValueList(ptr noundef) #1

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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !21, i64 247}
!17 = !{!"_ISCSI_SESSION", !10, i64 0, !18, i64 4, !22, i64 276, !7, i64 2648, !12, i64 2872, !7, i64 2880, !7, i64 2881, !21, i64 2888, !10, i64 2892, !10, i64 2896, !10, i64 2900, !10, i64 2904, !21, i64 2908, !24, i64 2912, !10, i64 2928, !24, i64 2936, !21, i64 2952, !10, i64 2956, !7, i64 2960, !7, i64 2961, !10, i64 2964, !10, i64 2968, !10, i64 2972, !10, i64 2976, !21, i64 2980, !7, i64 2982, !7, i64 2983, !7, i64 2984}
!18 = !{!"_ISCSI_SESSION_CONFIG_DATA", !19, i64 0, !20, i64 259, !20, i64 263, !20, i64 267}
!19 = !{!"", !7, i64 0, !7, i64 1, !20, i64 2, !20, i64 6, !20, i64 10, !7, i64 14, !7, i64 15, !20, i64 239, !21, i64 243, !7, i64 245, !7, i64 253}
!20 = !{!"", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!"_ISCSI_CHAP_AUTH_DATA", !23, i64 0, !10, i64 292, !7, i64 296, !10, i64 1320, !7, i64 1324, !10, i64 1340, !7, i64 1344, !10, i64 2368}
!23 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!24 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}


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

@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiUpdateTargetAddress(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @IScsiBuildKeyValueList(ptr noundef %1, i32 noundef %2)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %26, label %.preheader38

.preheader38:                                     ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 247
  %7 = getelementptr inbounds i8, ptr %0, i64 243
  br label %.outer

.outer:                                           ; preds = %.preheader38, %.loopexit
  %.026.ph = phi i64 [ -9223372036854775794, %.preheader38 ], [ %24, %.loopexit ]
  %8 = tail call ptr @IScsiGetValueByKeyFromList(ptr noundef nonnull %4, ptr noundef nonnull @.str.3)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.loopexit39, label %.lr.ph

.lr.ph:                                           ; preds = %.outer, %.backedge
  %10 = phi ptr [ %20, %.backedge ], [ %8, %.outer ]
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = add i8 %11, -48
  %or.cond = icmp ult i8 %12, 10
  br i1 %or.cond, label %.preheader, label %.backedge

.preheader:                                       ; preds = %.lr.ph, %14
  %13 = phi i8 [ %.pr, %14 ], [ %11, %.lr.ph ]
  %.027 = phi ptr [ %15, %14 ], [ %10, %.lr.ph ]
  switch i8 %13, label %14 [
    i8 44, label %.backedge
    i8 58, label %16
    i8 0, label %.loopexit
  ]

14:                                               ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %.027, i64 1
  %.pr = load i8, ptr %15, align 1, !tbaa !5
  br label %.preheader, !llvm.loop !8

16:                                               ; preds = %.preheader
  store i8 0, ptr %.027, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %.027, i64 1
  %18 = tail call i64 @AsciiStrDecimalToUintn(ptr noundef nonnull %17) #2
  %19 = icmp ugt i64 %18, 65535
  br i1 %19, label %.backedge, label %22

.backedge:                                        ; preds = %.preheader, %16, %.lr.ph
  %20 = tail call ptr @IScsiGetValueByKeyFromList(ptr noundef nonnull %4, ptr noundef nonnull @.str.3)
  %21 = icmp eq ptr %20, null
  br i1 %21, label %.loopexit39, label %.lr.ph

22:                                               ; preds = %16
  %23 = trunc nuw i64 %18 to i16
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %22
  %storemerge = phi i16 [ %23, %22 ], [ 3260, %.preheader ]
  store i16 %storemerge, ptr %6, align 1, !tbaa !10
  %24 = tail call i64 @IScsiAsciiStrToIp(ptr noundef nonnull %10, ptr noundef nonnull %7) #2
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %.outer, label %.loopexit39

.loopexit39:                                      ; preds = %.loopexit, %.outer, %.backedge
  %.1 = phi i64 [ %.026.ph, %.backedge ], [ %.026.ph, %.outer ], [ %24, %.loopexit ]
  tail call void @IScsiFreeKeyValueList(ptr noundef nonnull %4)
  br label %26

26:                                               ; preds = %3, %.loopexit39
  %.0 = phi i64 [ %.1, %.loopexit39 ], [ -9223372036854775799, %3 ]
  ret i64 %.0
}

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

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

declare i64 @AsciiStrDecimalToUintn(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @IScsiFreeKeyValueList(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !16, i64 247}
!11 = !{!"_ISCSI_SESSION", !12, i64 0, !13, i64 4, !17, i64 276, !6, i64 2648, !19, i64 2872, !6, i64 2880, !6, i64 2881, !16, i64 2888, !12, i64 2892, !12, i64 2896, !12, i64 2900, !12, i64 2904, !16, i64 2908, !20, i64 2912, !12, i64 2928, !20, i64 2936, !16, i64 2952, !12, i64 2956, !6, i64 2960, !6, i64 2961, !12, i64 2964, !12, i64 2968, !12, i64 2972, !12, i64 2976, !16, i64 2980, !6, i64 2982, !6, i64 2983, !6, i64 2984}
!12 = !{!"int", !6, i64 0}
!13 = !{!"_ISCSI_SESSION_CONFIG_DATA", !14, i64 0, !15, i64 259, !15, i64 263, !15, i64 267}
!14 = !{!"", !6, i64 0, !6, i64 1, !15, i64 2, !15, i64 6, !15, i64 10, !6, i64 14, !6, i64 15, !15, i64 239, !16, i64 243, !6, i64 245, !6, i64 253}
!15 = !{!"", !6, i64 0}
!16 = !{!"short", !6, i64 0}
!17 = !{!"_ISCSI_CHAP_AUTH_DATA", !18, i64 0, !12, i64 292, !6, i64 296, !12, i64 1320, !6, i64 1324, !12, i64 1340, !6, i64 1344, !12, i64 2368}
!18 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !6, i64 0, !6, i64 1, !6, i64 128, !6, i64 145, !6, i64 272}
!19 = !{!"long long", !6, i64 0}
!20 = !{!"_LIST_ENTRY", !21, i64 0, !21, i64 8}
!21 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass