; LLVM IR from sskorol/respeaker-websockets :: src (cAPA102)

; 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.cAPA102_LEDs = type { i32, i32, ptr, i8 }

@cAPA012_BUF = external hidden global %struct.cAPA102_LEDs, align 8

; Function Attrs: nounwind uwtable
define dso_local void @cAPA102_Clear_All() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %3 = load ptr, ptr getelementptr inbounds (%struct.cAPA102_LEDs, ptr @cAPA012_BUF, i32 0, i32 2), align 8, !tbaa !5
  store ptr %3, ptr %1, align 8, !tbaa !11
  store i32 0, ptr %2, align 4, !tbaa !12
  br label %4

4:                                                ; preds = %15, %0
  %5 = load i32, ptr %2, align 4, !tbaa !12
  %6 = load i32, ptr @cAPA012_BUF, align 8, !tbaa !13
  %7 = icmp ult i32 %5, %6
  br i1 %7, label %8, label %20

8:                                                ; preds = %4
  %9 = load ptr, ptr %1, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 1
  store i8 0, ptr %10, align 1, !tbaa !14
  %11 = load ptr, ptr %1, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 2
  store i8 0, ptr %12, align 1, !tbaa !14
  %13 = load ptr, ptr %1, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 3
  store i8 0, ptr %14, align 1, !tbaa !14
  br label %15

15:                                               ; preds = %8
  %16 = load i32, ptr %2, align 4, !tbaa !12
  %17 = add i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !12
  %18 = load ptr, ptr %1, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  store ptr %19, ptr %1, align 8, !tbaa !11
  br label %4, !llvm.loop !15

20:                                               ; preds = %4
  call void @cAPA102_Refresh()
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @cAPA102_Refresh() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.cAPA102_LEDs = type { i32, i32, ptr, i8 }

@cAPA012_BUF = external hidden local_unnamed_addr global %struct.cAPA102_LEDs, align 8

; Function Attrs: nounwind uwtable
define dso_local void @cAPA102_Clear_All() local_unnamed_addr #0 {
  %1 = load i32, ptr @cAPA012_BUF, align 8, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @cAPA012_BUF, i64 8), align 8, !tbaa !11
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.07 = phi i32 [ %6, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.056 = phi ptr [ %7, %.lr.ph ], [ %2, %.lr.ph.preheader ]
  %3 = getelementptr inbounds i8, ptr %.056, i64 1
  store i8 0, ptr %3, align 1, !tbaa !12
  %4 = getelementptr inbounds i8, ptr %.056, i64 2
  store i8 0, ptr %4, align 1, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %.056, i64 3
  store i8 0, ptr %5, align 1, !tbaa !12
  %6 = add nuw i32 %.07, 1
  %7 = getelementptr inbounds i8, ptr %.056, i64 4
  %8 = load i32, ptr @cAPA012_BUF, align 8, !tbaa !5
  %9 = icmp ult i32 %6, %8
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @cAPA102_Refresh()
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @cAPA102_Refresh() 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 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass