; 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._agooReq = type { i32, ptr, i32, ptr, %struct._agooStr, %struct._agooStr, %struct._agooStr, %struct._agooStr, %struct._agooStr, [46 x i8], ptr, ptr, i64, [8 x i8] }
%struct._agooStr = type { ptr, i32 }

@up_con = external hidden constant [42 x i8], align 16
@.str = external hidden unnamed_addr constant [18 x i8], align 1
@ws_magic = external hidden constant [37 x i8], align 16
@ws_accept = external hidden constant [23 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@ws_protocol = external hidden constant [25 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_ws_add_headers(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca [1024 x i8], align 16
  %8 = alloca [32 x i8], align 16
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call ptr @agoo_text_append(ptr noundef %10, ptr noundef @up_con, i32 noundef 41)
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._agooReq, ptr %12, i32 0, i32 7
  %14 = getelementptr inbounds %struct._agooStr, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._agooReq, ptr %16, i32 0, i32 7
  %18 = getelementptr inbounds %struct._agooStr, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = call ptr @agoo_con_header_value(ptr noundef %15, i32 noundef %19, ptr noundef @.str, ptr noundef %5)
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr null, %20
  br i1 %21, label %22, label %58

22:                                               ; preds = %2
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = add i64 %24, 37
  %26 = icmp ult i64 %25, 1024
  br i1 %26, label %27, label %58

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 1024, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = add i64 %29, 37
  %31 = sub i64 %30, 1
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %9, align 4, !tbaa !9
  %33 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = call ptr @strncpy(ptr noundef %33, ptr noundef %34, i64 noundef %36) #4
  %38 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = call ptr @strcpy(ptr noundef %41, ptr noundef @ws_magic) #4
  %43 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  call void @sha1(ptr noundef %43, i64 noundef %45, ptr noundef %46)
  %47 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 0
  %48 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %49 = call i32 @b64_to(ptr noundef %47, i32 noundef 20, ptr noundef %48)
  store i32 %49, ptr %9, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call ptr @agoo_text_append(ptr noundef %50, ptr noundef @ws_accept, i32 noundef 22)
  store ptr %51, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = call ptr @agoo_text_append(ptr noundef %52, ptr noundef %53, i32 noundef %54)
  store ptr %55, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = call ptr @agoo_text_append(ptr noundef %56, ptr noundef @.str.1, i32 noundef 2)
  store ptr %57, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %7) #4
  br label %58

58:                                               ; preds = %27, %22, %2
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._agooReq, ptr %59, i32 0, i32 7
  %61 = getelementptr inbounds %struct._agooStr, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._agooReq, ptr %63, i32 0, i32 7
  %65 = getelementptr inbounds %struct._agooStr, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !15
  %67 = call ptr @agoo_con_header_value(ptr noundef %62, i32 noundef %66, ptr noundef @.str.2, ptr noundef %5)
  store ptr %67, ptr %6, align 8, !tbaa !5
  %68 = icmp ne ptr null, %67
  br i1 %68, label %69, label %78

69:                                               ; preds = %58
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = call ptr @agoo_text_append(ptr noundef %70, ptr noundef @ws_protocol, i32 noundef 24)
  store ptr %71, ptr %4, align 8, !tbaa !5
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = call ptr @agoo_text_append(ptr noundef %72, ptr noundef %73, i32 noundef %74)
  store ptr %75, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = call ptr @agoo_text_append(ptr noundef %76, ptr noundef @.str.1, i32 noundef 2)
  store ptr %77, ptr %4, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %69, %58
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret ptr %79
}

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

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

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

declare void @sha1(ptr noundef, i64 noundef, ptr noundef) #2

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

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"_agooReq", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 48, !13, i64 64, !13, i64 80, !13, i64 96, !7, i64 112, !6, i64 160, !6, i64 168, !14, i64 176, !7, i64 184}
!13 = !{!"_agooStr", !6, i64 0, !10, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !10, i64 88}


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

@up_con = external hidden constant [42 x i8], align 16
@.str = external hidden unnamed_addr constant [18 x i8], align 1
@ws_magic = external hidden constant [37 x i8], align 16
@ws_accept = external hidden constant [23 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@ws_protocol = external hidden constant [25 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_ws_add_headers(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca [1024 x i8], align 16
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  %6 = tail call ptr @agoo_text_append(ptr noundef %1, ptr noundef nonnull @up_con, i32 noundef 41) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %0, i64 88
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = call ptr @agoo_con_header_value(ptr noundef %8, i32 noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull %3) #4
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %27, label %12

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %14, 37
  %16 = icmp ult i64 %15, 1024
  br i1 %16, label %17, label %27

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  %18 = add i32 %13, 36
  %19 = call ptr @strncpy(ptr noundef nonnull %4, ptr noundef nonnull %11, i64 noundef %14) #4
  %20 = getelementptr inbounds i8, ptr %4, i64 %14
  %21 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %20, ptr noundef nonnull dereferenceable(1) @ws_magic) #4
  %22 = sext i32 %18 to i64
  call void @sha1(ptr noundef nonnull %4, i64 noundef %22, ptr noundef nonnull %5) #4
  %23 = call i32 @b64_to(ptr noundef nonnull %5, i32 noundef 20, ptr noundef nonnull %4) #4
  %24 = call ptr @agoo_text_append(ptr noundef %6, ptr noundef nonnull @ws_accept, i32 noundef 22) #4
  %25 = call ptr @agoo_text_append(ptr noundef %24, ptr noundef nonnull %4, i32 noundef %23) #4
  %26 = call ptr @agoo_text_append(ptr noundef %25, ptr noundef nonnull @.str.1, i32 noundef 2) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %4) #4
  br label %27

27:                                               ; preds = %17, %12, %2
  %.0 = phi ptr [ %26, %17 ], [ %6, %12 ], [ %6, %2 ]
  %28 = load ptr, ptr %7, align 8, !tbaa !9
  %29 = load i32, ptr %9, align 8, !tbaa !14
  %30 = call ptr @agoo_con_header_value(ptr noundef %28, i32 noundef %29, ptr noundef nonnull @.str.2, ptr noundef nonnull %3) #4
  %.not17 = icmp eq ptr %30, null
  br i1 %.not17, label %36, label %31

31:                                               ; preds = %27
  %32 = call ptr @agoo_text_append(ptr noundef %.0, ptr noundef nonnull @ws_protocol, i32 noundef 24) #4
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = call ptr @agoo_text_append(ptr noundef %32, ptr noundef nonnull %30, i32 noundef %33) #4
  %35 = call ptr @agoo_text_append(ptr noundef %34, ptr noundef nonnull @.str.1, i32 noundef 2) #4
  br label %36

36:                                               ; preds = %31, %27
  %.1 = phi ptr [ %35, %31 ], [ %.0, %27 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  ret ptr %.1
}

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

declare void @sha1(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

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

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 80}
!10 = !{!"_agooReq", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !12, i64 48, !12, i64 64, !12, i64 80, !12, i64 96, !7, i64 112, !11, i64 160, !11, i64 168, !13, i64 176, !7, i64 184}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_agooStr", !11, i64 0, !6, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !6, i64 88}


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