; 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_cmd = type <{ i8, 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: inlinehint nounwind uwtable
declare dso_local void @evthr_inc_backlog(ptr noundef) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @evthr_get_backlog(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @evthr_defer(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.evthr_cmd, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 17, ptr %9) #5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @evthr_get_backlog(ptr noundef %11)
  store i32 %12, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.evthr, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %26

17:                                               ; preds = %3
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.evthr, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp sgt i32 %19, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %17
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %56

25:                                               ; preds = %17
  br label %26

26:                                               ; preds = %25, %3
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 4, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %56

30:                                               ; preds = %26
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.evthr_cmd, ptr %9, i32 0, i32 2
  store ptr %31, ptr %32, align 1, !tbaa !14
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.evthr_cmd, ptr %9, i32 0, i32 1
  store ptr %33, ptr %34, align 1, !tbaa !16
  %35 = load i8, ptr %9, align 1
  %36 = and i8 %35, -2
  %37 = or i8 %36, 0
  store i8 %37, ptr %9, align 1
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.evthr, ptr %38, i32 0, i32 9
  %40 = call i32 @pthread_mutex_lock(ptr noundef %39) #5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  call void @evthr_inc_backlog(ptr noundef %41)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.evthr, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = call i64 @send(i32 noundef %44, ptr noundef %9, i64 noundef 17, i32 noundef 0)
  %46 = icmp sle i64 %45, 0
  br i1 %46, label %47, label %52

47:                                               ; preds = %30
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  call void @evthr_dec_backlog(ptr noundef %48)
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.evthr, ptr %49, i32 0, i32 9
  %51 = call i32 @pthread_mutex_unlock(ptr noundef %50) #5
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %56

52:                                               ; preds = %30
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.evthr, ptr %53, i32 0, i32 9
  %55 = call i32 @pthread_mutex_unlock(ptr noundef %54) #5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %56

56:                                               ; preds = %52, %47, %29, %24
  call void @llvm.lifetime.end.p0(i64 17, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %57 = load i32, ptr %4, align 4
  ret i32 %57
}

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #3

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #4

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #3

attributes #0 = { inlinehint 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 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 #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 = { "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 }

!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, !10, i64 4}
!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 = !{!15, !6, i64 9}
!15 = !{!"evthr_cmd", !7, i64 0, !6, i64 1, !6, i64 9}
!16 = !{!15, !6, i64 1}
!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"

%struct.evthr_cmd = type <{ i8, ptr, ptr }>

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

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

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @evthr_get_backlog(ptr noundef) local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 5) i32 @evthr_defer(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.evthr_cmd, align 1
  call void @llvm.lifetime.start.p0(i64 17, ptr nonnull %4) #5
  %5 = tail call i32 @evthr_get_backlog(ptr noundef %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  %.not14 = icmp slt i32 %5, %7
  %or.cond = select i1 %.not, i1 true, i1 %.not14
  br i1 %or.cond, label %8, label %21

8:                                                ; preds = %3
  %9 = icmp eq i32 %5, -1
  br i1 %9, label %21, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %4, i64 9
  store ptr %1, ptr %11, align 1, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  store ptr %2, ptr %12, align 1, !tbaa !14
  store i8 0, ptr %4, align 1
  %13 = getelementptr inbounds i8, ptr %0, i64 120
  %14 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %13) #5
  tail call void @evthr_inc_backlog(ptr noundef nonnull %0)
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = call i64 @send(i32 noundef %16, ptr noundef nonnull %4, i64 noundef 17, i32 noundef 0) #5
  %18 = icmp slt i64 %17, 1
  br i1 %18, label %19, label %.sink.split

19:                                               ; preds = %10
  call void @evthr_dec_backlog(ptr noundef nonnull %0)
  br label %.sink.split

.sink.split:                                      ; preds = %10, %19
  %.0.ph = phi i32 [ 2, %19 ], [ 0, %10 ]
  %20 = call i32 @pthread_mutex_unlock(ptr noundef nonnull %13) #5
  br label %21

21:                                               ; preds = %.sink.split, %8, %3
  %.0 = phi i32 [ 1, %3 ], [ 4, %8 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 17, ptr nonnull %4) #5
  ret i32 %.0
}

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #3

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #3

attributes #0 = { inlinehint 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 = { 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 #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 = { "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 }

!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 4}
!6 = !{!"evthr", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16, !10, i64 24, !10, i64 32, !8, i64 40, !8, i64 80, !8, i64 120, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !11, i64 192}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 8}
!12 = !{!13, !10, i64 9}
!13 = !{!"evthr_cmd", !8, i64 0, !10, i64 1, !10, i64 9}
!14 = !{!13, !10, i64 1}
!15 = !{!6, !7, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass