; LLVM IR from ohler55/agoo :: ext/agoo (websocket)

; 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._agooText = type { ptr, i64, i64, %struct._agooAtom, i8, [8 x i8] }
%struct._agooAtom = type { ptr, %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { 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 ptr @agoo_ws_expand(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [16 x i8], align 16
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 0
  store ptr %7, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._agooText, ptr %8, i32 0, i32 4
  %10 = load i8, ptr %9, align 8, !tbaa !9, !range !14, !noundef !15
  %11 = trunc i8 %10 to i1
  %12 = zext i1 %11 to i64
  %13 = select i1 %11, i32 2, i32 1
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %5, align 1, !tbaa !16
  %15 = load i8, ptr %5, align 1, !tbaa !16
  %16 = zext i8 %15 to i32
  %17 = or i32 128, %16
  %18 = trunc i32 %17 to i8
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %4, align 8, !tbaa !5
  store i8 %18, ptr %19, align 1, !tbaa !16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._agooText, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !17
  %24 = icmp sge i64 125, %23
  br i1 %24, label %25, label %32

25:                                               ; preds = %1
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._agooText, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = trunc i64 %28 to i8
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i32 1
  store ptr %31, ptr %4, align 8, !tbaa !5
  store i8 %29, ptr %30, align 1, !tbaa !16
  br label %77

32:                                               ; preds = %1
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._agooText, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = icmp sge i64 65535, %35
  br i1 %36, label %37, label %55

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %4, align 8, !tbaa !5
  store i8 126, ptr %38, align 1, !tbaa !16
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._agooText, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !17
  %43 = ashr i64 %42, 8
  %44 = and i64 %43, 255
  %45 = trunc i64 %44 to i8
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %4, align 8, !tbaa !5
  store i8 %45, ptr %46, align 1, !tbaa !16
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._agooText, ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !17
  %51 = and i64 %50, 255
  %52 = trunc i64 %51 to i8
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %4, align 8, !tbaa !5
  store i8 %52, ptr %53, align 1, !tbaa !16
  br label %76

55:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %4, align 8, !tbaa !5
  store i8 127, ptr %56, align 1, !tbaa !16
  store i32 56, ptr %6, align 4, !tbaa !18
  br label %58

58:                                               ; preds = %72, %55
  %59 = load i32, ptr %6, align 4, !tbaa !18
  %60 = icmp sle i32 0, %59
  br i1 %60, label %61, label %75

61:                                               ; preds = %58
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._agooText, ptr %62, i32 0, i32 1
  %64 = load i64, ptr %63, align 8, !tbaa !17
  %65 = load i32, ptr %6, align 4, !tbaa !18
  %66 = zext i32 %65 to i64
  %67 = ashr i64 %64, %66
  %68 = and i64 %67, 255
  %69 = trunc i64 %68 to i8
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i32 1
  store ptr %71, ptr %4, align 8, !tbaa !5
  store i8 %69, ptr %70, align 1, !tbaa !16
  br label %72

72:                                               ; preds = %61
  %73 = load i32, ptr %6, align 4, !tbaa !18
  %74 = sub nsw i32 %73, 8
  store i32 %74, ptr %6, align 4, !tbaa !18
  br label %58, !llvm.loop !20

75:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %76

76:                                               ; preds = %75, %37
  br label %77

77:                                               ; preds = %76, %25
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 0
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds [16 x i8], ptr %3, i64 0, i64 0
  %82 = ptrtoint ptr %80 to i64
  %83 = ptrtoint ptr %81 to i64
  %84 = sub i64 %82, %83
  %85 = trunc i64 %84 to i32
  %86 = call ptr @agoo_text_prepend(ptr noundef %78, ptr noundef %79, i32 noundef %85)
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  ret ptr %86
}

declare ptr @agoo_text_prepend(ptr noundef, ptr noundef, i32 noundef) #2

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 = { "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 = { 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 = !{!10, !13, i64 72}
!10 = !{!"_agooText", !6, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !13, i64 72, !7, i64 73}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_agooAtom", !6, i64 0, !7, i64 8}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !11, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 ptr @agoo_ws_expand(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !13, !noundef !14
  %5 = trunc nuw i8 %4 to i1
  %6 = select i1 %5, i8 -126, i8 -127
  %7 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %6, ptr %2, align 16, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !16
  %10 = icmp slt i64 %9, 126
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %1
  %12 = icmp ult i64 %9, 65536
  %13 = getelementptr inbounds i8, ptr %2, i64 2
  %14 = getelementptr inbounds i8, ptr %2, i64 3
  br i1 %12, label %15, label %.loopexit.loopexit

15:                                               ; preds = %11
  store i8 126, ptr %7, align 1, !tbaa !15
  %16 = lshr i64 %9, 8
  %17 = trunc nuw i64 %16 to i8
  store i8 %17, ptr %13, align 2, !tbaa !15
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %11
  store i8 127, ptr %7, align 1, !tbaa !15
  %18 = lshr i64 %9, 56
  %19 = trunc nuw i64 %18 to i8
  store i8 %19, ptr %13, align 2, !tbaa !15
  %20 = lshr i64 %9, 48
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %21, ptr %14, align 1, !tbaa !15
  %23 = lshr i64 %9, 40
  %24 = trunc i64 %23 to i8
  %25 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %24, ptr %22, align 4, !tbaa !15
  %26 = lshr i64 %9, 32
  %27 = trunc i64 %26 to i8
  %28 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %27, ptr %25, align 1, !tbaa !15
  %29 = lshr i64 %9, 24
  %30 = trunc i64 %29 to i8
  %31 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %30, ptr %28, align 2, !tbaa !15
  %32 = lshr i64 %9, 16
  %33 = trunc i64 %32 to i8
  %34 = getelementptr inbounds i8, ptr %2, i64 8
  store i8 %33, ptr %31, align 1, !tbaa !15
  %35 = lshr i64 %9, 8
  %36 = trunc i64 %35 to i8
  %37 = getelementptr inbounds i8, ptr %2, i64 9
  store i8 %36, ptr %34, align 8, !tbaa !15
  br label %.loopexit

.loopexit:                                        ; preds = %1, %.loopexit.loopexit, %15
  %.sink26 = phi i32 [ 10, %.loopexit.loopexit ], [ 4, %15 ], [ 2, %1 ]
  %.sink25 = phi ptr [ %37, %.loopexit.loopexit ], [ %14, %15 ], [ %7, %1 ]
  %38 = trunc i64 %9 to i8
  store i8 %38, ptr %.sink25, align 1, !tbaa !15
  %39 = call ptr @agoo_text_prepend(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef %.sink26) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret ptr %39
}

declare ptr @agoo_text_prepend(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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 = { "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 = { 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, !12, i64 72}
!6 = !{!"_agooText", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 72, !8, i64 73}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_agooAtom", !7, i64 0, !8, i64 8}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass