; 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_pool = type { i32, %struct.evthr_pool_slist }
%struct.evthr_pool_slist = type { ptr, ptr }
%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
declare dso_local ptr @evthr_new(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @evthr_pool_free(ptr noundef) #1

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

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %79

15:                                               ; preds = %3
  %16 = call noalias ptr @calloc(i64 noundef 24, i64 noundef 1) #4
  store ptr %16, ptr %8, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %79

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.evthr_pool, ptr %21, i32 0, i32 0
  store i32 %20, ptr %22, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.evthr_pool, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.evthr_pool_slist, ptr %25, i32 0, i32 0
  store ptr null, ptr %26, align 8, !tbaa !14
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.evthr_pool, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.evthr_pool_slist, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.evthr_pool, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.evthr_pool_slist, ptr %31, i32 0, i32 1
  store ptr %29, ptr %32, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %23
  br label %34

34:                                               ; preds = %33
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %74, %34
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %39, label %77

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = call ptr @evthr_new(ptr noundef %40, ptr noundef %41)
  store ptr %42, ptr %11, align 8, !tbaa !9
  %43 = icmp ne ptr %42, null
  br i1 %43, label %46, label %44

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  call void @evthr_pool_free(ptr noundef %45)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %71

46:                                               ; preds = %39
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.evthr, ptr %48, i32 0, i32 14
  %50 = getelementptr inbounds %struct.anon, ptr %49, i32 0, i32 0
  store ptr null, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.evthr_pool, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.evthr_pool_slist, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %11, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.evthr, ptr %55, i32 0, i32 14
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 1
  store ptr %54, ptr %57, align 8, !tbaa !19
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.evthr_pool, ptr %59, i32 0, i32 1
  %61 = getelementptr inbounds %struct.evthr_pool_slist, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  store ptr %58, ptr %62, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.evthr, ptr %63, i32 0, i32 14
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.evthr_pool, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds %struct.evthr_pool_slist, ptr %67, i32 0, i32 1
  store ptr %65, ptr %68, align 8, !tbaa !15
  br label %69

69:                                               ; preds = %47
  br label %70

70:                                               ; preds = %69
  store i32 0, ptr %10, align 4
  br label %71

71:                                               ; preds = %70, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %72 = load i32, ptr %10, align 4
  switch i32 %72, label %79 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %9, align 4, !tbaa !5
  br label %35, !llvm.loop !20

77:                                               ; preds = %35
  %78 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %78, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %79

79:                                               ; preds = %77, %71, %18, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %80 = load ptr, ptr %4, align 8
  ret ptr %80
}

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 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 = { nounwind }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"evthr_pool", !6, i64 0, !13, i64 8}
!13 = !{!"evthr_pool_slist", !10, i64 0, !10, i64 8}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!17, !10, i64 192}
!17 = !{!"evthr", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !7, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 80, !7, i64 120, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !18, i64 192}
!18 = !{!"", !10, i64 0, !10, i64 8}
!19 = !{!17, !10, i64 200}
!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: nounwind uwtable
declare dso_local ptr @evthr_new(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @evthr_pool_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @evthr_pool_new(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %0, 0
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = tail call noalias dereferenceable_or_null(24) ptr @calloc(i64 noundef 24, i64 noundef 1) #2
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.loopexit, label %7

7:                                                ; preds = %5
  store i32 %0, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !12
  %10 = icmp sgt i32 %0, 0
  br i1 %10, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7, %12
  %.02227 = phi i32 [ %16, %12 ], [ 0, %7 ]
  %11 = tail call ptr @evthr_new(ptr noundef %1, ptr noundef %2)
  %.not26.not = icmp eq ptr %11, null
  br i1 %.not26.not, label %.thread, label %12

.thread:                                          ; preds = %.lr.ph
  tail call void @evthr_pool_free(ptr noundef nonnull %6)
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %11, i64 192
  store ptr null, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %9, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %11, i64 200
  store ptr %14, ptr %15, align 8, !tbaa !16
  store ptr %11, ptr %14, align 8, !tbaa !17
  store ptr %13, ptr %9, align 8, !tbaa !12
  %16 = add nuw nsw i32 %.02227, 1
  %exitcond.not = icmp eq i32 %16, %0
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !18

.loopexit:                                        ; preds = %12, %7, %.thread, %5, %3
  %.2 = phi ptr [ null, %3 ], [ null, %5 ], [ null, %.thread ], [ %6, %7 ], [ %6, %12 ]
  ret ptr %.2
}

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 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 #2 = { 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, !7, i64 0}
!6 = !{!"evthr_pool", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"evthr_pool_slist", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!14, !11, i64 192}
!14 = !{!"evthr", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !11, i64 24, !11, i64 32, !8, i64 40, !8, i64 80, !8, i64 120, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !15, i64 192}
!15 = !{!"", !11, i64 0, !11, i64 8}
!16 = !{!14, !11, i64 200}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass