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

; 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._SOCK_INIT_DATA = type { i32, i8, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr }
%struct._SOCKET = type { i32, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, i8, i32, i8, i16, %struct.EFI_LOCK, %struct._SOCK_BUFFER, %struct._SOCK_BUFFER, i64, i8, i32, i32, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, [20 x i8], %union._NET_PROTOCOL, ptr, ptr, ptr }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._SOCK_BUFFER = type { i32, i32, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str.27 = external hidden unnamed_addr constant [48 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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @SockCreate(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @SockSetState(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @SockClone(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct._SOCK_INIT_DATA, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 96, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._SOCKET, ptr %7, i32 0, i32 15
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 3
  store i32 %9, ptr %10, align 8, !tbaa !17
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 2
  store ptr %11, ptr %12, align 8, !tbaa !19
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._SOCKET, ptr %13, i32 0, i32 8
  %15 = load i8, ptr %14, align 8, !tbaa !20
  %16 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 1
  store i8 %15, ptr %16, align 4, !tbaa !21
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._SOCKET, ptr %17, i32 0, i32 25
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  %20 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 12
  store ptr %19, ptr %20, align 8, !tbaa !23
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._SOCKET, ptr %21, i32 0, i32 7
  %23 = load i32, ptr %22, align 4, !tbaa !24
  %24 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 0
  store i32 %23, ptr %24, align 8, !tbaa !25
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._SOCKET, ptr %25, i32 0, i32 12
  %27 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !26
  %29 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 5
  store i32 %28, ptr %29, align 8, !tbaa !27
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._SOCKET, ptr %30, i32 0, i32 11
  %32 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !28
  %34 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 4
  store i32 %33, ptr %34, align 4, !tbaa !29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._SOCKET, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !30
  %38 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 13
  store ptr %37, ptr %38, align 8, !tbaa !31
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._SOCKET, ptr %39, i32 0, i32 27
  %41 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 6
  store ptr %40, ptr %41, align 8, !tbaa !32
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._SOCKET, ptr %42, i32 0, i32 28
  %44 = load ptr, ptr %43, align 8, !tbaa !33
  %45 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 7
  store ptr %44, ptr %45, align 8, !tbaa !34
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._SOCKET, ptr %46, i32 0, i32 29
  %48 = load ptr, ptr %47, align 8, !tbaa !35
  %49 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 8
  store ptr %48, ptr %49, align 8, !tbaa !36
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._SOCKET, ptr %50, i32 0, i32 30
  %52 = load ptr, ptr %51, align 8, !tbaa !37
  %53 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 9
  store ptr %52, ptr %53, align 8, !tbaa !38
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._SOCKET, ptr %54, i32 0, i32 26
  %56 = getelementptr inbounds [20 x i8], ptr %55, i64 0, i64 0
  %57 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 10
  store ptr %56, ptr %57, align 8, !tbaa !39
  %58 = getelementptr inbounds %struct._SOCK_INIT_DATA, ptr %5, i32 0, i32 11
  store i32 20, ptr %58, align 8, !tbaa !40
  %59 = call ptr @SockCreate(ptr noundef %5)
  store ptr %59, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = icmp eq ptr null, %60
  br i1 %61, label %62, label %77

62:                                               ; preds = %1
  br label %63

63:                                               ; preds = %62
  %64 = call zeroext i8 @DebugPrintEnabled()
  %65 = icmp ne i8 %64, 0
  br i1 %65, label %66, label %74

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %69 = icmp ne i8 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %67
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.27)
  br label %71

71:                                               ; preds = %70, %67
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73, %63
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %85

77:                                               ; preds = %1
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  call void @SockSetState(ptr noundef %78, i8 noundef zeroext 2)
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._SOCKET, ptr %79, i32 0, i32 6
  %81 = load i8, ptr %80, align 8, !tbaa !41
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._SOCKET, ptr %82, i32 0, i32 6
  store i8 %81, ptr %83, align 8, !tbaa !41
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %84, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %85

85:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 96, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %86 = load ptr, ptr %2, align 8
  ret ptr %86
}

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 = !{!10, !11, i64 140}
!10 = !{!"_SOCKET", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !7, i64 56, !11, i64 60, !7, i64 64, !13, i64 66, !14, i64 72, !16, i64 96, !16, i64 112, !15, i64 128, !7, i64 136, !11, i64 140, !11, i64 144, !6, i64 152, !12, i64 160, !12, i64 176, !12, i64 192, !12, i64 208, !12, i64 224, !6, i64 240, !6, i64 248, !6, i64 256, !7, i64 264, !7, i64 288, !6, i64 368, !6, i64 376, !6, i64 384}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !11, i64 16}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"_SOCK_BUFFER", !11, i64 0, !11, i64 4, !6, i64 8}
!17 = !{!18, !11, i64 16}
!18 = !{!"_SOCK_INIT_DATA", !11, i64 0, !7, i64 4, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 80, !6, i64 88}
!19 = !{!18, !6, i64 8}
!20 = !{!10, !7, i64 64}
!21 = !{!18, !7, i64 4}
!22 = !{!10, !6, i64 256}
!23 = !{!18, !6, i64 80}
!24 = !{!10, !11, i64 60}
!25 = !{!18, !11, i64 0}
!26 = !{!10, !11, i64 112}
!27 = !{!18, !11, i64 24}
!28 = !{!10, !11, i64 96}
!29 = !{!18, !11, i64 20}
!30 = !{!10, !6, i64 16}
!31 = !{!18, !6, i64 88}
!32 = !{!18, !6, i64 32}
!33 = !{!10, !6, i64 368}
!34 = !{!18, !6, i64 40}
!35 = !{!10, !6, i64 376}
!36 = !{!18, !6, i64 48}
!37 = !{!10, !6, i64 384}
!38 = !{!18, !6, i64 56}
!39 = !{!18, !6, i64 64}
!40 = !{!18, !11, i64 72}
!41 = !{!10, !7, i64 56}


; 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._SOCK_INIT_DATA = type { i32, i8, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr }

@.str.27 = external hidden unnamed_addr constant [48 x i8], align 1

; 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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @SockCreate(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @SockSetState(ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @SockClone(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct._SOCK_INIT_DATA, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 140
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %4, ptr %5, align 8, !tbaa !16
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %0, ptr %6, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = load i8, ptr %7, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %8, ptr %9, align 4, !tbaa !20
  %10 = getelementptr inbounds i8, ptr %0, i64 256
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %2, i64 80
  store ptr %11, ptr %12, align 8, !tbaa !22
  %13 = getelementptr inbounds i8, ptr %0, i64 60
  %14 = load i32, ptr %13, align 4, !tbaa !23
  store i32 %14, ptr %2, align 8, !tbaa !24
  %15 = getelementptr inbounds i8, ptr %0, i64 112
  %16 = load i32, ptr %15, align 8, !tbaa !25
  %17 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 %16, ptr %17, align 8, !tbaa !26
  %18 = getelementptr inbounds i8, ptr %0, i64 96
  %19 = load i32, ptr %18, align 8, !tbaa !27
  %20 = getelementptr inbounds i8, ptr %2, i64 20
  store i32 %19, ptr %20, align 4, !tbaa !28
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !29
  %23 = getelementptr inbounds i8, ptr %2, i64 88
  store ptr %22, ptr %23, align 8, !tbaa !30
  %24 = getelementptr inbounds i8, ptr %0, i64 288
  %25 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr %24, ptr %25, align 8, !tbaa !31
  %26 = getelementptr inbounds i8, ptr %0, i64 368
  %27 = getelementptr inbounds i8, ptr %2, i64 40
  %28 = load <2 x ptr>, ptr %26, align 8, !tbaa !32
  store <2 x ptr> %28, ptr %27, align 8, !tbaa !32
  %29 = getelementptr inbounds i8, ptr %0, i64 384
  %30 = load ptr, ptr %29, align 8, !tbaa !33
  %31 = getelementptr inbounds i8, ptr %2, i64 56
  store ptr %30, ptr %31, align 8, !tbaa !34
  %32 = getelementptr inbounds i8, ptr %0, i64 264
  %33 = getelementptr inbounds i8, ptr %2, i64 64
  store ptr %32, ptr %33, align 8, !tbaa !35
  %34 = getelementptr inbounds i8, ptr %2, i64 72
  store i32 20, ptr %34, align 8, !tbaa !36
  %35 = call ptr @SockCreate(ptr noundef nonnull %2)
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %42

37:                                               ; preds = %1
  %38 = call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %38, 0
  br i1 %.not, label %46, label %39

39:                                               ; preds = %37
  %40 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not20 = icmp eq i8 %40, 0
  br i1 %.not20, label %46, label %41

41:                                               ; preds = %39
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.27) #3
  br label %46

42:                                               ; preds = %1
  call void @SockSetState(ptr noundef nonnull %35, i8 noundef zeroext 2)
  %43 = getelementptr inbounds i8, ptr %0, i64 56
  %44 = load i8, ptr %43, align 8, !tbaa !37
  %45 = getelementptr inbounds i8, ptr %35, i64 56
  store i8 %44, ptr %45, align 8, !tbaa !37
  br label %46

46:                                               ; preds = %37, %41, %39, %42
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %2) #3
  ret ptr %35
}

attributes #0 = { mustprogress 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, !7, i64 140}
!6 = !{!"_SOCKET", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !8, i64 56, !7, i64 60, !8, i64 64, !12, i64 66, !13, i64 72, !15, i64 96, !15, i64 112, !14, i64 128, !8, i64 136, !7, i64 140, !7, i64 144, !10, i64 152, !11, i64 160, !11, i64 176, !11, i64 192, !11, i64 208, !11, i64 224, !10, i64 240, !10, i64 248, !10, i64 256, !8, i64 264, !8, i64 288, !10, i64 368, !10, i64 376, !10, i64 384}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 8, !7, i64 16}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"_SOCK_BUFFER", !7, i64 0, !7, i64 4, !10, i64 8}
!16 = !{!17, !7, i64 16}
!17 = !{!"_SOCK_INIT_DATA", !7, i64 0, !8, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !10, i64 88}
!18 = !{!17, !10, i64 8}
!19 = !{!6, !8, i64 64}
!20 = !{!17, !8, i64 4}
!21 = !{!6, !10, i64 256}
!22 = !{!17, !10, i64 80}
!23 = !{!6, !7, i64 60}
!24 = !{!17, !7, i64 0}
!25 = !{!6, !7, i64 112}
!26 = !{!17, !7, i64 24}
!27 = !{!6, !7, i64 96}
!28 = !{!17, !7, i64 20}
!29 = !{!6, !10, i64 16}
!30 = !{!17, !10, i64 88}
!31 = !{!17, !10, i64 32}
!32 = !{!10, !10, i64 0}
!33 = !{!6, !10, i64 384}
!34 = !{!17, !10, i64 56}
!35 = !{!17, !10, i64 64}
!36 = !{!17, !7, i64 72}
!37 = !{!6, !8, i64 56}


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