; 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_kv_s = type { ptr, ptr, i64, i64, i8, i8, %struct.anon.1 }
%struct.anon.1 = 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: nounwind uwtable
define dso_local ptr @evhtp_kv_new(ptr noundef %0, ptr noundef %1, i8 noundef signext %2, i8 noundef signext %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %14 = call noalias ptr @malloc(i64 noundef 56) #6
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %103

17:                                               ; preds = %4
  %18 = load i8, ptr %8, align 1, !tbaa !9
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.evhtp_kv_s, ptr %19, i32 0, i32 4
  store i8 %18, ptr %20, align 8, !tbaa !10
  %21 = load i8, ptr %9, align 1, !tbaa !9
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.evhtp_kv_s, ptr %22, i32 0, i32 5
  store i8 %21, ptr %23, align 1, !tbaa !14
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.evhtp_kv_s, ptr %24, i32 0, i32 2
  store i64 0, ptr %25, align 8, !tbaa !15
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.evhtp_kv_s, ptr %26, i32 0, i32 3
  store i64 0, ptr %27, align 8, !tbaa !16
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.evhtp_kv_s, ptr %28, i32 0, i32 0
  store ptr null, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.evhtp_kv_s, ptr %30, i32 0, i32 1
  store ptr null, ptr %31, align 8, !tbaa !18
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %66

34:                                               ; preds = %17
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call i64 @strlen(ptr noundef %35) #7
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.evhtp_kv_s, ptr %37, i32 0, i32 2
  store i64 %36, ptr %38, align 8, !tbaa !15
  %39 = load i8, ptr %8, align 1, !tbaa !9
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %61

42:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.evhtp_kv_s, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = add i64 %45, 1
  %47 = call noalias ptr @malloc(i64 noundef %46) #6
  store ptr %47, ptr %12, align 8, !tbaa !5
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.evhtp_kv_s, ptr %49, i32 0, i32 2
  %51 = load i64, ptr %50, align 8, !tbaa !15
  %52 = getelementptr inbounds i8, ptr %48, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !9
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.evhtp_kv_s, ptr %55, i32 0, i32 2
  %57 = load i64, ptr %56, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %53, ptr align 1 %54, i64 %57, i1 false)
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.evhtp_kv_s, ptr %59, i32 0, i32 0
  store ptr %58, ptr %60, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %65

61:                                               ; preds = %34
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.evhtp_kv_s, ptr %63, i32 0, i32 0
  store ptr %62, ptr %64, align 8, !tbaa !17
  br label %65

65:                                               ; preds = %61, %42
  br label %66

66:                                               ; preds = %65, %17
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %101

69:                                               ; preds = %66
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = call i64 @strlen(ptr noundef %70) #7
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.evhtp_kv_s, ptr %72, i32 0, i32 3
  store i64 %71, ptr %73, align 8, !tbaa !16
  %74 = load i8, ptr %9, align 1, !tbaa !9
  %75 = sext i8 %74 to i32
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %96

77:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.evhtp_kv_s, ptr %78, i32 0, i32 3
  %80 = load i64, ptr %79, align 8, !tbaa !16
  %81 = add i64 %80, 1
  %82 = call noalias ptr @malloc(i64 noundef %81) #6
  store ptr %82, ptr %13, align 8, !tbaa !5
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.evhtp_kv_s, ptr %84, i32 0, i32 3
  %86 = load i64, ptr %85, align 8, !tbaa !16
  %87 = getelementptr inbounds i8, ptr %83, i64 %86
  store i8 0, ptr %87, align 1, !tbaa !9
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.evhtp_kv_s, ptr %90, i32 0, i32 3
  %92 = load i64, ptr %91, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %88, ptr align 1 %89, i64 %92, i1 false)
  %93 = load ptr, ptr %13, align 8, !tbaa !5
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.evhtp_kv_s, ptr %94, i32 0, i32 1
  store ptr %93, ptr %95, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %100

96:                                               ; preds = %69
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.evhtp_kv_s, ptr %98, i32 0, i32 1
  store ptr %97, ptr %99, align 8, !tbaa !18
  br label %100

100:                                              ; preds = %96, %77
  br label %101

101:                                              ; preds = %100, %66
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %102, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %103

103:                                              ; preds = %101, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %104 = load ptr, ptr %5, align 8
  ret ptr %104
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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 willreturn memory(read) "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 allocsize(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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 32}
!11 = !{!"evhtp_kv_s", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !7, i64 33, !13, i64 40}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8}
!14 = !{!11, !7, i64 33}
!15 = !{!11, !12, i64 16}
!16 = !{!11, !12, i64 24}
!17 = !{!11, !6, i64 0}
!18 = !{!11, !6, i64 8}


; 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 nofree nounwind willreturn uwtable
define dso_local noalias noundef ptr @evhtp_kv_new(ptr noundef %0, ptr noundef %1, i8 noundef signext %2, i8 noundef signext %3) local_unnamed_addr #0 {
  %5 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %27, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %5, i64 32
  store i8 %2, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 33
  store i8 %3, ptr %8, align 1, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %.not40 = icmp eq ptr %0, null
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %5, i8 0, i64 32, i1 false)
  br i1 %.not40, label %19, label %11

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  store i64 %13, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i8 %2, 1
  br i1 %14, label %15, label %.sink.split

15:                                               ; preds = %11
  %16 = add i64 %13, 1
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #5
  %18 = getelementptr inbounds i8, ptr %17, i64 %13
  store i8 0, ptr %18, align 1, !tbaa !14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr nonnull align 1 %0, i64 %13, i1 false)
  br label %.sink.split

.sink.split:                                      ; preds = %11, %15
  %.sink = phi ptr [ %17, %15 ], [ %0, %11 ]
  store ptr %.sink, ptr %5, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %.sink.split, %6
  %.not41 = icmp eq ptr %1, null
  br i1 %.not41, label %27, label %20

20:                                               ; preds = %19
  %21 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  store i64 %21, ptr %9, align 8, !tbaa !16
  %22 = icmp eq i8 %3, 1
  br i1 %22, label %23, label %.sink.split42

23:                                               ; preds = %20
  %24 = add i64 %21, 1
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #5
  %26 = getelementptr inbounds i8, ptr %25, i64 %21
  store i8 0, ptr %26, align 1, !tbaa !14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr nonnull align 1 %1, i64 %21, i1 false)
  br label %.sink.split42

.sink.split42:                                    ; preds = %20, %23
  %.sink43 = phi ptr [ %25, %23 ], [ %1, %20 ]
  store ptr %.sink43, ptr %10, align 8, !tbaa !17
  br label %27

27:                                               ; preds = %.sink.split42, %19, %4
  ret ptr %5
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #0 = { mustprogress nofree nounwind willreturn 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 nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind willreturn memory(read) }

!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, !8, i64 32}
!6 = !{!"evhtp_kv_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !8, i64 32, !8, i64 33, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 8}
!12 = !{!6, !8, i64 33}
!13 = !{!6, !10, i64 16}
!14 = !{!8, !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 24}
!17 = !{!6, !7, i64 8}


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