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

; 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.sockaddr_storage = type { i16, [118 x i8], i64 }
%struct.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }
%struct._agooCon = type { ptr, i32, ptr, ptr, i64, [46 x i8], [8192 x i8], i64, i64, i64, double, i8, i8, i8, ptr, ptr, ptr, %union.pthread_mutex_t, ptr, ptr, ptr }
%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 }
%struct.sockaddr_in6 = type { i16, i16, i32, %struct.in6_addr, i32 }
%struct.in6_addr = type { %union.anon }
%union.anon = type { [4 x i32] }

@con_timeout = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_con_create(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.sockaddr_storage, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %14 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 8408) #6
  store ptr %14, ptr %9, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %19

16:                                               ; preds = %4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i32 @agoo_err_memory(ptr noundef %17, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 65)
  br label %60

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 128, ptr %11, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = call i32 @getpeername(i32 noundef %20, ptr noundef %10, ptr noundef %11) #5
  %22 = getelementptr inbounds %struct.sockaddr_storage, ptr %10, i32 0, i32 0
  %23 = load i16, ptr %22, align 8, !tbaa !13
  %24 = zext i16 %23 to i32
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %26, label %33

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr %10, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sockaddr_in, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._agooCon, ptr %29, i32 0, i32 5
  %31 = getelementptr inbounds [46 x i8], ptr %30, i64 0, i64 0
  %32 = call ptr @inet_ntop(i32 noundef 2, ptr noundef %28, ptr noundef %31, i32 noundef 46) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %40

33:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store ptr %10, ptr %13, align 8, !tbaa !5
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.sockaddr_in6, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._agooCon, ptr %36, i32 0, i32 5
  %38 = getelementptr inbounds [46 x i8], ptr %37, i64 0, i64 0
  %39 = call ptr @inet_ntop(i32 noundef 10, ptr noundef %35, ptr noundef %38, i32 noundef 46) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %40

40:                                               ; preds = %33, %26
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._agooCon, ptr %42, i32 0, i32 1
  store i32 %41, ptr %43, align 8, !tbaa !16
  %44 = load i64, ptr %7, align 8, !tbaa !11
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._agooCon, ptr %45, i32 0, i32 4
  store i64 %44, ptr %46, align 8, !tbaa !20
  %47 = call double @dtime()
  %48 = load double, ptr @con_timeout, align 8, !tbaa !21
  %49 = fadd double %47, %48
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._agooCon, ptr %50, i32 0, i32 10
  store double %49, ptr %51, align 8, !tbaa !22
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._agooCon, ptr %53, i32 0, i32 2
  store ptr %52, ptr %54, align 8, !tbaa !23
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._agooCon, ptr %55, i32 0, i32 20
  store ptr null, ptr %56, align 8, !tbaa !24
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._agooCon, ptr %57, i32 0, i32 17
  %59 = call i32 @pthread_mutex_init(ptr noundef %58, ptr noundef null) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #5
  br label %60

60:                                               ; preds = %40, %16
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret ptr %61
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @getpeername(i32 noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @inet_ntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) #4

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

declare double @dtime() #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) #4

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 = { nounwind allocsize(0,1) "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"sockaddr_storage", !15, i64 0, !7, i64 2, !12, i64 120}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !10, i64 8}
!17 = !{!"_agooCon", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !7, i64 40, !7, i64 86, !12, i64 8280, !12, i64 8288, !12, i64 8296, !18, i64 8304, !19, i64 8312, !19, i64 8313, !19, i64 8314, !6, i64 8320, !6, i64 8328, !6, i64 8336, !7, i64 8344, !6, i64 8384, !6, i64 8392, !6, i64 8400}
!18 = !{!"double", !7, i64 0}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!17, !12, i64 32}
!21 = !{!18, !18, i64 0}
!22 = !{!17, !18, i64 8304}
!23 = !{!17, !6, i64 16}
!24 = !{!17, !6, i64 8400}


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

%struct.sockaddr_storage = type { i16, [118 x i8], i64 }

@con_timeout = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @agoo_con_create(ptr noundef %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.sockaddr_storage, align 8
  %6 = alloca i32, align 4
  %7 = tail call noalias dereferenceable_or_null(8408) ptr @calloc(i64 noundef 1, i64 noundef 8408) #5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %4
  %10 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 65) #6
  br label %27

11:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  store i32 128, ptr %6, align 4, !tbaa !5
  %12 = call i32 @getpeername(i32 noundef %1, ptr noundef nonnull %5, ptr noundef nonnull %6) #6
  %13 = load i16, ptr %5, align 8, !tbaa !9
  %14 = icmp eq i16 %13, 2
  %15 = getelementptr inbounds i8, ptr %7, i64 40
  %.17 = select i1 %14, i32 2, i32 10
  %..sroa.sel.v = select i1 %14, i64 4, i64 8
  %..sroa.sel = getelementptr inbounds i8, ptr %5, i64 %..sroa.sel.v
  %16 = call ptr @inet_ntop(i32 noundef %.17, ptr noundef nonnull %..sroa.sel, ptr noundef nonnull %15, i32 noundef 46) #6
  %17 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 %1, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %7, i64 32
  store i64 %2, ptr %18, align 8, !tbaa !18
  %19 = call double @dtime() #6
  %20 = load double, ptr @con_timeout, align 8, !tbaa !19
  %21 = fadd double %19, %20
  %22 = getelementptr inbounds i8, ptr %7, i64 8304
  store double %21, ptr %22, align 8, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %3, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %7, i64 8400
  store ptr null, ptr %24, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %7, i64 8344
  %26 = call i32 @pthread_mutex_init(ptr noundef nonnull %25, ptr noundef null) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #6
  br label %27

27:                                               ; preds = %11, %9
  ret ptr %7
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @getpeername(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare ptr @inet_ntop(i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

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

declare double @dtime() local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) local_unnamed_addr #4

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #5 = { nounwind allocsize(0,1) }
attributes #6 = { 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 0}
!10 = !{!"sockaddr_storage", !11, i64 0, !7, i64 2, !12, i64 120}
!11 = !{!"short", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_agooCon", !15, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !12, i64 32, !7, i64 40, !7, i64 86, !12, i64 8280, !12, i64 8288, !12, i64 8296, !16, i64 8304, !17, i64 8312, !17, i64 8313, !17, i64 8314, !15, i64 8320, !15, i64 8328, !15, i64 8336, !7, i64 8344, !15, i64 8384, !15, i64 8392, !15, i64 8400}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!14, !12, i64 32}
!19 = !{!16, !16, i64 0}
!20 = !{!14, !16, i64 8304}
!21 = !{!14, !15, i64 16}
!22 = !{!14, !15, i64 8400}


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