; 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_callbacks_s = type { ptr, ptr }
%struct.evhtp_callback_s = type { i32, ptr, i32, ptr, ptr, %union.anon.5, %struct.anon.6 }
%union.anon.5 = type { ptr }
%struct.anon.6 = 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @evhtp_callbacks_free(ptr noundef %0) #2 {
  %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 %64

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

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

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

21:                                               ; preds = %16, %13
  %22 = phi i1 [ false, %13 ], [ true, %16 ]
  br i1 %22, label %23, label %62

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.evhtp_callback_s, ptr %25, i32 0, i32 6
  %27 = getelementptr inbounds %struct.anon.6, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %41

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.evhtp_callback_s, ptr %31, i32 0, i32 6
  %33 = getelementptr inbounds %struct.anon.6, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.evhtp_callback_s, ptr %35, i32 0, i32 6
  %37 = getelementptr inbounds %struct.anon.6, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.evhtp_callback_s, ptr %38, i32 0, i32 6
  %40 = getelementptr inbounds %struct.anon.6, ptr %39, i32 0, i32 1
  store ptr %34, ptr %40, align 8, !tbaa !15
  br label %48

41:                                               ; preds = %24
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.evhtp_callback_s, ptr %42, i32 0, i32 6
  %44 = getelementptr inbounds %struct.anon.6, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.evhtp_callbacks_s, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !16
  br label %48

48:                                               ; preds = %41, %30
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.evhtp_callback_s, ptr %49, i32 0, i32 6
  %51 = getelementptr inbounds %struct.anon.6, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.evhtp_callback_s, ptr %53, i32 0, i32 6
  %55 = getelementptr inbounds %struct.anon.6, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  store ptr %52, ptr %56, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %48
  br label %58

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

60:                                               ; preds = %58
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %61, ptr %3, align 8, !tbaa !5
  br label %13, !llvm.loop !17

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

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

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

67:                                               ; preds = %64
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 0}
!10 = !{!"evhtp_callbacks_s", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 48}
!12 = !{!"evhtp_callback_s", !13, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !14, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8}
!15 = !{!12, !6, i64 56}
!16 = !{!10, !6, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

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

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

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

.critedge.loopexit:                               ; preds = %.lr.ph21, %.lr.ph
  %.018.lcssa = phi ptr [ %4, %.lr.ph ], [ %8, %.lr.ph21 ]
  %.lcssa = phi ptr [ %7, %.lr.ph ], [ %13, %.lr.ph21 ]
  %14 = getelementptr inbounds i8, ptr %.018.lcssa, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  store ptr %15, ptr %5, align 8, !tbaa !18
  store ptr %.lcssa, ptr %15, align 8, !tbaa !15
  tail call void @evhtp_callback_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 %16

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

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

attributes #0 = { 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 #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 0}
!6 = !{!"evhtp_callbacks_s", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 48}
!11 = !{!"evhtp_callback_s", !12, i64 0, !7, i64 8, !12, i64 16, !7, i64 24, !7, i64 32, !8, i64 40, !13, i64 48}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 8}
!14 = !{!11, !7, i64 56}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 8}


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