; LLVM IR from mlcommons/tiny :: benchmark/interface/Drivers/BSP/Components/cs42l51 (cs42l51)

; 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.CS42L51_IO_t = type { ptr, ptr, i16, ptr, ptr, ptr }
%struct.CS42L51_Object_t = type { %struct.CS42L51_IO_t, %struct.cs42l51_ctx_t, i8 }
%struct.cs42l51_ctx_t = type { ptr, ptr, ptr }

; 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 i32 @CS42L51_RegisterBusIO(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = 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 4, ptr %5) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %69

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %14, i32 0, i32 0
  store ptr %12, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %20, i32 0, i32 1
  store ptr %18, ptr %21, align 8, !tbaa !18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 8, !tbaa !19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %26, i32 0, i32 2
  store i16 %24, ptr %27, align 8, !tbaa !20
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %32, i32 0, i32 3
  store ptr %30, ptr %33, align 8, !tbaa !22
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !23
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %38, i32 0, i32 4
  store ptr %36, ptr %39, align 8, !tbaa !24
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %40, i32 0, i32 5
  %42 = load ptr, ptr %41, align 8, !tbaa !25
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %44, i32 0, i32 5
  store ptr %42, ptr %45, align 8, !tbaa !26
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.cs42l51_ctx_t, ptr %47, i32 0, i32 1
  store ptr @CS42L51_ReadRegWrap, ptr %48, align 8, !tbaa !27
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %49, i32 0, i32 1
  %51 = getelementptr inbounds %struct.cs42l51_ctx_t, ptr %50, i32 0, i32 0
  store ptr @CS42L51_WriteRegWrap, ptr %51, align 8, !tbaa !28
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.cs42l51_ctx_t, ptr %54, i32 0, i32 2
  store ptr %52, ptr %55, align 8, !tbaa !29
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %67

61:                                               ; preds = %9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.CS42L51_Object_t, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds %struct.CS42L51_IO_t, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  %66 = call i32 %65()
  store i32 %66, ptr %5, align 4, !tbaa !9
  br label %68

67:                                               ; preds = %9
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %67, %61
  br label %69

69:                                               ; preds = %68, %8
  %70 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %70
}

; Function Attrs: nounwind uwtable
declare hidden i32 @CS42L51_ReadRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @CS42L51_WriteRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) #1

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !12, i64 0, !16, i64 48, !7, i64 72}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!12, !6, i64 8}
!18 = !{!15, !6, i64 8}
!19 = !{!12, !13, i64 16}
!20 = !{!15, !13, i64 16}
!21 = !{!12, !6, i64 24}
!22 = !{!15, !6, i64 24}
!23 = !{!12, !6, i64 32}
!24 = !{!15, !6, i64 32}
!25 = !{!12, !6, i64 40}
!26 = !{!15, !6, i64 40}
!27 = !{!15, !6, i64 56}
!28 = !{!15, !6, i64 48}
!29 = !{!15, !6, i64 64}


; 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
define dso_local i32 @CS42L51_RegisterBusIO(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %23, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %5, ptr %0, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load i16, ptr %9, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 %10, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load <2 x ptr>, ptr %12, align 8, !tbaa !18
  store <2 x ptr> %14, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %1, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %16, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr @CS42L51_ReadRegWrap, ptr %19, align 8, !tbaa !21
  store ptr @CS42L51_WriteRegWrap, ptr %18, align 8, !tbaa !22
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %0, ptr %20, align 8, !tbaa !23
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %23, label %21

21:                                               ; preds = %4
  %22 = tail call i32 %5() #1
  br label %23

23:                                               ; preds = %4, %2, %21
  %.0 = phi i32 [ %22, %21 ], [ -1, %2 ], [ -1, %4 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @CS42L51_ReadRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @CS42L51_WriteRegWrap(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) #0

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 = { 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 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 48, !8, i64 72}
!13 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!6, !7, i64 8}
!15 = !{!12, !7, i64 8}
!16 = !{!6, !10, i64 16}
!17 = !{!12, !10, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!6, !7, i64 40}
!20 = !{!12, !7, i64 40}
!21 = !{!12, !7, i64 56}
!22 = !{!12, !7, i64 48}
!23 = !{!12, !7, i64 64}


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