; 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
@__FUNCTION__.on_idle = external hidden unnamed_addr constant [8 x i8], align 1
@RUNTIME = external global %struct.RUNTIME_OPTIONS, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @on_idle() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  %4 = load ptr, ptr @stdout, align 8, !tbaa !9
  %5 = call i32 (i32, ptr, ptr, ...) @verbose(i32 noundef 2, ptr noundef %4, ptr noundef @.str, ptr noundef @__FUNCTION__.on_idle)
  store i8 0, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 8), align 4, !tbaa !11
  call void @cAPA102_Clear_All()
  %6 = call i64 @time(ptr noundef null) #4
  %7 = trunc i64 %6 to i32
  call void @srand(i32 noundef %7) #4
  %8 = load i8, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 3), align 8, !tbaa !17
  %9 = zext i8 %8 to i32
  %10 = sdiv i32 %9, 20
  %11 = trunc i32 %10 to i8
  store i8 %11, ptr %3, align 1, !tbaa !18
  br label %12

12:                                               ; preds = %67, %0
  %13 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !19
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %70

15:                                               ; preds = %12
  call void @delay_on_state(i32 noundef 2000, i32 noundef 0)
  call void @cAPA102_Clear_All()
  %16 = call i32 @rand() #4
  %17 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 1), align 4, !tbaa !20
  %18 = srem i32 %16, %17
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr %2, align 1, !tbaa !18
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %37, %15
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = load i8, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 3), align 8, !tbaa !17
  %23 = zext i8 %22 to i32
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !19
  %27 = icmp eq i32 %26, 0
  br label %28

28:                                               ; preds = %25, %20
  %29 = phi i1 [ false, %20 ], [ %27, %25 ]
  br i1 %29, label %30, label %42

30:                                               ; preds = %28
  %31 = load i8, ptr %2, align 1, !tbaa !18
  %32 = zext i8 %31 to i32
  %33 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 6), align 4, !tbaa !21
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = trunc i32 %34 to i8
  %36 = call i32 @remap_4byte(i32 noundef %33, i8 noundef zeroext %35)
  call void @cAPA102_Set_Pixel_4byte(i32 noundef %32, i32 noundef %36)
  call void @cAPA102_Refresh()
  call void @delay_on_state(i32 noundef 100, i32 noundef 0)
  br label %37

37:                                               ; preds = %30
  %38 = load i8, ptr %3, align 1, !tbaa !18
  %39 = zext i8 %38 to i32
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %1, align 4, !tbaa !5
  br label %20, !llvm.loop !22

42:                                               ; preds = %28
  %43 = load i8, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 3), align 8, !tbaa !17
  %44 = zext i8 %43 to i32
  store i32 %44, ptr %1, align 4, !tbaa !5
  %45 = load i8, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 3), align 8, !tbaa !17
  %46 = zext i8 %45 to i32
  store i32 %46, ptr %1, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %62, %42
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 5), align 8, !tbaa !19
  %52 = icmp eq i32 %51, 0
  br label %53

53:                                               ; preds = %50, %47
  %54 = phi i1 [ false, %47 ], [ %52, %50 ]
  br i1 %54, label %55, label %67

55:                                               ; preds = %53
  %56 = load i8, ptr %2, align 1, !tbaa !18
  %57 = zext i8 %56 to i32
  %58 = load i32, ptr getelementptr inbounds (%struct.RUNTIME_OPTIONS, ptr @RUNTIME, i32 0, i32 6), align 4, !tbaa !21
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = trunc i32 %59 to i8
  %61 = call i32 @remap_4byte(i32 noundef %58, i8 noundef zeroext %60)
  call void @cAPA102_Set_Pixel_4byte(i32 noundef %57, i32 noundef %61)
  call void @cAPA102_Refresh()
  call void @delay_on_state(i32 noundef 100, i32 noundef 0)
  br label %62

62:                                               ; preds = %55
  %63 = load i8, ptr %3, align 1, !tbaa !18
  %64 = zext i8 %63 to i32
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = sub nsw i32 %65, %64
  store i32 %66, ptr %1, align 4, !tbaa !5
  br label %47, !llvm.loop !24

67:                                               ; preds = %53
  %68 = load i8, ptr %2, align 1, !tbaa !18
  %69 = zext i8 %68 to i32
  call void @cAPA102_Set_Pixel_4byte(i32 noundef %69, i32 noundef 0)
  call void @cAPA102_Refresh()
  call void @delay_on_state(i32 noundef 3000, i32 noundef 0)
  br label %12, !llvm.loop !25

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

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

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

declare void @cAPA102_Clear_All() #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #3

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

; Function Attrs: nounwind
declare i32 @rand() #3

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

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

declare void @cAPA102_Refresh() #2

; 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 = { "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 "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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 116}
!12 = !{!"", !7, i64 0, !13, i64 52, !14, i64 64, !7, i64 72, !15, i64 80, !6, i64 88, !16, i64 92, !6, i64 112, !7, i64 116, !7, i64 117, !7, i64 118, !7, i64 124}
!13 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!"", !6, i64 0, !6, i64 4}
!15 = !{!"long", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16}
!17 = !{!12, !7, i64 72}
!18 = !{!7, !7, i64 0}
!19 = !{!12, !6, i64 88}
!20 = !{!12, !6, i64 52}
!21 = !{!12, !6, i64 92}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}
!25 = distinct !{!25, !23}


; 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
@__FUNCTION__.on_idle = external hidden unnamed_addr constant [8 x i8], align 1
@RUNTIME = external local_unnamed_addr global %struct.RUNTIME_OPTIONS, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @on_idle() local_unnamed_addr #0 {
  %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_idle) #3
  store i8 0, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 116), align 4, !tbaa !9
  tail call void @cAPA102_Clear_All() #3
  %3 = tail call i64 @time(ptr noundef null) #3
  %4 = trunc i64 %3 to i32
  tail call void @srand(i32 noundef %4) #3
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8, !tbaa !16
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.lr.ph15, label %._crit_edge16

.lr.ph15:                                         ; preds = %0
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 72), align 8, !tbaa !17
  %8 = udiv i8 %7, 20
  %9 = zext nneg i8 %8 to i32
  br label %10

10:                                               ; preds = %.lr.ph15, %._crit_edge
  tail call void @delay_on_state(i32 noundef 2000, i32 noundef 0)
  tail call void @cAPA102_Clear_All() #3
  %11 = tail call i32 @rand() #3
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 52), align 4, !tbaa !18
  %13 = srem i32 %11, %12
  %14 = load i8, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 72), align 8, !tbaa !17
  %15 = zext i8 %14 to i32
  %16 = icmp ne i8 %14, 0
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %18 = icmp eq i32 %17, 0
  %19 = select i1 %16, i1 %18, i1 false
  br i1 %19, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %10
  %20 = and i32 %13, 255
  br label %26

.preheader:                                       ; preds = %26, %10
  %21 = phi i32 [ %17, %10 ], [ %34, %26 ]
  %.lcssa = phi i32 [ %15, %10 ], [ %32, %26 ]
  %22 = icmp ne i32 %.lcssa, 0
  %23 = icmp eq i32 %21, 0
  %24 = select i1 %22, i1 %23, i1 false
  %25 = and i32 %13, 255
  br i1 %24, label %.lr.ph13, label %._crit_edge

26:                                               ; preds = %.lr.ph, %26
  %.011 = phi i32 [ 0, %.lr.ph ], [ %30, %26 ]
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 92), align 4, !tbaa !19
  %28 = trunc i32 %.011 to i8
  %29 = tail call i32 @remap_4byte(i32 noundef %27, i8 noundef zeroext %28)
  tail call void @cAPA102_Set_Pixel_4byte(i32 noundef %20, i32 noundef %29) #3
  tail call void @cAPA102_Refresh() #3
  tail call void @delay_on_state(i32 noundef 100, i32 noundef 0)
  %30 = add nuw nsw i32 %.011, %9
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 72), align 8, !tbaa !17
  %32 = zext i8 %31 to i32
  %33 = icmp ult i32 %30, %32
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %35 = icmp eq i32 %34, 0
  %36 = select i1 %33, i1 %35, i1 false
  br i1 %36, label %26, label %.preheader, !llvm.loop !20

.lr.ph13:                                         ; preds = %.preheader, %.lr.ph13
  %.112 = phi i32 [ %40, %.lr.ph13 ], [ %.lcssa, %.preheader ]
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 92), align 4, !tbaa !19
  %38 = trunc nuw i32 %.112 to i8
  %39 = tail call i32 @remap_4byte(i32 noundef %37, i8 noundef zeroext %38)
  tail call void @cAPA102_Set_Pixel_4byte(i32 noundef %25, i32 noundef %39) #3
  tail call void @cAPA102_Refresh() #3
  tail call void @delay_on_state(i32 noundef 100, i32 noundef 0)
  %40 = sub nsw i32 %.112, %9
  %41 = icmp sgt i32 %40, 0
  %42 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8
  %43 = icmp eq i32 %42, 0
  %44 = select i1 %41, i1 %43, i1 false
  br i1 %44, label %.lr.ph13, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph13, %.preheader
  tail call void @cAPA102_Set_Pixel_4byte(i32 noundef %25, i32 noundef 0) #3
  tail call void @cAPA102_Refresh() #3
  tail call void @delay_on_state(i32 noundef 3000, i32 noundef 0)
  %45 = load i32, ptr getelementptr inbounds (i8, ptr @RUNTIME, i64 88), align 8, !tbaa !16
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %10, label %._crit_edge16, !llvm.loop !23

._crit_edge16:                                    ; preds = %._crit_edge, %0
  tail call void @cAPA102_Clear_All() #3
  ret ptr @.str.1
}

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

declare void @cAPA102_Clear_All() local_unnamed_addr #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

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

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

declare void @cAPA102_Refresh() 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 "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 88}
!17 = !{!10, !7, i64 72}
!18 = !{!10, !12, i64 52}
!19 = !{!10, !12, i64 92}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = distinct !{!23, !21}


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