; LLVM IR from zeroth-robotics/zeroth-bot :: kos-zbot/firmware/sts3215 (sts3215)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @servo_write(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, i8 noundef zeroext) #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 @set_servo_speed(i8 noundef zeroext %0, i16 noundef zeroext %1, i32 noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca i16, align 2
  %8 = alloca [2 x i8], align 1
  store i8 %0, ptr %4, align 1, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !8
  store i32 %2, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  %9 = load i16, ptr %5, align 2, !tbaa !8
  %10 = zext i16 %9 to i32
  %11 = and i32 %10, 32767
  %12 = trunc i32 %11 to i16
  store i16 %12, ptr %7, align 2, !tbaa !8
  %13 = load i32, ptr %6, align 4, !tbaa !10
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %3
  %16 = load i16, ptr %7, align 2, !tbaa !8
  %17 = zext i16 %16 to i32
  %18 = or i32 %17, 32768
  %19 = trunc i32 %18 to i16
  store i16 %19, ptr %7, align 2, !tbaa !8
  br label %20

20:                                               ; preds = %15, %3
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  %21 = load i16, ptr %7, align 2, !tbaa !8
  %22 = zext i16 %21 to i32
  %23 = and i32 %22, 255
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 0
  store i8 %24, ptr %25, align 1, !tbaa !5
  %26 = load i16, ptr %7, align 2, !tbaa !8
  %27 = zext i16 %26 to i32
  %28 = ashr i32 %27, 8
  %29 = and i32 %28, 255
  %30 = trunc i32 %29 to i8
  %31 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 1
  store i8 %30, ptr %31, align 1, !tbaa !5
  %32 = load i8, ptr %4, align 1, !tbaa !5
  %33 = getelementptr inbounds [2 x i8], ptr %8, i64 0, i64 0
  %34 = call i32 @servo_write(i8 noundef zeroext %32, i8 noundef zeroext 46, ptr noundef %33, i8 noundef zeroext 2)
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  ret i32 %34
}

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


; 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
declare dso_local i32 @servo_write(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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 @set_servo_speed(i8 noundef zeroext %0, i16 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [2 x i8], align 1
  %5 = and i16 %1, 32512
  %6 = lshr i32 %2, 16
  %7 = trunc nuw i32 %6 to i16
  %masksel = and i16 %7, -32768
  %spec.select = or disjoint i16 %masksel, %5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #2
  %8 = trunc i16 %1 to i8
  store i8 %8, ptr %4, align 1, !tbaa !5
  %9 = lshr exact i16 %spec.select, 8
  %10 = trunc nuw i16 %9 to i8
  %11 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = call i32 @servo_write(i8 noundef zeroext %0, i8 noundef zeroext 46, ptr noundef nonnull %4, i8 noundef zeroext 2)
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #2
  ret i32 %12
}

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 = { mustprogress 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass