; LLVM IR from kala13x/libxutils :: src/net (http)

; 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.xhttp_ = type { ptr, i16, ptr, i32, %struct.XByteBuffer, i32, %struct.XMap, i16, i16, i64, i64, i64, i64, i64, i8, i8, i8, [256 x i8], [128 x i8], [2048 x i8] }
%struct.XByteBuffer = type { ptr, i64, i64, i16, i16, i32 }
%struct.XMap = type { ptr, ptr, ptr, i64, i64, i32 }

declare i32 @XMap_Init(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @XHTTP_HeaderClearCb(ptr noundef) #1

declare i32 @XByteBuffer_Init(ptr noundef, i64 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @XHTTP_Reset(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = icmp ne i8 %5, 0
  br i1 %6, label %7, label %21

7:                                                ; preds = %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.xhttp_, ptr %8, i32 0, i32 4
  call void @XByteBuffer_Clear(ptr noundef %9)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.xhttp_, ptr %10, i32 0, i32 4
  %12 = call i32 @XByteBuffer_Init(ptr noundef %11, i64 noundef 0, i32 noundef 0)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.xhttp_, ptr %13, i32 0, i32 6
  call void @XMap_Destroy(ptr noundef %14)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.xhttp_, ptr %15, i32 0, i32 6
  %17 = call i32 @XMap_Init(ptr noundef %16, ptr noundef null, i64 noundef 0)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.xhttp_, ptr %18, i32 0, i32 6
  %20 = getelementptr inbounds %struct.XMap, ptr %19, i32 0, i32 0
  store ptr @XHTTP_HeaderClearCb, ptr %20, align 8, !tbaa !10
  br label %26

21:                                               ; preds = %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.xhttp_, ptr %22, i32 0, i32 4
  call void @XByteBuffer_Reset(ptr noundef %23)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.xhttp_, ptr %24, i32 0, i32 6
  call void @XMap_Reset(ptr noundef %25)
  br label %26

26:                                               ; preds = %21, %7
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xhttp_, ptr %27, i32 0, i32 9
  store i64 0, ptr %28, align 8, !tbaa !17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.xhttp_, ptr %29, i32 0, i32 10
  store i64 0, ptr %30, align 8, !tbaa !18
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.xhttp_, ptr %31, i32 0, i32 7
  store i16 0, ptr %32, align 8, !tbaa !19
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.xhttp_, ptr %33, i32 0, i32 8
  store i16 0, ptr %34, align 2, !tbaa !20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.xhttp_, ptr %35, i32 0, i32 16
  store i8 0, ptr %36, align 2, !tbaa !21
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.xhttp_, ptr %37, i32 0, i32 19
  %39 = getelementptr inbounds [2048 x i8], ptr %38, i64 0, i64 0
  store i8 0, ptr %39, align 1, !tbaa !9
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.xhttp_, ptr %40, i32 0, i32 3
  store i32 0, ptr %41, align 8, !tbaa !22
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.xhttp_, ptr %42, i32 0, i32 5
  store i32 0, ptr %43, align 8, !tbaa !23
  ret void
}

declare void @XByteBuffer_Clear(ptr noundef) #0

declare void @XMap_Destroy(ptr noundef) #0

declare void @XByteBuffer_Reset(ptr noundef) #0

declare void @XMap_Reset(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 = { 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" }

!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, !6, i64 72}
!11 = !{!"xhttp_", !6, i64 0, !12, i64 8, !6, i64 16, !13, i64 24, !14, i64 32, !13, i64 64, !16, i64 72, !12, i64 120, !12, i64 122, !15, i64 128, !15, i64 136, !15, i64 144, !15, i64 152, !15, i64 160, !7, i64 168, !7, i64 169, !7, i64 170, !7, i64 171, !7, i64 427, !7, i64 555}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"XByteBuffer", !6, i64 0, !15, i64 8, !15, i64 16, !12, i64 24, !12, i64 26, !13, i64 28}
!15 = !{!"long", !7, i64 0}
!16 = !{!"XMap", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !15, i64 32, !13, i64 40}
!17 = !{!11, !15, i64 128}
!18 = !{!11, !15, i64 136}
!19 = !{!11, !12, i64 120}
!20 = !{!11, !12, i64 122}
!21 = !{!11, !7, i64 170}
!22 = !{!11, !13, i64 24}
!23 = !{!11, !13, i64 64}


; 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 @XMap_Init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @XHTTP_HeaderClearCb(ptr noundef) #1

declare i32 @XByteBuffer_Init(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XHTTP_Reset(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #1 {
  %.not = icmp eq i8 %1, 0
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  tail call void @XByteBuffer_Clear(ptr noundef nonnull %3) #3
  %5 = tail call i32 @XByteBuffer_Init(ptr noundef nonnull %3, i64 noundef 0, i32 noundef 0) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @XMap_Destroy(ptr noundef nonnull %6) #3
  %7 = tail call i32 @XMap_Init(ptr noundef nonnull %6, ptr noundef null, i64 noundef 0) #3
  store ptr @XHTTP_HeaderClearCb, ptr %6, align 8, !tbaa !5
  br label %10

8:                                                ; preds = %2
  tail call void @XByteBuffer_Reset(ptr noundef nonnull %3) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @XMap_Reset(ptr noundef nonnull %9) #3
  br label %10

10:                                               ; preds = %8, %4
  %11 = getelementptr inbounds i8, ptr %0, i64 128
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  store i16 0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 122
  store i16 0, ptr %13, align 2, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 170
  store i8 0, ptr %14, align 2, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %0, i64 555
  store i8 0, ptr %15, align 1, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 0, ptr %17, align 8, !tbaa !20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  ret void
}

declare void @XByteBuffer_Clear(ptr noundef) local_unnamed_addr #0

declare void @XMap_Destroy(ptr noundef) local_unnamed_addr #0

declare void @XByteBuffer_Reset(ptr noundef) local_unnamed_addr #0

declare void @XMap_Reset(ptr noundef) local_unnamed_addr #0

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 72}
!6 = !{!"xhttp_", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !12, i64 32, !11, i64 64, !14, i64 72, !10, i64 120, !10, i64 122, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !8, i64 168, !8, i64 169, !8, i64 170, !8, i64 171, !8, i64 427, !8, i64 555}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"XByteBuffer", !7, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 26, !11, i64 28}
!13 = !{!"long", !8, i64 0}
!14 = !{!"XMap", !7, i64 0, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !11, i64 40}
!15 = !{!6, !10, i64 120}
!16 = !{!6, !10, i64 122}
!17 = !{!6, !8, i64 170}
!18 = !{!8, !8, i64 0}
!19 = !{!6, !11, i64 24}
!20 = !{!6, !11, i64 64}


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