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

; 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_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }
%struct._EFI_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct._EFI_COMPONENT_NAME2_PROTOCOL = type { ptr, ptr, ptr }

@mTcp4DriverBinding = external dso_local global %struct._EFI_DRIVER_BINDING_PROTOCOL, align 8
@.str = external hidden unnamed_addr constant [153 x i8], align 1
@gTcp4ComponentName = external global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@gTcp4ComponentName2 = external global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@.str.3 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@mTcpGlobalIss = external global i32, align 4
@mTcp4RandomPort = external dso_local global i16, align 2

; 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 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4DriverEntryPoint(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @EfiLibInstallDriverBindingComponentName2(ptr noundef %7, ptr noundef %8, ptr noundef @mTcp4DriverBinding, ptr noundef %9, ptr noundef @gTcp4ComponentName, ptr noundef @gTcp4ComponentName2)
  store i64 %10, ptr %5, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %2
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %34

14:                                               ; preds = %11
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = icmp slt i64 %15, 0
  br i1 %16, label %17, label %33

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = call zeroext i8 @DebugPrintEnabled()
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %30

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  %23 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load i64, ptr %5, align 8, !tbaa !9
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i64 noundef %26)
  br label %27

27:                                               ; preds = %25, %22
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29, %18
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  call void @DebugAssert(ptr noundef @.str, i64 noundef 209, ptr noundef @.str.4)
  br label %33

33:                                               ; preds = %32, %14
  br label %34

34:                                               ; preds = %33, %11
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = call i32 @NetRandomInitSeed()
  store i32 %37, ptr %6, align 4, !tbaa !11
  %38 = load i32, ptr %6, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = mul i64 %39, 1103515245
  %41 = add i64 %40, 12345
  %42 = trunc i64 %41 to i32
  %43 = zext i32 %42 to i64
  %44 = urem i64 %43, 4294967295
  %45 = load i32, ptr @mTcpGlobalIss, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = urem i64 %44, %46
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr @mTcpGlobalIss, align 4, !tbaa !11
  %49 = load i32, ptr %6, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = mul i64 %50, 1103515245
  %52 = add i64 %51, 12345
  %53 = trunc i64 %52 to i32
  %54 = zext i32 %53 to i64
  %55 = urem i64 %54, 4294967295
  %56 = urem i64 %55, 1024
  %57 = trunc i64 %56 to i16
  %58 = zext i16 %57 to i32
  %59 = add nsw i32 1024, %58
  %60 = trunc i32 %59 to i16
  store i16 %60, ptr @mTcp4RandomPort, align 2, !tbaa !13
  %61 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %61
}

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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

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

declare i32 @NetRandomInitSeed() #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !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"

%struct._EFI_DRIVER_BINDING_PROTOCOL = type { ptr, ptr, ptr, i32, ptr, ptr }
%struct._EFI_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct._EFI_COMPONENT_NAME2_PROTOCOL = type { ptr, ptr, ptr }

@mTcp4DriverBinding = external dso_local global %struct._EFI_DRIVER_BINDING_PROTOCOL, align 8
@.str = external hidden unnamed_addr constant [153 x i8], align 1
@gTcp4ComponentName = external global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@gTcp4ComponentName2 = external global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@.str.3 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@mTcpGlobalIss = external local_unnamed_addr global i32, align 4
@mTcp4RandomPort = external dso_local local_unnamed_addr global i16, align 2

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4DriverEntryPoint(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i64 @EfiLibInstallDriverBindingComponentName2(ptr noundef %0, ptr noundef %1, ptr noundef nonnull @mTcp4DriverBinding, ptr noundef %0, ptr noundef nonnull @gTcp4ComponentName, ptr noundef nonnull @gTcp4ComponentName2) #2
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %5 = icmp ne i8 %4, 0
  %6 = icmp slt i64 %3, 0
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %7, label %13

7:                                                ; preds = %2
  %8 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %12, label %9

9:                                                ; preds = %7
  %10 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not8 = icmp eq i8 %10, 0
  br i1 %.not8, label %12, label %11

11:                                               ; preds = %9
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i64 noundef %3) #2
  br label %12

12:                                               ; preds = %9, %11, %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 209, ptr noundef nonnull @.str.4) #2
  br label %13

13:                                               ; preds = %12, %2
  %14 = tail call i32 @NetRandomInitSeed() #2
  %.fr = freeze i32 %14
  %15 = mul i32 %.fr, 1103515245
  %16 = add i32 %15, 12345
  %.not10 = icmp eq i32 %16, -1
  %17 = add nsw i32 %15, 12346
  %18 = select i1 %.not10, i32 %17, i32 %16
  %19 = load i32, ptr @mTcpGlobalIss, align 4, !tbaa !5
  %20 = urem i32 %18, %19
  store i32 %20, ptr @mTcpGlobalIss, align 4, !tbaa !5
  %21 = trunc i32 %18 to i16
  %22 = and i16 %21, 1023
  %23 = or disjoint i16 %22, 1024
  store i16 %23, ptr @mTcp4RandomPort, align 2, !tbaa !9
  ret i64 %3
}

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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

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

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

declare i32 @NetRandomInitSeed() 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}


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