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

; 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.RUNTIME_OPTIONS = type { [50 x i8], %struct.HW_LED_SPEC, %struct.HW_GPIO_SPEC, i8, i64, i32, %struct.COLOURS, i32, i8, i8, [6 x i8], i8 }
%struct.HW_LED_SPEC = type { i32, i32, i32 }
%struct.HW_GPIO_SPEC = type { i32, i32 }
%struct.COLOURS = type { i32, i32, i32, i32, i32 }

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [33 x i8], align 1
@RUNTIME = external global %struct.RUNTIME_OPTIONS, align 8
@__FUNCTION__.on_listen = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 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

declare i32 @verbose(i32 noundef, ptr noundef, ptr noundef, ...) #1

declare void @cAPA102_Clear_All() #1

; Function Attrs: nounwind uwtable
declare hidden void @delay_on_state(i32 noundef, i32 noundef) #2

declare void @cAPA102_Set_Pixel_4byte(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @remap_4byte(i32 noundef, i8 noundef zeroext) #2

declare void @cAPA102_Refresh() #1

; 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 ptr @on_listen() #2 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %4 = load ptr, ptr @stdout, align 8, !tbaa !5
  %5 = call i32 (i32, ptr, ptr, ...) @verbose(i32 noundef 2, ptr noundef %4, ptr noundef @.str, ptr noundef @__FUNCTION__.on_listen)
  store i8 0, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 8), align 4, !tbaa !9
  call void @cAPA102_Clear_All()
  %6 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 1), align 4, !tbaa !16
  %7 = sdiv i32 %6, 3
  %8 = trunc i32 %7 to i8
  store i8 %8, ptr %3, align 1, !tbaa !17
  br label %9

9:                                                ; preds = %51, %0
  %10 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !18
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %52

12:                                               ; preds = %9
  store i8 0, ptr %1, align 1, !tbaa !17
  br label %13

13:                                               ; preds = %48, %12
  %14 = load i8, ptr %1, align 1, !tbaa !17
  %15 = zext i8 %14 to i32
  %16 = icmp slt i32 %15, 3
  br i1 %16, label %17, label %20

17:                                               ; preds = %13
  %18 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !18
  %19 = icmp eq i32 %18, 1
  br label %20

20:                                               ; preds = %17, %13
  %21 = phi i1 [ false, %13 ], [ %19, %17 ]
  br i1 %21, label %22, label %51

22:                                               ; preds = %20
  store i8 0, ptr %2, align 1, !tbaa !17
  br label %23

23:                                               ; preds = %44, %22
  %24 = load i8, ptr %2, align 1, !tbaa !17
  %25 = zext i8 %24 to i32
  %26 = load i8, ptr %3, align 1, !tbaa !17
  %27 = zext i8 %26 to i32
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %23
  %30 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !18
  %31 = icmp eq i32 %30, 1
  br label %32

32:                                               ; preds = %29, %23
  %33 = phi i1 [ false, %23 ], [ %31, %29 ]
  br i1 %33, label %34, label %47

34:                                               ; preds = %32
  %35 = load i8, ptr %2, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = mul nsw i32 %36, 3
  %38 = load i8, ptr %1, align 1, !tbaa !17
  %39 = zext i8 %38 to i32
  %40 = add nsw i32 %37, %39
  %41 = load i32, ptr getelementptr inbounds (%struct.COLOURS, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 6), i32 0, i32 1), align 4, !tbaa !19
  %42 = load i8, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 3), align 8, !tbaa !20
  %43 = call i32 @remap_4byte(i32 noundef %41, i8 noundef zeroext %42)
  call void @cAPA102_Set_Pixel_4byte(i32 noundef %40, i32 noundef %43)
  br label %44

44:                                               ; preds = %34
  %45 = load i8, ptr %2, align 1, !tbaa !17
  %46 = add i8 %45, 1
  store i8 %46, ptr %2, align 1, !tbaa !17
  br label %23, !llvm.loop !21

47:                                               ; preds = %32
  call void @cAPA102_Refresh()
  call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  call void @cAPA102_Clear_All()
  call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  br label %48

48:                                               ; preds = %47
  %49 = load i8, ptr %1, align 1, !tbaa !17
  %50 = add i8 %49, 1
  store i8 %50, ptr %1, align 1, !tbaa !17
  br label %13, !llvm.loop !23

51:                                               ; preds = %20
  br label %9, !llvm.loop !24

52:                                               ; preds = %9
  call void @cAPA102_Clear_All()
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret ptr @.str.2
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !7, i64 116}
!10 = !{!"", !7, i64 0, !11, i64 52, !13, i64 64, !7, i64 72, !14, i64 80, !12, i64 88, !15, i64 92, !12, i64 112, !7, i64 116, !7, i64 117, !7, i64 118, !7, i64 124}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!16 = !{!10, !12, i64 52}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !12, i64 88}
!19 = !{!10, !12, i64 96}
!20 = !{!10, !7, i64 72}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}
!24 = distinct !{!24, !22}


; 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.RUNTIME_OPTIONS = type { [50 x i8], %struct.HW_LED_SPEC, %struct.HW_GPIO_SPEC, i8, i64, i32, %struct.COLOURS, i32, i8, i8, [6 x i8], i8 }
%struct.HW_LED_SPEC = type { i32, i32, i32 }
%struct.HW_GPIO_SPEC = type { i32, i32 }
%struct.COLOURS = type { i32, i32, i32, i32, i32 }

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [33 x i8], align 1
@RUNTIME = external local_unnamed_addr global %struct.RUNTIME_OPTIONS, align 8
@__FUNCTION__.on_listen = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1

declare i32 @verbose(i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

declare void @cAPA102_Clear_All() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @delay_on_state(i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @cAPA102_Set_Pixel_4byte(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @remap_4byte(i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @cAPA102_Refresh() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @on_listen() local_unnamed_addr #1 {
  %1 = load ptr, ptr @stdout, align 8, !tbaa !5
  %2 = tail call i32 (i32, ptr, ptr, ...) @verbose(i32 noundef 2, ptr noundef %1, ptr noundef nonnull @.str, ptr noundef nonnull @__FUNCTION__.on_listen) #2
  store i8 0, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 116), align 4, !tbaa !9
  tail call void @cAPA102_Clear_All() #2
  %.pr = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %3 = icmp eq i32 %.pr, 1
  br i1 %3, label %.preheader10.preheader, label %._crit_edge13

.preheader10.preheader:                           ; preds = %0
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 52), align 4, !tbaa !16
  %.fr15 = freeze i32 %4
  %5 = sdiv i32 %.fr15, 3
  %6 = and i32 %5, 255
  %.not = icmp eq i32 %6, 0
  br label %.preheader.lr.ph

.loopexit:                                        ; preds = %._crit_edge, %.preheader.us
  %7 = phi i32 [ %11, %.preheader.us ], [ %27, %._crit_edge ]
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %.preheader.lr.ph, label %._crit_edge13, !llvm.loop !17

.preheader.lr.ph:                                 ; preds = %.loopexit, %.preheader10.preheader
  br i1 %.not, label %.preheader.us, label %.lr.ph.preheader

.preheader.us:                                    ; preds = %.preheader.lr.ph, %.preheader.us
  %.012.us = phi i8 [ %9, %.preheader.us ], [ 0, %.preheader.lr.ph ]
  tail call void @cAPA102_Refresh() #2
  tail call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  tail call void @cAPA102_Clear_All() #2
  tail call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  %9 = add nuw nsw i8 %.012.us, 1
  %10 = icmp ult i8 %.012.us, 2
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %12 = icmp eq i32 %11, 1
  %13 = select i1 %10, i1 %12, i1 false
  br i1 %13, label %.preheader.us, label %.loopexit, !llvm.loop !20

.lr.ph.preheader:                                 ; preds = %.preheader.lr.ph, %._crit_edge
  %indvars.iv = phi i32 [ %indvars.iv.next, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %14 = phi i32 [ %21, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.0711 = phi i8 [ %20, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %15 = mul nuw nsw i32 %14, 3
  %16 = add nuw nsw i32 %15, %indvars.iv
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 96), align 8, !tbaa !21
  %18 = load i8, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 72), align 8, !tbaa !22
  %19 = tail call i32 @remap_4byte(i32 noundef %17, i8 noundef zeroext %18)
  tail call void @cAPA102_Set_Pixel_4byte(i32 noundef %16, i32 noundef %19) #2
  %20 = add nuw i8 %.0711, 1
  %21 = zext i8 %20 to i32
  %22 = icmp ugt i32 %6, %21
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %24 = icmp eq i32 %23, 1
  %25 = select i1 %22, i1 %24, i1 false
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph
  tail call void @cAPA102_Refresh() #2
  tail call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  tail call void @cAPA102_Clear_All() #2
  tail call void @delay_on_state(i32 noundef 80, i32 noundef 1)
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %26 = icmp ult i32 %indvars.iv, 2
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %28 = icmp eq i32 %27, 1
  %29 = select i1 %26, i1 %28, i1 false
  br i1 %29, label %.lr.ph.preheader, label %.loopexit, !llvm.loop !20

._crit_edge13:                                    ; preds = %.loopexit, %0
  tail call void @cAPA102_Clear_All() #2
  ret ptr @.str.2
}

attributes #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 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, !7, i64 116}
!10 = !{!"", !7, i64 0, !11, i64 52, !13, i64 64, !7, i64 72, !14, i64 80, !12, i64 88, !15, i64 92, !12, i64 112, !7, i64 116, !7, i64 117, !7, i64 118, !7, i64 124}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4}
!14 = !{!"long", !7, i64 0}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!16 = !{!10, !12, i64 52}
!17 = distinct !{!17, !18, !19}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.unswitch.partial.disable"}
!20 = distinct !{!20, !18}
!21 = !{!10, !12, i64 96}
!22 = !{!10, !7, i64 72}
!23 = distinct !{!23, !18}


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