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

; 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_LOGIN_REQUEST = type { i8, i8, i8, i8, i8, [3 x i8], [6 x i8], i16, i32, i16, i16, i32, i32, [4 x i32] }
%struct._ISCSI_BASIC_HEADER = type { i8, i8, i16, i8, [3 x i8], [8 x i8], i32, [7 x i32] }

; 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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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

19:                                               ; preds = %3
  store i64 -9223372036854775784, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %109

20:                                               ; preds = %3
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._ISCSI_LOGIN_REQUEST, ptr %21, i32 0, i32 5
  %23 = getelementptr inbounds [3 x i8], ptr %22, i64 0, i64 0
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = shl i32 %25, 16
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._ISCSI_LOGIN_REQUEST, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds [3 x i8], ptr %28, i64 0, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = shl i32 %31, 8
  %33 = or i32 %26, %32
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._ISCSI_LOGIN_REQUEST, ptr %34, i32 0, i32 5
  %36 = getelementptr inbounds [3 x i8], ptr %35, i64 0, i64 2
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = or i32 %33, %38
  store i32 %39, ptr %8, align 4, !tbaa !10
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call i64 @AsciiStrLen(ptr noundef %40)
  %42 = trunc i64 %41 to i32
  store i32 %42, ptr %9, align 4, !tbaa !10
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i64 @AsciiStrLen(ptr noundef %43)
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr %10, align 4, !tbaa !10
  %46 = load i32, ptr %9, align 4, !tbaa !10
  %47 = add i32 %46, 1
  %48 = load i32, ptr %10, align 4, !tbaa !10
  %49 = add i32 %47, %48
  %50 = add i32 %49, 1
  store i32 %50, ptr %11, align 4, !tbaa !10
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i32, ptr %11, align 4, !tbaa !10
  %53 = call ptr @NetbufAllocSpace(ptr noundef %51, i32 noundef %52, i8 noundef zeroext 0)
  store ptr %53, ptr %13, align 8, !tbaa !5
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %20
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %109

57:                                               ; preds = %20
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !10
  %61 = zext i32 %60 to i64
  %62 = call ptr @CopyMem(ptr noundef %58, ptr noundef %59, i64 noundef %61)
  %63 = load i32, ptr %9, align 4, !tbaa !10
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  %65 = zext i32 %63 to i64
  %66 = getelementptr inbounds i8, ptr %64, i64 %65
  store ptr %66, ptr %13, align 8, !tbaa !5
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 61, ptr %67, align 1, !tbaa !9
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %13, align 8, !tbaa !5
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load i32, ptr %10, align 4, !tbaa !10
  %73 = zext i32 %72 to i64
  %74 = call ptr @CopyMem(ptr noundef %70, ptr noundef %71, i64 noundef %73)
  %75 = load i32, ptr %10, align 4, !tbaa !10
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = zext i32 %75 to i64
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  store ptr %78, ptr %13, align 8, !tbaa !5
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %79, align 1, !tbaa !9
  br label %80

80:                                               ; preds = %57
  %81 = load i32, ptr %8, align 4, !tbaa !10
  %82 = load i32, ptr %11, align 4, !tbaa !10
  %83 = add i32 %81, %82
  %84 = lshr i32 %83, 16
  %85 = and i32 %84, 255
  %86 = trunc i32 %85 to i8
  %87 = load ptr, ptr %12, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._ISCSI_BASIC_HEADER, ptr %87, i32 0, i32 4
  %89 = getelementptr inbounds [3 x i8], ptr %88, i64 0, i64 0
  store i8 %86, ptr %89, align 1, !tbaa !9
  %90 = load i32, ptr %8, align 4, !tbaa !10
  %91 = load i32, ptr %11, align 4, !tbaa !10
  %92 = add i32 %90, %91
  %93 = lshr i32 %92, 8
  %94 = and i32 %93, 255
  %95 = trunc i32 %94 to i8
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._ISCSI_BASIC_HEADER, ptr %96, i32 0, i32 4
  %98 = getelementptr inbounds [3 x i8], ptr %97, i64 0, i64 1
  store i8 %95, ptr %98, align 1, !tbaa !9
  %99 = load i32, ptr %8, align 4, !tbaa !10
  %100 = load i32, ptr %11, align 4, !tbaa !10
  %101 = add i32 %99, %100
  %102 = and i32 %101, 255
  %103 = trunc i32 %102 to i8
  %104 = load ptr, ptr %12, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct._ISCSI_BASIC_HEADER, ptr %104, i32 0, i32 4
  %106 = getelementptr inbounds [3 x i8], ptr %105, i64 0, i64 2
  store i8 %103, ptr %106, align 1, !tbaa !9
  br label %107

107:                                              ; preds = %80
  br label %108

108:                                              ; preds = %107
  store i64 0, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %109

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

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

declare i64 @AsciiStrLen(ptr noundef) #1

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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"

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @IScsiAddKeyValuePair(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call ptr @NetbufGetByte(ptr noundef %0, i32 noundef 0, ptr noundef null) #2
  %5 = icmp eq ptr %4, null
  br i1 %5, label %42, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %4, i64 5
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %4, i64 6
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %4, i64 7
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = tail call i64 @AsciiStrLen(ptr noundef %1) #2
  %14 = trunc i64 %13 to i32
  %15 = tail call i64 @AsciiStrLen(ptr noundef %2) #2
  %16 = trunc i64 %15 to i32
  %17 = add i32 %14, 2
  %18 = add i32 %17, %16
  %19 = tail call ptr @NetbufAllocSpace(ptr noundef %0, i32 noundef %18, i8 noundef zeroext 0) #2
  %20 = icmp eq ptr %19, null
  br i1 %20, label %42, label %21

21:                                               ; preds = %6
  %22 = zext i8 %8 to i32
  %23 = shl nuw nsw i32 %22, 16
  %24 = zext i8 %10 to i32
  %25 = shl nuw nsw i32 %24, 8
  %26 = or disjoint i32 %25, %23
  %27 = zext i8 %12 to i32
  %28 = or disjoint i32 %26, %27
  %29 = and i64 %13, 4294967295
  %30 = tail call ptr @CopyMem(ptr noundef nonnull %19, ptr noundef %1, i64 noundef %29) #2
  %31 = getelementptr inbounds i8, ptr %19, i64 %29
  store i8 61, ptr %31, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 1
  %33 = and i64 %15, 4294967295
  %34 = tail call ptr @CopyMem(ptr noundef nonnull %32, ptr noundef %2, i64 noundef %33) #2
  %35 = getelementptr inbounds i8, ptr %32, i64 %33
  store i8 0, ptr %35, align 1, !tbaa !5
  %36 = add i32 %18, %28
  %37 = lshr i32 %36, 16
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %7, align 1, !tbaa !5
  %39 = lshr i32 %36, 8
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %9, align 1, !tbaa !5
  %41 = trunc i32 %36 to i8
  store i8 %41, ptr %11, align 1, !tbaa !5
  br label %42

42:                                               ; preds = %6, %3, %21
  %.0 = phi i64 [ 0, %21 ], [ -9223372036854775784, %3 ], [ -9223372036854775799, %6 ]
  ret i64 %.0
}

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

declare i64 @AsciiStrLen(ptr noundef) local_unnamed_addr #0

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass