; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/I2c (I2cHostI2cBusConfigurationAvailable)

; 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.I2C_HOST_CONTEXT = type { i64, i64, ptr, ptr, i64, i8, %struct._LIST_ENTRY, %struct._EFI_I2C_HOST_PROTOCOL, ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._EFI_I2C_HOST_PROTOCOL = type { ptr, ptr }
%struct.I2C_REQUEST = type { i32, %struct._LIST_ENTRY, i64, i64, ptr, ptr, ptr }
%struct._EFI_I2C_MASTER_PROTOCOL = type { ptr, ptr, ptr, ptr }

@.str.12 = external hidden unnamed_addr constant [139 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [26 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

; Function Attrs: nounwind uwtable
define dso_local void @I2cHostI2cBusConfigurationAvailable(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %13, i32 0, i32 9
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %2
  %17 = call zeroext i8 @DebugAssertEnabled()
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 626, ptr noundef @.str.14)
  br label %23

23:                                               ; preds = %22, %19
  br label %24

24:                                               ; preds = %23, %16
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %27, i32 0, i32 5
  store i8 0, ptr %28, align 8, !tbaa !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %29, i32 0, i32 4
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %26
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %35, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = call i64 @I2cHostRequestComplete(ptr noundef %34, i64 noundef %37)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %39, i32 0, i32 1
  store i64 -1, ptr %40, align 8, !tbaa !16
  store i32 1, ptr %11, align 4
  br label %87

41:                                               ; preds = %26
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %42, i32 0, i32 6
  store ptr %43, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call ptr @GetFirstNode(ptr noundef %44)
  store ptr %45, ptr %9, align 8, !tbaa !5
  %46 = call zeroext i8 @DebugAssertEnabled()
  %47 = zext i8 %46 to i32
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %59

49:                                               ; preds = %41
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = ptrtoint ptr %50 to i64
  %52 = sub i64 %51, ptrtoint (ptr getelementptr inbounds (%struct.I2C_REQUEST, ptr null, i32 0, i32 1) to i64)
  %53 = inttoptr i64 %52 to ptr
  %54 = getelementptr inbounds %struct.I2C_REQUEST, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = icmp ne i32 %55, 1380135497
  br i1 %56, label %57, label %59

57:                                               ; preds = %49
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 658, ptr noundef @.str.13)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  br label %64

59:                                               ; preds = %49, %41
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i64
  %62 = sub i64 %61, ptrtoint (ptr getelementptr inbounds (%struct.I2C_REQUEST, ptr null, i32 0, i32 1) to i64)
  %63 = inttoptr i64 %62 to ptr
  br label %64

64:                                               ; preds = %59, %57
  %65 = phi ptr [ %58, %57 ], [ %63, %59 ]
  store ptr %65, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.I2C_REQUEST, ptr %66, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !20
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %69, i32 0, i32 1
  store i64 %68, ptr %70, align 8, !tbaa !16
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._EFI_I2C_MASTER_PROTOCOL, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.I2C_REQUEST, ptr %75, i32 0, i32 3
  %77 = load i64, ptr %76, align 8, !tbaa !23
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.I2C_REQUEST, ptr %78, i32 0, i32 5
  %80 = load ptr, ptr %79, align 8, !tbaa !24
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !25
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.I2C_HOST_CONTEXT, ptr %84, i32 0, i32 4
  %86 = call i64 %73(ptr noundef %74, i64 noundef %77, ptr noundef %80, ptr noundef %83, ptr noundef %85)
  store i64 %86, ptr %10, align 8, !tbaa !26
  store i32 0, ptr %11, align 4
  br label %87

87:                                               ; preds = %64, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %88 = load i32, ptr %11, align 4
  switch i32 %88, label %90 [
    i32 0, label %89
    i32 1, label %89
  ]

89:                                               ; preds = %87, %87
  ret void

90:                                               ; preds = %87
  unreachable
}

declare zeroext i8 @DebugAssertEnabled() #2

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @I2cHostRequestComplete(ptr noundef, i64 noundef) #1

declare ptr @GetFirstNode(ptr noundef) #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, !6, i64 88}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !7, i64 40, !12, i64 48, !13, i64 64, !6, i64 80, !6, i64 88}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"_EFI_I2C_HOST_PROTOCOL", !6, i64 0, !6, i64 8}
!14 = !{!10, !7, i64 40}
!15 = !{!10, !11, i64 32}
!16 = !{!10, !11, i64 8}
!17 = !{!18, !19, i64 0}
!18 = !{!"", !19, i64 0, !12, i64 8, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!19 = !{!"int", !7, i64 0}
!20 = !{!18, !11, i64 24}
!21 = !{!22, !6, i64 16}
!22 = !{!"_EFI_I2C_MASTER_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!18, !11, i64 32}
!24 = !{!18, !6, i64 48}
!25 = !{!10, !6, i64 24}
!26 = !{!11, !11, 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"

@.str.12 = external hidden unnamed_addr constant [139 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @I2cHostI2cBusConfigurationAvailable(ptr nocapture noundef readnone %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 88
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call zeroext i8 @DebugAssertEnabled() #2
  %6 = icmp eq i8 %5, 0
  %7 = icmp ne ptr %4, null
  %or.cond = select i1 %6, i1 true, i1 %7
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %2
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 626, ptr noundef nonnull @.str.14) #2
  br label %9

9:                                                ; preds = %8, %2
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  store i8 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = icmp slt i64 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %9
  %15 = tail call i64 @I2cHostRequestComplete(ptr noundef nonnull %1, i64 noundef %12)
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 -1, ptr %16, align 8, !tbaa !15
  br label %37

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %1, i64 48
  %19 = tail call ptr @GetFirstNode(ptr noundef nonnull %18) #2
  %20 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %20, 0
  %.pre = ptrtoint ptr %19 to i64
  %.pre23 = add i64 %.pre, -8
  %.pre25 = inttoptr i64 %.pre23 to ptr
  br i1 %.not, label %._crit_edge, label %21

21:                                               ; preds = %17
  %22 = load i32, ptr %.pre25, align 8, !tbaa !16
  %.not22 = icmp eq i32 %22, 1380135497
  br i1 %.not22, label %._crit_edge, label %23

23:                                               ; preds = %21
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 658, ptr noundef nonnull @.str.13) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %17, %21, %23
  %24 = phi ptr [ %19, %23 ], [ %.pre25, %21 ], [ %.pre25, %17 ]
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = load i64, ptr %25, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %26, ptr %27, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %4, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %24, i64 32
  %31 = load i64, ptr %30, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %24, i64 48
  %33 = load ptr, ptr %32, align 8, !tbaa !23
  %34 = getelementptr inbounds i8, ptr %1, i64 24
  %35 = load ptr, ptr %34, align 8, !tbaa !24
  %36 = tail call i64 %29(ptr noundef %4, i64 noundef %31, ptr noundef %33, ptr noundef %35, ptr noundef nonnull %11) #2
  br label %37

37:                                               ; preds = %._crit_edge, %14
  ret void
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

declare ptr @GetFirstNode(ptr noundef) 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, !10, i64 88}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !8, i64 40, !11, i64 48, !12, i64 64, !10, i64 80, !10, i64 88}
!7 = !{!"long long", !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 = !{!"_EFI_I2C_HOST_PROTOCOL", !10, i64 0, !10, i64 8}
!13 = !{!6, !8, i64 40}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !7, i64 8}
!16 = !{!17, !18, i64 0}
!17 = !{!"", !18, i64 0, !11, i64 8, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!18 = !{!"int", !8, i64 0}
!19 = !{!17, !7, i64 24}
!20 = !{!21, !10, i64 16}
!21 = !{!"_EFI_I2C_MASTER_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!22 = !{!17, !7, i64 32}
!23 = !{!17, !10, i64 48}
!24 = !{!6, !10, i64 24}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass