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

; 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
define dso_local i32 @XHTTP_Parse(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.xhttp_, ptr %8, i32 0, i32 4
  %10 = getelementptr inbounds %struct.XByteBuffer, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call i64 @XHTTP_ParseHeaderLength(ptr noundef %12)
  store i64 %13, ptr %5, align 8, !tbaa !16
  %14 = load i64, ptr %5, align 8, !tbaa !16
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.xhttp_, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds %struct.XByteBuffer, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load i64, ptr %5, align 8, !tbaa !16
  %23 = sub i64 %22, 1
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store i8 0, ptr %24, align 1, !tbaa !17
  %25 = load i64, ptr %5, align 8, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.xhttp_, ptr %26, i32 0, i32 10
  store i64 %25, ptr %27, align 8, !tbaa !18
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call i32 @XHTTP_ParseType(ptr noundef %28)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.xhttp_, ptr %30, i32 0, i32 5
  store i32 %29, ptr %31, align 8, !tbaa !19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = call i64 @XHTTP_ParseVersion(ptr noundef %32)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %38, label %35

35:                                               ; preds = %17
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call i32 @XHTTP_StatusCb(ptr noundef %36, i32 noundef 1)
  store i32 %37, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %99

38:                                               ; preds = %17
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.xhttp_, ptr %39, i32 0, i32 5
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = icmp eq i32 %41, 2
  br i1 %42, label %43, label %48

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call zeroext i16 @XHTTP_ParseCode(ptr noundef %44)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.xhttp_, ptr %46, i32 0, i32 8
  store i16 %45, ptr %47, align 2, !tbaa !20
  br label %59

48:                                               ; preds = %38
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.xhttp_, ptr %49, i32 0, i32 5
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = icmp eq i32 %51, 1
  br i1 %52, label %53, label %58

53:                                               ; preds = %48
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i32 @XHTTP_ParseMethod(ptr noundef %54)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.xhttp_, ptr %56, i32 0, i32 3
  store i32 %55, ptr %57, align 8, !tbaa !21
  br label %58

58:                                               ; preds = %53, %48
  br label %59

59:                                               ; preds = %58, %43
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = call i64 @XHTTP_ParseUrl(ptr noundef %60)
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %66, label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = call i32 @XHTTP_StatusCb(ptr noundef %64, i32 noundef 1)
  store i32 %65, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %99

66:                                               ; preds = %59
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = call i32 @XHTTP_ParseHeaders(ptr noundef %67)
  %69 = icmp eq i32 %68, -1
  br i1 %69, label %70, label %73

70:                                               ; preds = %66
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = call i32 @XHTTP_StatusCb(ptr noundef %71, i32 noundef 9)
  store i32 %72, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %99

73:                                               ; preds = %66
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = call i64 @XHTTP_ParseContentLength(ptr noundef %74)
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.xhttp_, ptr %76, i32 0, i32 9
  store i64 %75, ptr %77, align 8, !tbaa !22
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.xhttp_, ptr %78, i32 0, i32 4
  %80 = getelementptr inbounds %struct.XByteBuffer, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !9
  %82 = load i64, ptr %5, align 8, !tbaa !16
  %83 = sub i64 %82, 1
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  store i8 10, ptr %84, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = call i32 @XHTTP_StatusCb(ptr noundef %85, i32 noundef 23)
  store i32 %86, ptr %7, align 4, !tbaa !23
  %87 = load i32, ptr %7, align 4, !tbaa !23
  %88 = icmp eq i32 %87, 16
  br i1 %88, label %89, label %90

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

90:                                               ; preds = %73
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = call i32 @XHTTP_CheckComplete(ptr noundef %91)
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %95

94:                                               ; preds = %90
  store i32 20, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %98

95:                                               ; preds = %90
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %7, align 4, !tbaa !23
  store i32 %97, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %98

98:                                               ; preds = %96, %94, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %99

99:                                               ; preds = %98, %70, %63, %35, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %100 = load i32, ptr %2, align 4
  ret i32 %100
}

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseHeaderLength(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseType(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseVersion(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_StatusCb(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @XHTTP_ParseCode(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseMethod(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseUrl(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseHeaders(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseContentLength(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_CheckComplete(ptr noundef) #1

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 }

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


; 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: nounwind uwtable
define dso_local i32 @XHTTP_Parse(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i64 @XHTTP_ParseHeaderLength(ptr noundef %3)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %41, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = add i64 %4, -1
  %8 = getelementptr inbounds i8, ptr %6, i64 %7
  store i8 0, ptr %8, align 1, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  store i64 %4, ptr %9, align 8, !tbaa !16
  %10 = tail call i32 @XHTTP_ParseType(ptr noundef nonnull %0)
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %10, ptr %11, align 8, !tbaa !17
  %12 = tail call i64 @XHTTP_ParseVersion(ptr noundef nonnull %0)
  %.not32 = icmp eq i64 %12, 0
  br i1 %.not32, label %13, label %15

13:                                               ; preds = %5
  %14 = tail call i32 @XHTTP_StatusCb(ptr noundef nonnull %0, i32 noundef 1)
  br label %41

15:                                               ; preds = %5
  %16 = load i32, ptr %11, align 8, !tbaa !17
  switch i32 %16, label %23 [
    i32 2, label %17
    i32 1, label %20
  ]

17:                                               ; preds = %15
  %18 = tail call zeroext i16 @XHTTP_ParseCode(ptr noundef nonnull %0)
  %19 = getelementptr inbounds i8, ptr %0, i64 122
  store i16 %18, ptr %19, align 2, !tbaa !18
  br label %23

20:                                               ; preds = %15
  %21 = tail call i32 @XHTTP_ParseMethod(ptr noundef nonnull %0)
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %21, ptr %22, align 8, !tbaa !19
  br label %23

23:                                               ; preds = %15, %20, %17
  %24 = tail call i64 @XHTTP_ParseUrl(ptr noundef nonnull %0)
  %.not33 = icmp eq i64 %24, 0
  br i1 %.not33, label %25, label %27

25:                                               ; preds = %23
  %26 = tail call i32 @XHTTP_StatusCb(ptr noundef nonnull %0, i32 noundef 1)
  br label %41

27:                                               ; preds = %23
  %28 = tail call i32 @XHTTP_ParseHeaders(ptr noundef nonnull %0)
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %32

30:                                               ; preds = %27
  %31 = tail call i32 @XHTTP_StatusCb(ptr noundef nonnull %0, i32 noundef 9)
  br label %41

32:                                               ; preds = %27
  %33 = tail call i64 @XHTTP_ParseContentLength(ptr noundef nonnull %0)
  %34 = getelementptr inbounds i8, ptr %0, i64 128
  store i64 %33, ptr %34, align 8, !tbaa !20
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 %7
  store i8 10, ptr %36, align 1, !tbaa !15
  %37 = tail call i32 @XHTTP_StatusCb(ptr noundef nonnull %0, i32 noundef 23)
  %38 = icmp eq i32 %37, 16
  br i1 %38, label %41, label %39

39:                                               ; preds = %32
  %40 = tail call i32 @XHTTP_CheckComplete(ptr noundef nonnull %0)
  %.not34 = icmp eq i32 %40, 0
  %. = select i1 %.not34, i32 %37, i32 20
  br label %41

41:                                               ; preds = %32, %39, %1, %30, %25, %13
  %.1 = phi i32 [ %31, %30 ], [ %26, %25 ], [ %14, %13 ], [ 17, %1 ], [ 16, %32 ], [ %., %39 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseHeaderLength(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseType(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseVersion(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_StatusCb(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @XHTTP_ParseCode(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseMethod(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseUrl(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_ParseHeaders(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @XHTTP_ParseContentLength(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @XHTTP_CheckComplete(ptr noundef) local_unnamed_addr #0

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

!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 32}
!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 = !{!8, !8, i64 0}
!16 = !{!6, !13, i64 136}
!17 = !{!6, !11, i64 64}
!18 = !{!6, !10, i64 122}
!19 = !{!6, !11, i64 24}
!20 = !{!6, !13, i64 128}


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