; 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 void @evthr_free(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

8:                                                ; preds = %1
  store i32 1, ptr %5, align 4
  br label %66

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.evthr_pool, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %struct.evthr_pool_slist, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %62, %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.evthr, ptr %18, i32 0, i32 14
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %17, %14
  %23 = phi i1 [ false, %14 ], [ true, %17 ]
  br i1 %23, label %24, label %64

24:                                               ; preds = %22
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.evthr, ptr %26, i32 0, i32 14
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %42

31:                                               ; preds = %25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.evthr, ptr %32, i32 0, i32 14
  %34 = getelementptr inbounds %struct.anon, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.evthr, ptr %36, i32 0, i32 14
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.evthr, ptr %39, i32 0, i32 14
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 1
  store ptr %35, ptr %41, align 8, !tbaa !16
  br label %50

42:                                               ; preds = %25
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.evthr, ptr %43, i32 0, i32 14
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.evthr_pool, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.evthr_pool_slist, ptr %48, i32 0, i32 1
  store ptr %46, ptr %49, align 8, !tbaa !17
  br label %50

50:                                               ; preds = %42, %31
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.evthr, ptr %51, i32 0, i32 14
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.evthr, ptr %55, i32 0, i32 14
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  store ptr %54, ptr %58, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @evthr_free(ptr noundef %61)
  br label %62

62:                                               ; preds = %60
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %63, ptr %3, align 8, !tbaa !5
  br label %14, !llvm.loop !18

64:                                               ; preds = %22
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %65) #3
  store i32 0, ptr %5, align 4
  br label %66

66:                                               ; preds = %64, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %67 = load i32, ptr %5, align 4
  switch i32 %67, label %69 [
    i32 0, label %68
    i32 1, label %68
  ]

68:                                               ; preds = %66, %66
  ret void

69:                                               ; preds = %66
  unreachable
}

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 "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, !6, i64 8}
!10 = !{!"evthr_pool", !11, i64 0, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"evthr_pool_slist", !6, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 192}
!14 = !{!"evthr", !11, i64 0, !11, i64 4, !11, i64 8, !11, 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, !15, i64 192}
!15 = !{!"", !6, i64 0, !6, i64 8}
!16 = !{!14, !6, i64 200}
!17 = !{!10, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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 void @evthr_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @evthr_pool_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %17, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not17 = icmp eq ptr %5, null
  br i1 %.not17, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = getelementptr inbounds i8, ptr %5, i64 192
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %.not1619 = icmp eq ptr %8, null
  br i1 %.not1619, label %.critedge.loopexit, label %.lr.ph21

.lr.ph21:                                         ; preds = %.lr.ph, %.lr.ph21
  %9 = phi ptr [ %14, %.lr.ph21 ], [ %8, %.lr.ph ]
  %.01820 = phi ptr [ %9, %.lr.ph21 ], [ %5, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.01820, i64 200
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %9, i64 200
  store ptr %11, ptr %12, align 8, !tbaa !15
  store ptr %9, ptr %11, align 8, !tbaa !16
  tail call void @evthr_free(ptr noundef nonnull %.01820)
  %13 = getelementptr inbounds i8, ptr %9, i64 192
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %.not16 = icmp eq ptr %14, null
  br i1 %.not16, label %.critedge.loopexit, label %.lr.ph21, !llvm.loop !17

.critedge.loopexit:                               ; preds = %.lr.ph21, %.lr.ph
  %.018.lcssa = phi ptr [ %5, %.lr.ph ], [ %9, %.lr.ph21 ]
  %.lcssa = phi ptr [ %8, %.lr.ph ], [ %14, %.lr.ph21 ]
  %15 = getelementptr inbounds i8, ptr %.018.lcssa, i64 200
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  store ptr %16, ptr %6, align 8, !tbaa !19
  store ptr %.lcssa, ptr %16, align 8, !tbaa !16
  tail call void @evthr_free(ptr noundef nonnull %.018.lcssa)
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %3
  tail call void @free(ptr noundef nonnull %0) #2
  br label %17

17:                                               ; preds = %1, %.critedge
  ret void
}

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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 }

!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, !11, i64 8}
!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 = !{!13, !11, i64 192}
!13 = !{!"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, !14, i64 192}
!14 = !{!"", !11, i64 0, !11, i64 8}
!15 = !{!13, !11, i64 200}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !11, i64 16}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass