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

; 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.evhtp_connection_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.timeval, %struct.timeval, i32, i8, i8, i8, ptr, i64, i64, i64, i32, i8, i8, ptr, %struct.anon.0 }
%struct.timeval = type { i64, i64 }
%struct.anon.0 = type { ptr, ptr }
%struct.evhtp_request_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i16, i32, i32, i32, ptr, ptr, i32, %struct.anon }
%struct.anon = type { ptr, ptr }

declare i32 @bufferevent_disable(ptr noundef, i16 noundef signext) #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
declare dso_local ptr @evhtp_connection_get_bev(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @evhtp_unset_all_hooks(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @evhtp_connection_take_ownership(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = call ptr @evhtp_connection_get_bev(ptr noundef %4)
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.evhtp_connection_s, ptr %6, i32 0, i32 5
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.evhtp_connection_s, ptr %11, i32 0, i32 5
  %13 = call i32 @evhtp_unset_all_hooks(ptr noundef %12)
  br label %14

14:                                               ; preds = %10, %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.evhtp_connection_s, ptr %15, i32 0, i32 15
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %32

19:                                               ; preds = %14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.evhtp_connection_s, ptr %20, i32 0, i32 15
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds %struct.evhtp_request_s, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %32

26:                                               ; preds = %19
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.evhtp_connection_s, ptr %27, i32 0, i32 15
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = getelementptr inbounds %struct.evhtp_request_s, ptr %29, i32 0, i32 2
  %31 = call i32 @evhtp_unset_all_hooks(ptr noundef %30)
  br label %32

32:                                               ; preds = %26, %19, %14
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @evhtp_connection_set_bev(ptr noundef %33, ptr noundef null)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.evhtp_connection_s, ptr %34, i32 0, i32 13
  store i8 0, ptr %35, align 1, !tbaa !19
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call i32 @bufferevent_disable(ptr noundef %36, i16 noundef signext 2)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @bufferevent_setcb(ptr noundef %38, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %39
}

; Function Attrs: nounwind uwtable
declare dso_local void @evhtp_connection_set_bev(ptr noundef, ptr noundef) #2

declare void @bufferevent_setcb(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

attributes #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 }

!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 40}
!10 = !{!"evhtp_connection_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !11, i64 88, !13, i64 104, !7, i64 108, !7, i64 109, !7, i64 110, !6, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !13, i64 144, !7, i64 148, !7, i64 149, !6, i64 152, !14, i64 160}
!11 = !{!"timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8}
!15 = !{!10, !6, i64 112}
!16 = !{!17, !6, i64 16}
!17 = !{!"evhtp_request_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !13, i64 64, !13, i64 68, !18, i64 72, !13, i64 76, !13, i64 80, !13, i64 84, !6, i64 88, !6, i64 96, !13, i64 104, !14, i64 112}
!18 = !{!"short", !7, i64 0}
!19 = !{!10, !7, i64 109}


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

declare i32 @bufferevent_disable(ptr noundef, i16 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @evhtp_connection_get_bev(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @evhtp_unset_all_hooks(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @evhtp_connection_take_ownership(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call ptr @evhtp_connection_get_bev(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %7, label %5

5:                                                ; preds = %1
  %6 = tail call i32 @evhtp_unset_all_hooks(ptr noundef nonnull %3)
  br label %7

7:                                                ; preds = %5, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %.not11 = icmp eq ptr %9, null
  br i1 %.not11, label %15, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %.not12 = icmp eq ptr %12, null
  br i1 %.not12, label %15, label %13

13:                                               ; preds = %10
  %14 = tail call i32 @evhtp_unset_all_hooks(ptr noundef nonnull %11)
  br label %15

15:                                               ; preds = %13, %10, %7
  tail call void @evhtp_connection_set_bev(ptr noundef nonnull %0, ptr noundef null)
  %16 = getelementptr inbounds i8, ptr %0, i64 109
  store i8 0, ptr %16, align 1, !tbaa !18
  %17 = tail call i32 @bufferevent_disable(ptr noundef %2, i16 noundef signext 2) #2
  tail call void @bufferevent_setcb(ptr noundef %2, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null) #2
  ret ptr %2
}

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

declare void @bufferevent_setcb(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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 40}
!6 = !{!"evhtp_connection_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !10, i64 72, !10, i64 88, !12, i64 104, !8, i64 108, !8, i64 109, !8, i64 110, !7, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !12, i64 144, !8, i64 148, !8, i64 149, !7, i64 152, !13, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"timeval", !11, i64 0, !11, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 8}
!14 = !{!6, !7, i64 112}
!15 = !{!16, !7, i64 16}
!16 = !{!"evhtp_request_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !12, i64 64, !12, i64 68, !17, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !7, i64 88, !7, i64 96, !12, i64 104, !13, i64 112}
!17 = !{!"short", !8, i64 0}
!18 = !{!6, !8, i64 109}


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