; LLVM IR from pms67/HadesFCS :: Communication/UAVDataLink (UAVDataLink)

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @UAVDataLink_unpack(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [256 x i8], align 16
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %10) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i8, ptr %7, align 1, !tbaa !9
  %16 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 0
  %17 = call zeroext i8 @UAVDataLink_decodeCOBS(ptr noundef %14, i8 noundef zeroext %15, ptr noundef %16)
  %18 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 0
  %19 = load i8, ptr %18, align 16, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  store i8 %19, ptr %21, align 1, !tbaa !9
  %22 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 1
  store i8 %23, ptr %25, align 1, !tbaa !9
  %26 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 2
  %27 = load i8, ptr %26, align 2, !tbaa !9
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 2
  store i8 %27, ptr %29, align 1, !tbaa !9
  %30 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 3
  %31 = load i8, ptr %30, align 1, !tbaa !9
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 3
  store i8 %31, ptr %33, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  store i8 0, ptr %11, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  store i8 0, ptr %12, align 1, !tbaa !9
  br label %34

34:                                               ; preds = %64, %4
  %35 = load i8, ptr %12, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 3
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = icmp slt i32 %36, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  br label %67

43:                                               ; preds = %34
  %44 = load i8, ptr %12, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = add nsw i32 4, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load i8, ptr %12, align 1, !tbaa !9
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  store i8 %49, ptr %53, align 1, !tbaa !9
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i8, ptr %12, align 1, !tbaa !9
  %56 = zext i8 %55 to i64
  %57 = getelementptr inbounds i8, ptr %54, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = zext i8 %58 to i32
  %60 = load i8, ptr %11, align 1, !tbaa !9
  %61 = zext i8 %60 to i32
  %62 = xor i32 %61, %59
  %63 = trunc i32 %62 to i8
  store i8 %63, ptr %11, align 1, !tbaa !9
  br label %64

64:                                               ; preds = %43
  %65 = load i8, ptr %12, align 1, !tbaa !9
  %66 = add i8 %65, 1
  store i8 %66, ptr %12, align 1, !tbaa !9
  br label %34, !llvm.loop !10

67:                                               ; preds = %42
  %68 = load i8, ptr %11, align 1, !tbaa !9
  %69 = zext i8 %68 to i32
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 3
  %72 = load i8, ptr %71, align 1, !tbaa !9
  %73 = zext i8 %72 to i32
  %74 = add nsw i32 4, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [256 x i8], ptr %10, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !9
  %78 = zext i8 %77 to i32
  %79 = add nsw i32 %78, 1
  %80 = icmp eq i32 %69, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %67
  store i8 1, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %83

82:                                               ; preds = %67
  store i8 0, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %83

83:                                               ; preds = %82, %81
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr %10) #2
  %84 = load i8, ptr %5, align 1
  ret i8 %84
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @UAVDataLink_decodeCOBS(ptr noundef, i8 noundef zeroext, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @UAVDataLink_unpack(ptr noundef %0, i8 noundef zeroext %1, ptr nocapture noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %5) #2
  %6 = call zeroext i8 @UAVDataLink_decodeCOBS(ptr noundef %0, i8 noundef zeroext %1, ptr noundef nonnull %5)
  %7 = getelementptr inbounds i8, ptr %2, i64 3
  %8 = load <4 x i8>, ptr %5, align 16, !tbaa !5
  store <4 x i8> %8, ptr %2, align 1, !tbaa !5
  %9 = extractelement <4 x i8> %8, i64 3
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %10 = zext i8 %23 to i64
  %11 = zext i8 %22 to i32
  %12 = add nuw nsw i64 %10, 4
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %._crit_edge.loopexit
  %.017.lcssa = phi i32 [ %11, %._crit_edge.loopexit ], [ 0, %4 ]
  %.lcssa = phi i64 [ %12, %._crit_edge.loopexit ], [ 4, %4 ]
  %13 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %.lcssa
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = add nuw nsw i32 %15, 1
  %17 = icmp eq i32 %16, %.017.lcssa
  %. = zext i1 %17 to i8
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %5) #2
  ret i8 %.

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %4 ]
  %.01721 = phi i8 [ %22, %.lr.ph ], [ 0, %4 ]
  %18 = add nuw nsw i64 %indvars.iv, 4
  %19 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = xor i8 %20, %.01721
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i8, ptr %7, align 1, !tbaa !5
  %24 = zext i8 %23 to i64
  %25 = icmp ult i64 %indvars.iv.next, %24
  br i1 %25, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !8
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @UAVDataLink_decodeCOBS(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass