; LLVM IR from microbotsio/CodeCell :: src (shtp)

; 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.shtp_s = type { ptr, ptr, ptr, [8 x i8], i16, i16, [256 x i8], i16, i16, i8, [384 x i8], i16, i32, [384 x i8], i32, [5 x %struct.shtp_App_s], i8, i8, [5 x %struct.shtp_AppListener_s], [8 x %struct.shtp_Channel_s], [8 x %struct.shtp_ChanListener_s], i8, i32, i32, i32, i32, i32 }
%struct.shtp_App_s = type { i32, [32 x i8] }
%struct.shtp_AppListener_s = type { i16, ptr, ptr }
%struct.shtp_Channel_s = type { i8, i8, i32, [32 x i8], i8, ptr, ptr }
%struct.shtp_ChanListener_s = type { i16, [32 x i8], ptr, ptr }

; 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 i32 @shtp_send(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = 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 i16 %3, ptr %9, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %13, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !12
  %14 = load i16, ptr %9, align 2, !tbaa !10
  %15 = zext i16 %14 to i32
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.shtp_s, ptr %16, i32 0, i32 4
  %18 = load i16, ptr %17, align 8, !tbaa !14
  %19 = zext i16 %18 to i32
  %20 = icmp sgt i32 %15, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %39

22:                                               ; preds = %4
  %23 = load i8, ptr %7, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp sge i32 %24, 8
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.shtp_s, ptr %27, i32 0, i32 26
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = add i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !16
  store i32 -2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %39

31:                                               ; preds = %22
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i8, ptr %7, align 1, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i16, ptr %9, align 2, !tbaa !10
  %36 = zext i16 %35 to i32
  %37 = call i32 @txProcess(ptr noundef %32, i8 noundef zeroext %33, ptr noundef %34, i32 noundef %36)
  store i32 %37, ptr %11, align 4, !tbaa !12
  %38 = load i32, ptr %11, align 4, !tbaa !12
  store i32 %38, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %39

39:                                               ; preds = %31, %26, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %40 = load i32, ptr %5, align 4
  ret i32 %40
}

; Function Attrs: nounwind uwtable
declare hidden i32 @txProcess(ptr noundef, i8 noundef zeroext, ptr noundef, i32 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 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !11, i64 32}
!15 = !{!"shtp_s", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !11, i64 32, !11, i64 34, !7, i64 36, !11, i64 292, !11, i64 294, !7, i64 296, !7, i64 297, !11, i64 682, !13, i64 684, !7, i64 688, !13, i64 1072, !7, i64 1076, !7, i64 1256, !7, i64 1257, !7, i64 1264, !7, i64 1384, !7, i64 1896, !7, i64 2344, !13, i64 2348, !13, i64 2352, !13, i64 2356, !13, i64 2360, !13, i64 2364}
!16 = !{!15, !13, i64 2364}


; 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
define dso_local i32 @shtp_send(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = zext i16 %3 to i32
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i16, ptr %6, align 8, !tbaa !5
  %8 = icmp ult i16 %7, %3
  br i1 %8, label %17, label %9

9:                                                ; preds = %4
  %10 = icmp ugt i8 %1, 7
  br i1 %10, label %11, label %15

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 2364
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = add i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !12
  br label %17

15:                                               ; preds = %9
  %16 = tail call i32 @txProcess(ptr noundef nonnull %0, i8 noundef zeroext %1, ptr noundef %2, i32 noundef %5)
  br label %17

17:                                               ; preds = %4, %15, %11
  %.0 = phi i32 [ -2, %11 ], [ %16, %15 ], [ -2, %4 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @txProcess(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef) local_unnamed_addr #0

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

!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, !10, i64 32}
!6 = !{!"shtp_s", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !10, i64 32, !10, i64 34, !8, i64 36, !10, i64 292, !10, i64 294, !8, i64 296, !8, i64 297, !10, i64 682, !11, i64 684, !8, i64 688, !11, i64 1072, !8, i64 1076, !8, i64 1256, !8, i64 1257, !8, i64 1264, !8, i64 1384, !8, i64 1896, !8, i64 2344, !11, i64 2348, !11, i64 2352, !11, i64 2356, !11, i64 2360, !11, i64 2364}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 2364}


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