; 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: mustprogress uwtable
define dso_local i32 @MessageRead(ptr noundef %0, ptr noundef %1) #0 {
  %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 6
  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 3
  store ptr %12, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call zeroext i1 @RingBufferIsEmpty(ptr noundef %13)
  br i1 %14, label %15, label %16

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

16:                                               ; preds = %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  call void @RingBufferDequeue(ptr noundef %17, ptr noundef %18)
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tagPacket, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds %struct.tagPacketPayload, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tagMessage, ptr %23, i32 0, i32 0
  store i8 %22, ptr %24, align 1, !tbaa !13
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.tagPacket, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.tagPacketPayload, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  %30 = and i32 %29, 1
  %31 = trunc i32 %30 to i8
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tagMessage, ptr %32, i32 0, i32 1
  store i8 %31, ptr %33, align 1, !tbaa !16
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tagPacket, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.tagPacketPayload, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 1, !tbaa !15
  %38 = zext i8 %37 to i32
  %39 = ashr i32 %38, 1
  %40 = and i32 %39, 1
  %41 = trunc i32 %40 to i8
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.tagMessage, ptr %42, i32 0, i32 2
  store i8 %41, ptr %43, align 1, !tbaa !17
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.tagPacket, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.tagPacketHeader, ptr %45, i32 0, i32 1
  %47 = load i8, ptr %46, align 1, !tbaa !18
  %48 = zext i8 %47 to i32
  %49 = sub nsw i32 %48, 2
  %50 = trunc i32 %49 to i8
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.tagMessage, ptr %51, i32 0, i32 3
  store i8 %50, ptr %52, align 1, !tbaa !19
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tagMessage, ptr %53, i32 0, i32 3
  %55 = load i8, ptr %54, align 1, !tbaa !19
  %56 = icmp ne i8 %55, 0
  br i1 %56, label %57, label %69

57:                                               ; preds = %16
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.tagMessage, ptr %58, i32 0, i32 4
  %60 = getelementptr inbounds [167 x i8], ptr %59, i64 0, i64 0
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tagPacket, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.tagPacketPayload, ptr %62, i32 0, i32 2
  %64 = getelementptr inbounds [167 x i8], ptr %63, i64 0, i64 0
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tagMessage, ptr %65, i32 0, i32 3
  %67 = load i8, ptr %66, align 1, !tbaa !19
  %68 = zext i8 %67 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 1 %64, i64 %68, i1 false)
  br label %69

69:                                               ; preds = %57, %16
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %70

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

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

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

declare void @RingBufferDequeue(ptr noundef, ptr noundef) #3

; 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) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_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 = !{!14, !7, i64 0}
!14 = !{!"_ZTS10tagMessage", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!15 = !{!10, !7, i64 4}
!16 = !{!14, !7, i64 1}
!17 = !{!14, !7, i64 2}
!18 = !{!10, !7, i64 2}
!19 = !{!14, !7, i64 3}


; 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 uwtable
define dso_local range(i32 0, 2) i32 @MessageRead(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 657
  %4 = tail call zeroext i1 @RingBufferIsEmpty(ptr noundef nonnull %3)
  br i1 %4, label %24, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 265
  tail call void @RingBufferDequeue(ptr noundef nonnull %3, ptr noundef nonnull %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 268
  %8 = load i8, ptr %7, align 1, !tbaa !5
  store i8 %8, ptr %1, align 1, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 269
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %11 = and i8 %10, 1
  %12 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %11, ptr %12, align 1, !tbaa !14
  %13 = lshr i8 %10, 1
  %14 = and i8 %13, 1
  %15 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %14, ptr %15, align 1, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 267
  %17 = load i8, ptr %16, align 1, !tbaa !16
  %18 = add i8 %17, -2
  %19 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %18, ptr %19, align 1, !tbaa !17
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %24, label %20

20:                                               ; preds = %5
  %21 = getelementptr inbounds i8, ptr %1, i64 4
  %22 = getelementptr inbounds i8, ptr %0, i64 270
  %23 = zext i8 %18 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %21, ptr nonnull align 1 %22, i64 %23, i1 false)
  br label %24

24:                                               ; preds = %5, %20, %2
  %.0 = phi i32 [ 1, %2 ], [ 0, %20 ], [ 0, %5 ]
  ret i32 %.0
}

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

declare void @RingBufferDequeue(ptr noundef, ptr noundef) local_unnamed_addr #2

; 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) #3

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


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