; LLVM IR from beagleboard/librobotcontrol :: library/src (led)

; 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"

@blinking = external hidden global [11 x i32], align 16
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@stop_blinking_flag = external hidden global [11 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_led_set(i32 noundef, i32 noundef) #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

; Function Attrs: nounwind uwtable
define dso_local i32 @rc_led_blink(i32 noundef %0, float noundef %1, float noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %3
  %19 = load ptr, ptr @stderr, align 8, !tbaa !11
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str.4) #4
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %78

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %22 = load float, ptr %6, align 4, !tbaa !9
  %23 = fmul float 2.000000e+00, %22
  %24 = fdiv float 1.000000e+06, %23
  %25 = fptosi float %24 to i32
  store i32 %25, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %26 = load float, ptr %7, align 4, !tbaa !9
  %27 = fmul float %26, 2.000000e+00
  %28 = load float, ptr %6, align 4, !tbaa !9
  %29 = fmul float %27, %28
  %30 = fptosi float %29 to i32
  store i32 %30, ptr %12, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %32
  store i32 1, ptr %33, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [11 x i32], ptr @stop_blinking_flag, i64 0, i64 %35
  store i32 0, ptr %36, align 4, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %68, %21
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %71

41:                                               ; preds = %37
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [11 x i32], ptr @stop_blinking_flag, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %41
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = call i32 @rc_led_set(i32 noundef %48, i32 noundef 0)
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %51
  store i32 0, ptr %52, align 4, !tbaa !5
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %77

53:                                               ; preds = %41
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = icmp ne i32 %54, 0
  %56 = xor i1 %55, true
  %57 = zext i1 %56 to i32
  store i32 %57, ptr %9, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = call i32 @rc_led_set(i32 noundef %58, i32 noundef %59)
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %53
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %64
  store i32 0, ptr %65, align 4, !tbaa !5
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %77

66:                                               ; preds = %53
  %67 = load i32, ptr %11, align 4, !tbaa !5
  call void @rc_usleep(i32 noundef %67)
  br label %68

68:                                               ; preds = %66
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !5
  br label %37, !llvm.loop !13

71:                                               ; preds = %37
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = call i32 @rc_led_set(i32 noundef %72, i32 noundef 0)
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %75
  store i32 0, ptr %76, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %77

77:                                               ; preds = %71, %62, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %78

78:                                               ; preds = %77, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %79 = load i32, ptr %4, align 4
  ret i32 %79
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare void @rc_usleep(i32 noundef) #3

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 "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 = { "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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@blinking = external hidden local_unnamed_addr global [11 x i32], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [52 x i8], align 1
@stop_blinking_flag = external hidden local_unnamed_addr global [11 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @rc_led_set(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @rc_led_blink(i32 noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [11 x i32], ptr @blinking, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %3
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.4) #3
  br label %28

10:                                               ; preds = %3
  %11 = fmul float %1, 2.000000e+00
  %12 = fdiv float 1.000000e+06, %11
  %13 = fptosi float %12 to i32
  %14 = fmul float %2, 2.000000e+00
  %15 = fmul float %14, %1
  %16 = fptosi float %15 to i32
  store i32 1, ptr %5, align 4, !tbaa !5
  %17 = getelementptr inbounds [11 x i32], ptr @stop_blinking_flag, i64 0, i64 %4
  store i32 0, ptr %17, align 4, !tbaa !5
  %18 = icmp sgt i32 %16, 0
  br i1 %18, label %.lr.ph.preheader, label %._crit_edge

.lr.phthread-pre-split:                           ; preds = %25
  %.pr = load i32, ptr %17, align 4, !tbaa !5
  %.not21 = icmp eq i32 %.pr, 0
  br i1 %.not21, label %.lr.ph.preheader, label %19

19:                                               ; preds = %.lr.phthread-pre-split
  %20 = tail call i32 @rc_led_set(i32 noundef %0, i32 noundef 0)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %28

.lr.ph.preheader:                                 ; preds = %10, %.lr.phthread-pre-split
  %.0202326 = phi i32 [ %21, %.lr.phthread-pre-split ], [ 0, %10 ]
  %.0192425 = phi i32 [ %26, %.lr.phthread-pre-split ], [ 0, %10 ]
  %21 = xor i32 %.0202326, 1
  %22 = tail call i32 @rc_led_set(i32 noundef %0, i32 noundef %21)
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %.lr.ph.preheader
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %28

25:                                               ; preds = %.lr.ph.preheader
  tail call void @rc_usleep(i32 noundef %13) #4
  %26 = add nuw nsw i32 %.0192425, 1
  %exitcond.not = icmp eq i32 %26, %16
  br i1 %exitcond.not, label %._crit_edge, label %.lr.phthread-pre-split, !llvm.loop !11

._crit_edge:                                      ; preds = %25, %10
  %27 = tail call i32 @rc_led_set(i32 noundef %0, i32 noundef 0)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %19, %24, %._crit_edge, %7
  %.1 = phi i32 [ -1, %7 ], [ 1, %19 ], [ -1, %24 ], [ 0, %._crit_edge ]
  ret i32 %.1
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare void @rc_usleep(i32 noundef) local_unnamed_addr #2

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 = { nofree 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 #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 = { cold nounwind }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass