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

; 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.IP6_MLD_GROUP = type { %struct._LIST_ENTRY, i64, %struct.EFI_IPv6_ADDRESS, i32, i8, %struct.EFI_MAC_ADDRESS }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

; 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
declare dso_local i64 @Ip6SendMldReport(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6UpdateDelayTimer(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i16 %1, ptr %7, align 2, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load i16, ptr %7, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %16, i32 0, i32 3
  store i32 0, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call i64 @Ip6SendMldReport(ptr noundef %18, ptr noundef null, ptr noundef %19)
  store i64 %20, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %51

21:                                               ; preds = %4
  %22 = load i16, ptr %7, align 2, !tbaa !9
  %23 = zext i16 %22 to i32
  %24 = sdiv i32 %23, 1000
  store i32 %24, ptr %10, align 4, !tbaa !17
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %35, label %29

29:                                               ; preds = %21
  %30 = load i32, ptr %10, align 4, !tbaa !17
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp ult i32 %30, %33
  br i1 %34, label %35, label %50

35:                                               ; preds = %29, %21
  %36 = load i32, ptr %10, align 4, !tbaa !17
  %37 = zext i32 %36 to i64
  %38 = udiv i64 %37, 4294967295
  %39 = call i32 @NetRandomInitSeed()
  %40 = zext i32 %39 to i64
  %41 = mul i64 %40, 1103515245
  %42 = add i64 %41, 12345
  %43 = trunc i64 %42 to i32
  %44 = zext i32 %43 to i64
  %45 = urem i64 %44, 4294967295
  %46 = mul i64 %38, %45
  %47 = trunc i64 %46 to i32
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %48, i32 0, i32 3
  store i32 %47, ptr %49, align 8, !tbaa !11
  br label %50

50:                                               ; preds = %35, %29
  store i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %51

51:                                               ; preds = %50, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %52 = load i64, ptr %5, align 8
  ret i64 %52
}

declare i32 @NetRandomInitSeed() #2

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 = !{!"short", !7, i64 0}
!11 = !{!12, !16, i64 40}
!12 = !{!"", !13, i64 0, !14, i64 16, !15, i64 24, !16, i64 40, !7, i64 44, !15, i64 45}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, 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"

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6UpdateDelayTimer(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i16 %1, 0
  %6 = getelementptr inbounds i8, ptr %3, i64 40
  br i1 %5, label %7, label %9

7:                                                ; preds = %4
  store i32 0, ptr %6, align 8, !tbaa !5
  %8 = tail call i64 @Ip6SendMldReport(ptr noundef %0, ptr noundef null, ptr noundef %2)
  br label %18

9:                                                ; preds = %4
  %10 = load i32, ptr %6, align 8, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %16, label %12

12:                                               ; preds = %9
  %13 = udiv i16 %1, 1000
  %14 = zext nneg i16 %13 to i32
  %15 = icmp ugt i32 %10, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %12, %9
  %17 = tail call i32 @NetRandomInitSeed() #2
  store i32 0, ptr %6, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %12, %16, %7
  %.0 = phi i64 [ %8, %7 ], [ 0, %16 ], [ 0, %12 ]
  ret i64 %.0
}

declare i32 @NetRandomInitSeed() local_unnamed_addr #1

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, !13, i64 40}
!6 = !{!"", !7, i64 0, !11, i64 16, !12, i64 24, !13, i64 40, !9, i64 44, !12, i64 45}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!"", !9, i64 0}
!13 = !{!"int", !9, i64 0}


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