; 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_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 }
%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 }

@.str.52 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare i64 @evbuffer_get_length(ptr noundef) #2

declare i32 @evbuffer_add(ptr noundef, ptr noundef, i64 noundef) #2

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

16:                                               ; preds = %2
  store i32 1, ptr %6, align 4
  br label %45

17:                                               ; preds = %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.evhtp_request_s, ptr %18, i32 0, i32 13
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i64 @evbuffer_get_length(ptr noundef %24)
  %26 = trunc i64 %25 to i32
  %27 = call i32 (ptr, ptr, ...) @evbuffer_add_printf(ptr noundef %23, ptr noundef @.str.52, i32 noundef %26)
  br label %28

28:                                               ; preds = %22, %17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @evhtp_send_reply_body(ptr noundef %29, ptr noundef %30)
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.evhtp_request_s, ptr %31, i32 0, i32 13
  %33 = load i32, ptr %32, align 4, !tbaa !18
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %28
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i32 @evbuffer_add(ptr noundef %36, ptr noundef @.str.53, i64 noundef 2)
  br label %38

38:                                               ; preds = %35, %28
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.evhtp_request_s, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.evhtp_connection_s, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = call i32 @bufferevent_flush(ptr noundef %43, i16 noundef signext 4, i32 noundef 1)
  store i32 0, ptr %6, align 4
  br label %45

45:                                               ; preds = %38, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %46 = load i32, ptr %6, align 4
  switch i32 %46, label %48 [
    i32 0, label %47
    i32 1, label %47
  ]

47:                                               ; preds = %45, %45
  ret void

48:                                               ; preds = %45
  unreachable
}

declare ptr @bufferevent_get_output(ptr noundef) #2

declare i32 @evbuffer_add_printf(ptr noundef, ptr noundef, ...) #2

declare i32 @bufferevent_flush(ptr noundef, i16 noundef signext, i32 noundef) #2

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 }

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


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

@.str.52 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare i64 @evbuffer_get_length(ptr noundef) local_unnamed_addr #1

declare i32 @evbuffer_add(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @evhtp_send_reply_chunk(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %7 = tail call ptr @bufferevent_get_output(ptr noundef %6) #2
  %8 = tail call i64 @evbuffer_get_length(ptr noundef %1) #2
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %26, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 84
  %12 = load i32, ptr %11, align 4, !tbaa !17
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %17, label %13

13:                                               ; preds = %10
  %14 = tail call i64 @evbuffer_get_length(ptr noundef %1) #2
  %15 = trunc i64 %14 to i32
  %16 = tail call i32 (ptr, ptr, ...) @evbuffer_add_printf(ptr noundef %7, ptr noundef nonnull @.str.52, i32 noundef %15) #2
  br label %17

17:                                               ; preds = %13, %10
  tail call void @evhtp_send_reply_body(ptr noundef nonnull %0, ptr noundef %1)
  %18 = load i32, ptr %11, align 4, !tbaa !17
  %.not10 = icmp eq i32 %18, 0
  br i1 %.not10, label %21, label %19

19:                                               ; preds = %17
  %20 = tail call i32 @evbuffer_add(ptr noundef %7, ptr noundef nonnull @.str.53, i64 noundef 2) #2
  br label %21

21:                                               ; preds = %19, %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = tail call i32 @bufferevent_flush(ptr noundef %24, i16 noundef signext 4, i32 noundef 1) #2
  br label %26

26:                                               ; preds = %2, %21
  ret void
}

declare ptr @bufferevent_get_output(ptr noundef) local_unnamed_addr #1

declare i32 @evbuffer_add_printf(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare i32 @bufferevent_flush(ptr noundef, i16 noundef signext, i32 noundef) local_unnamed_addr #1

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


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