; LLVM IR from IOsonata/IOsonata :: ARM/NXP/src (spi_lpcxx)

; 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.__device_intrf = type <{ ptr, i32, ptr, %struct.atomic_flag, [3 x i8], i32, i32, i32, i8, i8, i8, i8, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }>
%struct.atomic_flag = type { i8 }
%struct.SSPDEV = type { i32, i32, ptr, ptr }
%struct.LPCSSPREG = type { i32, i32, i32, i32, i32, i32, i32, i32, 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

; Function Attrs: nounwind uwtable
define dso_local i32 @LpcSSPTxData(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.__device_intrf, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 4, !tbaa !11
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 1, ptr %9, align 1, !tbaa !16
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SSPDEV, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds %struct.LPCSSPREG, ptr %15, i32 0, i32 0
  %17 = load volatile i32, ptr %16, align 4, !tbaa !19
  %18 = and i32 %17, 8
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  store i8 0, ptr %9, align 1, !tbaa !16
  br label %21

21:                                               ; preds = %20, %3
  br label %22

22:                                               ; preds = %67, %21
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %68

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call zeroext i1 @LpcSSPWaitTxFifo(ptr noundef %26, i32 noundef 100000)
  br i1 %27, label %28, label %67

28:                                               ; preds = %25
  %29 = load i8, ptr %9, align 1, !tbaa !16, !range !21, !noundef !22
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %46

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !23
  %34 = zext i8 %33 to i32
  %35 = and i32 %34, 255
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SSPDEV, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = getelementptr inbounds %struct.LPCSSPREG, ptr %38, i32 0, i32 2
  store volatile i32 %35, ptr %39, align 4, !tbaa !24
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %44, -1
  store i32 %45, ptr %6, align 4, !tbaa !9
  br label %61

46:                                               ; preds = %28
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i16, ptr %47, align 2, !tbaa !25
  %49 = zext i16 %48 to i32
  %50 = and i32 %49, 65535
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.SSPDEV, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = getelementptr inbounds %struct.LPCSSPREG, ptr %53, i32 0, i32 2
  store volatile i32 %50, ptr %54, align 4, !tbaa !24
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 2
  store ptr %56, ptr %5, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %57, 2
  store i32 %58, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = sub nsw i32 %59, 2
  store i32 %60, ptr %6, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %46, %31
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SSPDEV, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = getelementptr inbounds %struct.LPCSSPREG, ptr %64, i32 0, i32 2
  %66 = load volatile i32, ptr %65, align 4, !tbaa !24
  br label %67

67:                                               ; preds = %61, %25
  br label %22, !llvm.loop !27

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @LpcSSPWaitTxFifo(ptr noundef, i32 noundef) #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 = !{!"__device_intrf", !6, i64 0, !10, i64 8, !6, i64 12, !13, i64 20, !10, i64 24, !7, i64 28, !10, i64 32, !14, i64 36, !14, i64 37, !7, i64 38, !7, i64 39, !15, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"atomic_flag", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!7, !7, i64 0}
!24 = !{!20, !10, i64 8}
!25 = !{!26, !26, i64 0}
!26 = !{!"short", !7, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; 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 @LpcSSPTxData(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  %7 = load volatile i32, ptr %6, align 4, !tbaa !16
  %8 = icmp sgt i32 %2, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %.fr26 = freeze i32 %7
  %9 = and i32 %.fr26, 8
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %20
  %.01625.us = phi i32 [ %.2.us, %20 ], [ 0, %.lr.ph ]
  %.01724.us = phi ptr [ %.219.us, %20 ], [ %1, %.lr.ph ]
  %.02023.us = phi i32 [ %.222.us, %20 ], [ %2, %.lr.ph ]
  %10 = tail call zeroext i1 @LpcSSPWaitTxFifo(ptr noundef %4, i32 noundef 100000)
  br i1 %10, label %11, label %20

11:                                               ; preds = %.lr.ph.split.us
  %12 = load i8, ptr %.01724.us, align 1, !tbaa !18
  %13 = zext i8 %12 to i32
  %14 = load ptr, ptr %5, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  store volatile i32 %13, ptr %15, align 4, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %.01724.us, i64 1
  %17 = add nsw i32 %.01625.us, 1
  %18 = add nsw i32 %.02023.us, -1
  %19 = load volatile i32, ptr %15, align 4, !tbaa !19
  br label %20

20:                                               ; preds = %11, %.lr.ph.split.us
  %.222.us = phi i32 [ %18, %11 ], [ %.02023.us, %.lr.ph.split.us ]
  %.219.us = phi ptr [ %16, %11 ], [ %.01724.us, %.lr.ph.split.us ]
  %.2.us = phi i32 [ %17, %11 ], [ %.01625.us, %.lr.ph.split.us ]
  %21 = icmp sgt i32 %.222.us, 0
  br i1 %21, label %.lr.ph.split.us, label %._crit_edge, !llvm.loop !20

.lr.ph.split:                                     ; preds = %.lr.ph, %32
  %.01625 = phi i32 [ %.2, %32 ], [ 0, %.lr.ph ]
  %.01724 = phi ptr [ %.219, %32 ], [ %1, %.lr.ph ]
  %.02023 = phi i32 [ %.222, %32 ], [ %2, %.lr.ph ]
  %22 = tail call zeroext i1 @LpcSSPWaitTxFifo(ptr noundef %4, i32 noundef 100000)
  br i1 %22, label %23, label %32

23:                                               ; preds = %.lr.ph.split
  %24 = load i16, ptr %.01724, align 2, !tbaa !22
  %25 = zext i16 %24 to i32
  %26 = load ptr, ptr %5, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  store volatile i32 %25, ptr %27, align 4, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %.01724, i64 2
  %29 = add nsw i32 %.01625, 2
  %30 = add nsw i32 %.02023, -2
  %31 = load volatile i32, ptr %27, align 4, !tbaa !19
  br label %32

32:                                               ; preds = %23, %.lr.ph.split
  %.222 = phi i32 [ %30, %23 ], [ %.02023, %.lr.ph.split ]
  %.219 = phi ptr [ %28, %23 ], [ %.01724, %.lr.ph.split ]
  %.2 = phi i32 [ %29, %23 ], [ %.01625, %.lr.ph.split ]
  %33 = icmp sgt i32 %.222, 0
  br i1 %33, label %.lr.ph.split, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %32, %20, %3
  %.016.lcssa = phi i32 [ 0, %3 ], [ %.2.us, %20 ], [ %.2, %32 ]
  ret i32 %.016.lcssa
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @LpcSSPWaitTxFifo(ptr noundef, i32 noundef) local_unnamed_addr #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" }

!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 = !{!"__device_intrf", !7, i64 0, !10, i64 8, !7, i64 12, !11, i64 20, !10, i64 24, !8, i64 28, !10, i64 32, !12, i64 36, !12, i64 37, !8, i64 38, !8, i64 39, !13, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"atomic_flag", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!15, !7, i64 8}
!15 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!18 = !{!8, !8, i64 0}
!19 = !{!17, !10, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !23, i64 0}
!23 = !{!"short", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass