; LLVM IR from cvra/robot-software :: uwb-beacon-firmware/src (uwb_protocol)

; 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
define dso_local i64 @uwb_mac_encapsulate_frame(i16 noundef zeroext %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i16, align 2
  %14 = alloca i32, align 4
  store i16 %0, ptr %7, align 2, !tbaa !5
  store i16 %1, ptr %8, align 2, !tbaa !5
  store i16 %2, ptr %9, align 2, !tbaa !5
  store i8 %3, ptr %10, align 1, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !10
  store i64 %5, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  store i16 0, ptr %13, align 2, !tbaa !5
  %15 = load i16, ptr %13, align 2, !tbaa !5
  %16 = zext i16 %15 to i32
  %17 = or i32 %16, 1
  %18 = trunc i32 %17 to i16
  store i16 %18, ptr %13, align 2, !tbaa !5
  %19 = load i16, ptr %13, align 2, !tbaa !5
  %20 = zext i16 %19 to i32
  %21 = or i32 %20, 64
  %22 = trunc i32 %21 to i16
  store i16 %22, ptr %13, align 2, !tbaa !5
  %23 = load i16, ptr %13, align 2, !tbaa !5
  %24 = zext i16 %23 to i32
  %25 = or i32 %24, 32768
  %26 = trunc i32 %25 to i16
  store i16 %26, ptr %13, align 2, !tbaa !5
  %27 = load i16, ptr %13, align 2, !tbaa !5
  %28 = zext i16 %27 to i32
  %29 = or i32 %28, 2048
  %30 = trunc i32 %29 to i16
  store i16 %30, ptr %13, align 2, !tbaa !5
  %31 = load ptr, ptr %11, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %31, i64 9
  %33 = load ptr, ptr %11, align 8, !tbaa !10
  %34 = load i64, ptr %12, align 8, !tbaa !12
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %32, ptr align 1 %33, i64 %34, i1 false)
  %35 = load i16, ptr %13, align 2, !tbaa !5
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 255
  %38 = trunc i32 %37 to i8
  %39 = load ptr, ptr %11, align 8, !tbaa !10
  %40 = getelementptr inbounds i8, ptr %39, i64 0
  store i8 %38, ptr %40, align 1, !tbaa !9
  %41 = load i16, ptr %13, align 2, !tbaa !5
  %42 = zext i16 %41 to i32
  %43 = ashr i32 %42, 8
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %11, align 8, !tbaa !10
  %46 = getelementptr inbounds i8, ptr %45, i64 1
  store i8 %44, ptr %46, align 1, !tbaa !9
  %47 = load i8, ptr %10, align 1, !tbaa !9
  %48 = load ptr, ptr %11, align 8, !tbaa !10
  %49 = getelementptr inbounds i8, ptr %48, i64 2
  store i8 %47, ptr %49, align 1, !tbaa !9
  %50 = load i16, ptr %7, align 2, !tbaa !5
  %51 = zext i16 %50 to i32
  %52 = and i32 %51, 255
  %53 = trunc i32 %52 to i8
  %54 = load ptr, ptr %11, align 8, !tbaa !10
  %55 = getelementptr inbounds i8, ptr %54, i64 3
  store i8 %53, ptr %55, align 1, !tbaa !9
  %56 = load i16, ptr %7, align 2, !tbaa !5
  %57 = zext i16 %56 to i32
  %58 = ashr i32 %57, 8
  %59 = trunc i32 %58 to i8
  %60 = load ptr, ptr %11, align 8, !tbaa !10
  %61 = getelementptr inbounds i8, ptr %60, i64 4
  store i8 %59, ptr %61, align 1, !tbaa !9
  %62 = load i16, ptr %9, align 2, !tbaa !5
  %63 = zext i16 %62 to i32
  %64 = and i32 %63, 255
  %65 = trunc i32 %64 to i8
  %66 = load ptr, ptr %11, align 8, !tbaa !10
  %67 = getelementptr inbounds i8, ptr %66, i64 5
  store i8 %65, ptr %67, align 1, !tbaa !9
  %68 = load i16, ptr %9, align 2, !tbaa !5
  %69 = zext i16 %68 to i32
  %70 = ashr i32 %69, 8
  %71 = trunc i32 %70 to i8
  %72 = load ptr, ptr %11, align 8, !tbaa !10
  %73 = getelementptr inbounds i8, ptr %72, i64 6
  store i8 %71, ptr %73, align 1, !tbaa !9
  %74 = load i16, ptr %8, align 2, !tbaa !5
  %75 = zext i16 %74 to i32
  %76 = and i32 %75, 255
  %77 = trunc i32 %76 to i8
  %78 = load ptr, ptr %11, align 8, !tbaa !10
  %79 = getelementptr inbounds i8, ptr %78, i64 7
  store i8 %77, ptr %79, align 1, !tbaa !9
  %80 = load i16, ptr %8, align 2, !tbaa !5
  %81 = zext i16 %80 to i32
  %82 = ashr i32 %81, 8
  %83 = trunc i32 %82 to i8
  %84 = load ptr, ptr %11, align 8, !tbaa !10
  %85 = getelementptr inbounds i8, ptr %84, i64 8
  store i8 %83, ptr %85, align 1, !tbaa !9
  %86 = load i64, ptr %12, align 8, !tbaa !12
  %87 = add i64 %86, 9
  store i64 %87, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !14
  br label %88

88:                                               ; preds = %99, %6
  %89 = load i32, ptr %14, align 4, !tbaa !14
  %90 = icmp slt i32 %89, 2
  br i1 %90, label %92, label %91

91:                                               ; preds = %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %102

92:                                               ; preds = %88
  %93 = load ptr, ptr %11, align 8, !tbaa !10
  %94 = load i64, ptr %12, align 8, !tbaa !12
  %95 = load i32, ptr %14, align 4, !tbaa !14
  %96 = sext i32 %95 to i64
  %97 = add i64 %94, %96
  %98 = getelementptr inbounds i8, ptr %93, i64 %97
  store i8 0, ptr %98, align 1, !tbaa !9
  br label %99

99:                                               ; preds = %92
  %100 = load i32, ptr %14, align 4, !tbaa !14
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %14, align 4, !tbaa !14
  br label %88, !llvm.loop !16

102:                                              ; preds = %91
  %103 = load i64, ptr %12, align 8, !tbaa !12
  %104 = add i64 %103, 2
  store i64 %104, ptr %12, align 8, !tbaa !12
  %105 = load i64, ptr %12, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  ret i64 %105
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i64 @uwb_mac_encapsulate_frame(i16 noundef zeroext %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i8 noundef zeroext %3, ptr nocapture noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %4, i64 9
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %7, ptr align 1 %4, i64 %5, i1 false)
  store i8 65, ptr %4, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 -120, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %4, i64 2
  store i8 %3, ptr %9, align 1, !tbaa !5
  %10 = trunc i16 %0 to i8
  %11 = getelementptr inbounds i8, ptr %4, i64 3
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = lshr i16 %0, 8
  %13 = trunc nuw i16 %12 to i8
  %14 = getelementptr inbounds i8, ptr %4, i64 4
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = trunc i16 %2 to i8
  %16 = getelementptr inbounds i8, ptr %4, i64 5
  store i8 %15, ptr %16, align 1, !tbaa !5
  %17 = lshr i16 %2, 8
  %18 = trunc nuw i16 %17 to i8
  %19 = getelementptr inbounds i8, ptr %4, i64 6
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = trunc i16 %1 to i8
  %21 = getelementptr inbounds i8, ptr %4, i64 7
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = lshr i16 %1, 8
  %23 = trunc nuw i16 %22 to i8
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  store i8 %23, ptr %24, align 1, !tbaa !5
  %25 = getelementptr i8, ptr %4, i64 %5
  %26 = getelementptr i8, ptr %25, i64 9
  store i16 0, ptr %26, align 1
  %27 = add i64 %5, 11
  ret i64 %27
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 nounwind willreturn memory(argmem: readwrite) }

!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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass