; LLVM IR from HANDS-FREE/OpenRE :: 4_Thirdparty/Dobot/ComPlatform (Message)

; 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.tagProtocolHandler = type { %struct.tagRingBuffer, %struct.tagRingBuffer, %struct.tagPacket, %struct.tagPacket, %struct.tagPacket, %struct.tagRingBuffer, %struct.tagRingBuffer }
%struct.tagPacket = type { %struct.tagPacketHeader, %struct.tagPacketPayload, i8 }
%struct.tagPacketHeader = type { [2 x i8], i8 }
%struct.tagPacketPayload = type { i8, i8, [167 x i8] }
%struct.tagRingBuffer = type <{ ptr, i32, i32, i8, i8, i32, i32, i32, i64, i64 }>
%struct.tagMessage = type { i8, i8, i8, i8, [167 x i8] }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @MessageWrite(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.tagProtocolHandler, ptr %9, i32 0, i32 5
  store ptr %10, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tagProtocolHandler, ptr %11, i32 0, i32 2
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call zeroext i1 @RingBufferIsFull(ptr noundef %13)
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tagMessage, ptr %17, i32 0, i32 3
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = add nsw i32 %20, 2
  %22 = trunc i32 %21 to i8
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tagPacket, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.tagPacketHeader, ptr %24, i32 0, i32 1
  store i8 %22, ptr %25, align 1, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tagMessage, ptr %26, i32 0, i32 0
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tagPacket, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.tagPacketPayload, ptr %30, i32 0, i32 0
  store i8 %28, ptr %31, align 1, !tbaa !16
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tagPacket, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %struct.tagPacketPayload, ptr %33, i32 0, i32 1
  store i8 0, ptr %34, align 1, !tbaa !17
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tagMessage, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 1, !tbaa !18
  %38 = zext i8 %37 to i32
  %39 = and i32 %38, 1
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tagPacket, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.tagPacketPayload, ptr %41, i32 0, i32 1
  %43 = load i8, ptr %42, align 1, !tbaa !17
  %44 = zext i8 %43 to i32
  %45 = or i32 %44, %39
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %42, align 1, !tbaa !17
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tagMessage, ptr %47, i32 0, i32 2
  %49 = load i8, ptr %48, align 1, !tbaa !19
  %50 = zext i8 %49 to i32
  %51 = shl i32 %50, 1
  %52 = and i32 %51, 2
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tagPacket, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.tagPacketPayload, ptr %54, i32 0, i32 1
  %56 = load i8, ptr %55, align 1, !tbaa !17
  %57 = zext i8 %56 to i32
  %58 = or i32 %57, %52
  %59 = trunc i32 %58 to i8
  store i8 %59, ptr %55, align 1, !tbaa !17
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.tagMessage, ptr %60, i32 0, i32 3
  %62 = load i8, ptr %61, align 1, !tbaa !9
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %64, label %76

64:                                               ; preds = %16
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tagPacket, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.tagPacketPayload, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds [167 x i8], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.tagMessage, ptr %69, i32 0, i32 4
  %71 = getelementptr inbounds [167 x i8], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.tagMessage, ptr %72, i32 0, i32 3
  %74 = load i8, ptr %73, align 1, !tbaa !9
  %75 = zext i8 %74 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %68, ptr align 1 %71, i64 %75, i1 false)
  br label %76

76:                                               ; preds = %64, %16
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  call void @RingBufferEnqueue(ptr noundef %77, ptr noundef %78)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %79

79:                                               ; preds = %76, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local zeroext i1 @RingBufferIsFull(ptr noundef) #3

declare void @RingBufferEnqueue(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 #4 = { "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 #5 = { 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++ TBAA"}
!9 = !{!10, !7, i64 3}
!10 = !{!"_ZTS10tagMessage", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!11 = !{!12, !7, i64 2}
!12 = !{!"_ZTS9tagPacket", !13, i64 0, !14, i64 3, !7, i64 172}
!13 = !{!"_ZTS15tagPacketHeader", !7, i64 0, !7, i64 2}
!14 = !{!"_ZTS16tagPacketPayload", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!10, !7, i64 0}
!16 = !{!12, !7, i64 3}
!17 = !{!12, !7, i64 4}
!18 = !{!10, !7, i64 1}
!19 = !{!10, !7, i64 2}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local range(i32 0, 3) i32 @MessageWrite(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 611
  %4 = getelementptr inbounds i8, ptr %0, i64 92
  %5 = tail call zeroext i1 @RingBufferIsFull(ptr noundef nonnull %3)
  br i1 %5, label %27, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 3
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = add i8 %8, 2
  %10 = getelementptr inbounds i8, ptr %0, i64 94
  store i8 %9, ptr %10, align 1, !tbaa !9
  %11 = load i8, ptr %1, align 1, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 95
  store i8 %11, ptr %12, align 1, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  %14 = getelementptr inbounds i8, ptr %1, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !15
  %16 = and i8 %15, 1
  %17 = getelementptr inbounds i8, ptr %1, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !16
  %19 = shl i8 %18, 1
  %20 = and i8 %19, 2
  %21 = or disjoint i8 %20, %16
  store i8 %21, ptr %13, align 1, !tbaa !17
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %26, label %22

22:                                               ; preds = %6
  %23 = getelementptr inbounds i8, ptr %0, i64 97
  %24 = getelementptr inbounds i8, ptr %1, i64 4
  %25 = zext i8 %8 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %23, ptr nonnull align 1 %24, i64 %25, i1 false)
  br label %26

26:                                               ; preds = %22, %6
  tail call void @RingBufferEnqueue(ptr noundef nonnull %3, ptr noundef nonnull %4)
  br label %27

27:                                               ; preds = %2, %26
  %.0 = phi i32 [ 0, %26 ], [ 2, %2 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local zeroext i1 @RingBufferIsFull(ptr noundef) local_unnamed_addr #2

declare void @RingBufferEnqueue(ptr noundef, ptr noundef) local_unnamed_addr #3

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

!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, !7, i64 3}
!6 = !{!"_ZTS10tagMessage", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 2}
!10 = !{!"_ZTS9tagPacket", !11, i64 0, !12, i64 3, !7, i64 172}
!11 = !{!"_ZTS15tagPacketHeader", !7, i64 0, !7, i64 2}
!12 = !{!"_ZTS16tagPacketPayload", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !7, i64 3}
!15 = !{!6, !7, i64 1}
!16 = !{!6, !7, i64 2}
!17 = !{!10, !7, i64 4}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass