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

; 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_DHCP6_PACKET = type <{ i32, i32, %struct.anon }>
%struct.anon = type <{ %struct.EFI_DHCP6_HEADER, [1 x i8] }>
%struct.EFI_DHCP6_HEADER = type { i32 }
%struct._DHCP6_INSTANCE = type { i32, ptr, ptr, %struct._LIST_ENTRY, %struct._EFI_DHCP6_PROTOCOL, ptr, ptr, ptr, %struct._DHCP6_IA_CB, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, i8, ptr, i64, i8, i8, i64 }
%struct._EFI_DHCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._DHCP6_IA_CB = type { ptr, i32, i32, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_DHCP6_CONFIG_DATA = type { ptr, ptr, i32, ptr, %struct.EFI_DHCP6_IA_DESCRIPTOR, ptr, i8, i8, ptr }
%struct.EFI_DHCP6_IA_DESCRIPTOR = type { i16, 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 @Dhcp6SeekIaOption(ptr noundef, i32 noundef, ptr noundef) #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #1

declare zeroext i16 @ReadUnaligned16(ptr noundef) #1

declare ptr @Dhcp6SeekOption(ptr noundef, i32 noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Dhcp6SeekStsOption(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 ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = 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 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %12, i32 0, i32 2
  %14 = getelementptr inbounds %struct.anon, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds [1 x i8], ptr %14, i64 0, i64 0
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 1, !tbaa !9
  %19 = sub i32 %18, 4
  %20 = call ptr @Dhcp6SeekOption(ptr noundef %15, i32 noundef %19, i16 noundef zeroext 13)
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %20, ptr %21, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %36

25:                                               ; preds = %3
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = call zeroext i16 @ReadUnaligned16(ptr noundef %28)
  %30 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %29)
  store i16 %30, ptr %10, align 2, !tbaa !14
  %31 = load i16, ptr %10, align 2, !tbaa !14
  %32 = zext i16 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %25
  store i64 -9223372036854775801, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

35:                                               ; preds = %25
  br label %36

36:                                               ; preds = %35, %3
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds [1 x i8], ptr %39, i64 0, i64 0
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 1, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = sub i64 %44, 4
  %46 = trunc i64 %45 to i32
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %47, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %49, i32 0, i32 4
  %51 = call ptr @Dhcp6SeekIaOption(ptr noundef %40, i32 noundef %46, ptr noundef %50)
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %51, ptr %52, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %36
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

57:                                               ; preds = %36
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %58, i32 0, i32 6
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %60, i32 0, i32 4
  %62 = getelementptr inbounds %struct.EFI_DHCP6_IA_DESCRIPTOR, ptr %61, i32 0, i32 0
  %63 = load i16, ptr %62, align 8, !tbaa !22
  %64 = zext i16 %63 to i32
  %65 = icmp eq i32 %64, 3
  br i1 %65, label %66, label %78

66:                                               ; preds = %57
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 16
  store ptr %69, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 2
  %73 = call zeroext i16 @ReadUnaligned16(ptr noundef %72)
  %74 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %73)
  %75 = zext i16 %74 to i32
  %76 = sub nsw i32 %75, 12
  %77 = trunc i32 %76 to i16
  store i16 %77, ptr %9, align 2, !tbaa !14
  br label %90

78:                                               ; preds = %57
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 8
  store ptr %81, ptr %8, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 2
  %85 = call zeroext i16 @ReadUnaligned16(ptr noundef %84)
  %86 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %85)
  %87 = zext i16 %86 to i32
  %88 = sub nsw i32 %87, 4
  %89 = trunc i32 %88 to i16
  store i16 %89, ptr %9, align 2, !tbaa !14
  br label %90

90:                                               ; preds = %78, %66
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load i16, ptr %9, align 2, !tbaa !14
  %93 = zext i16 %92 to i32
  %94 = call ptr @Dhcp6SeekOption(ptr noundef %91, i32 noundef %93, i16 noundef zeroext 13)
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %94, ptr %95, align 8, !tbaa !5
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %110

99:                                               ; preds = %90
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i64 4
  %103 = call zeroext i16 @ReadUnaligned16(ptr noundef %102)
  %104 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %103)
  store i16 %104, ptr %10, align 2, !tbaa !14
  %105 = load i16, ptr %10, align 2, !tbaa !14
  %106 = zext i16 %105 to i32
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %108, label %109

108:                                              ; preds = %99
  store i64 -9223372036854775801, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

109:                                              ; preds = %99
  br label %110

110:                                              ; preds = %109, %90
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

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

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 4}
!10 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !7, i64 4}
!13 = !{!"", !11, i64 0, !11, i64 1}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !6, i64 120}
!17 = !{!"_DHCP6_INSTANCE", !11, i64 0, !6, i64 8, !6, i64 16, !18, i64 24, !19, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !20, i64 136, !18, i64 160, !18, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !21, i64 216, !7, i64 224, !7, i64 225, !21, i64 232}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"_EFI_DHCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!20 = !{!"_DHCP6_IA_CB", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!21 = !{!"long long", !7, i64 0}
!22 = !{!23, !15, i64 32}
!23 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !24, i64 32, !6, i64 40, !7, i64 48, !7, i64 49, !6, i64 56}
!24 = !{!"", !15, i64 0, !11, i64 4}


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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i16 @ReadUnaligned16(ptr noundef) local_unnamed_addr #0

declare ptr @Dhcp6SeekOption(ptr noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, 1) i64 @Dhcp6SeekStsOption(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 12
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 1, !tbaa !5
  %7 = add i32 %6, -4
  %8 = tail call ptr @Dhcp6SeekOption(ptr noundef nonnull %4, i32 noundef %7, i16 noundef zeroext 13) #2
  store ptr %8, ptr %2, align 8, !tbaa !12
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %13, label %9

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  %11 = tail call zeroext i16 @ReadUnaligned16(ptr noundef nonnull %10) #2
  %12 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %11) #2
  %.not27 = icmp eq i16 %12, 0
  br i1 %.not27, label %13, label %38

13:                                               ; preds = %9, %3
  %14 = load i32, ptr %5, align 1, !tbaa !5
  %15 = add i32 %14, -4
  %16 = getelementptr inbounds i8, ptr %0, i64 120
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 32
  %19 = tail call ptr @Dhcp6SeekIaOption(ptr noundef nonnull %4, i32 noundef %15, ptr noundef nonnull %18) #2
  store ptr %19, ptr %2, align 8, !tbaa !12
  %20 = icmp eq ptr %19, null
  br i1 %20, label %38, label %21

21:                                               ; preds = %13
  %22 = load ptr, ptr %16, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %22, i64 32
  %24 = load i16, ptr %23, align 8, !tbaa !20
  %25 = icmp eq i16 %24, 3
  %26 = getelementptr inbounds i8, ptr %19, i64 2
  %27 = tail call zeroext i16 @ReadUnaligned16(ptr noundef nonnull %26) #2
  %28 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %27) #2
  %. = select i1 %25, i64 16, i64 8
  %.31 = select i1 %25, i16 -12, i16 -4
  %29 = getelementptr inbounds i8, ptr %19, i64 %.
  %30 = add i16 %28, %.31
  %31 = zext i16 %30 to i32
  %32 = tail call ptr @Dhcp6SeekOption(ptr noundef nonnull %29, i32 noundef %31, i16 noundef zeroext 13) #2
  store ptr %32, ptr %2, align 8, !tbaa !12
  %.not28 = icmp eq ptr %32, null
  br i1 %.not28, label %37, label %33

33:                                               ; preds = %21
  %34 = getelementptr inbounds i8, ptr %32, i64 4
  %35 = tail call zeroext i16 @ReadUnaligned16(ptr noundef nonnull %34) #2
  %36 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %35) #2
  %.not29 = icmp eq i16 %36, 0
  br i1 %.not29, label %37, label %38

37:                                               ; preds = %33, %21
  br label %38

38:                                               ; preds = %33, %13, %9, %37
  %.023 = phi i64 [ 0, %37 ], [ -9223372036854775801, %9 ], [ 0, %13 ], [ -9223372036854775801, %33 ]
  ret i64 %.023
}

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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !8, i64 4}
!11 = !{!"", !7, i64 0, !7, i64 1}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!15, !13, i64 120}
!15 = !{!"_DHCP6_INSTANCE", !7, i64 0, !13, i64 8, !13, i64 16, !16, i64 24, !17, i64 40, !13, i64 112, !13, i64 120, !13, i64 128, !18, i64 136, !16, i64 160, !16, i64 176, !13, i64 192, !8, i64 200, !13, i64 208, !19, i64 216, !8, i64 224, !8, i64 225, !19, i64 232}
!16 = !{!"_LIST_ENTRY", !13, i64 0, !13, i64 8}
!17 = !{!"_EFI_DHCP6_PROTOCOL", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64}
!18 = !{!"_DHCP6_IA_CB", !13, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!19 = !{!"long long", !8, i64 0}
!20 = !{!21, !23, i64 32}
!21 = !{!"", !13, i64 0, !13, i64 8, !7, i64 16, !13, i64 24, !22, i64 32, !13, i64 40, !8, i64 48, !8, i64 49, !13, i64 56}
!22 = !{!"", !23, i64 0, !7, i64 4}
!23 = !{!"short", !8, i64 0}


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