; LLVM IR from buaazp/zimg :: deps/libevhtp (evthr)

; 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.evthr = type { i32, i32, i32, i32, i8, ptr, ptr, %union.pthread_mutex_t, %union.pthread_mutex_t, %union.pthread_mutex_t, ptr, ptr, ptr, ptr, %struct.anon }
%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.anon = 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 @evthr_new(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [2 x i32], align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %9 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %10 = call i32 @evutil_socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef %9)
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

13:                                               ; preds = %2
  %14 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = call i32 @evutil_make_socket_nonblocking(i32 noundef %15)
  %17 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = call i32 @evutil_make_socket_nonblocking(i32 noundef %18)
  %20 = call noalias ptr @calloc(i64 noundef 208, i64 noundef 1) #7
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %13
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

23:                                               ; preds = %13
  %24 = call noalias ptr @malloc(i64 noundef 8) #8
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.evthr, ptr %25, i32 0, i32 10
  store ptr %24, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.evthr, ptr %28, i32 0, i32 11
  store ptr %27, ptr %29, align 8, !tbaa !14
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.evthr, ptr %31, i32 0, i32 12
  store ptr %30, ptr %32, align 8, !tbaa !15
  %33 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 0
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.evthr, ptr %35, i32 0, i32 2
  store i32 %34, ptr %36, align 8, !tbaa !16
  %37 = getelementptr inbounds [2 x i32], ptr %7, i64 0, i64 1
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.evthr, ptr %39, i32 0, i32 3
  store i32 %38, ptr %40, align 4, !tbaa !17
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.evthr, ptr %41, i32 0, i32 7
  %43 = call i32 @pthread_mutex_init(ptr noundef %42, ptr noundef null) #6
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %23
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @evthr_free(ptr noundef %46)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

47:                                               ; preds = %23
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.evthr, ptr %48, i32 0, i32 8
  %50 = call i32 @pthread_mutex_init(ptr noundef %49, ptr noundef null) #6
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  call void @evthr_free(ptr noundef %53)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

54:                                               ; preds = %47
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.evthr, ptr %55, i32 0, i32 9
  %57 = call i32 @pthread_mutex_init(ptr noundef %56, ptr noundef null) #6
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %54
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  call void @evthr_free(ptr noundef %60)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

61:                                               ; preds = %54
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %62, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %61, %59, %52, %45, %22, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %64 = load ptr, ptr %3, align 8
  ret ptr %64
}

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

declare i32 @evutil_make_socket_nonblocking(i32 noundef) #2

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @evthr_free(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 = { "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 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 #4 = { nounwind allocsize(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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind allocsize(0) }

!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 160}
!12 = !{!"evthr", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 80, !7, i64 120, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !13, i64 192}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!12, !6, i64 168}
!15 = !{!12, !6, i64 176}
!16 = !{!12, !10, i64 8}
!17 = !{!12, !10, i64 12}


; 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 noundef ptr @evthr_new(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [2 x i32], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  %4 = call i32 @evutil_socketpair(i32 noundef 1, i32 noundef 1, i32 noundef 0, ptr noundef nonnull %3) #6
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %28, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %3, align 8, !tbaa !5
  %8 = call i32 @evutil_make_socket_nonblocking(i32 noundef %7) #6
  %9 = getelementptr inbounds i8, ptr %3, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = call i32 @evutil_make_socket_nonblocking(i32 noundef %10) #6
  %12 = call noalias dereferenceable_or_null(208) ptr @calloc(i64 noundef 208, i64 noundef 1) #7
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %28, label %13

13:                                               ; preds = %6
  %14 = call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #8
  %15 = getelementptr inbounds i8, ptr %12, i64 160
  store ptr %14, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %12, i64 168
  store ptr %0, ptr %16, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %12, i64 176
  store ptr %1, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %12, i64 8
  %19 = load <2 x i32>, ptr %3, align 8, !tbaa !5
  store <2 x i32> %19, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %12, i64 40
  %21 = call i32 @pthread_mutex_init(ptr noundef nonnull %20, ptr noundef null) #6
  %.not16 = icmp eq i32 %21, 0
  br i1 %.not16, label %22, label %.sink.split

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %12, i64 80
  %24 = call i32 @pthread_mutex_init(ptr noundef nonnull %23, ptr noundef null) #6
  %.not17 = icmp eq i32 %24, 0
  br i1 %.not17, label %25, label %.sink.split

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %12, i64 120
  %27 = call i32 @pthread_mutex_init(ptr noundef nonnull %26, ptr noundef null) #6
  %.not18 = icmp eq i32 %27, 0
  br i1 %.not18, label %28, label %.sink.split

.sink.split:                                      ; preds = %25, %22, %13
  call void @evthr_free(ptr noundef nonnull %12)
  br label %28

28:                                               ; preds = %.sink.split, %25, %6, %2
  %.0 = phi ptr [ null, %2 ], [ null, %6 ], [ %12, %25 ], [ null, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  ret ptr %.0
}

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

declare i32 @evutil_make_socket_nonblocking(i32 noundef) local_unnamed_addr #2

; 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 #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare dso_local void @evthr_free(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 = { "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 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind allocsize(0) }

!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 160}
!10 = !{!"evthr", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 80, !7, i64 120, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !12, i64 192}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!10, !11, i64 168}
!14 = !{!10, !11, i64 176}


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