; LLVM IR from guanzhi/GmSSL :: src (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"

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@__FUNCTION__.http_parse_response = external hidden unnamed_addr constant [20 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @http_parse_response(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr @.str.6, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = load ptr, ptr %12, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #6
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %27, label %20

20:                                               ; preds = %5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = call i64 @strlen(ptr noundef %23) #6
  %25 = call i32 @memcmp(ptr noundef %21, ptr noundef %22, i64 noundef %24) #6
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %20, %5
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 74, ptr noundef @__FUNCTION__.http_parse_response) #5
  br label %31

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

33:                                               ; preds = %20
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %33
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 78, ptr noundef @__FUNCTION__.http_parse_response) #5
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

46:                                               ; preds = %33
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call ptr @strstr(ptr noundef %47, ptr noundef @.str.7) #6
  store ptr %48, ptr %13, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %56, label %50

50:                                               ; preds = %46
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 82, ptr noundef @__FUNCTION__.http_parse_response) #5
  br label %54

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

56:                                               ; preds = %46
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 4
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %58, ptr %59, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = ptrtoint ptr %61 to i64
  %64 = ptrtoint ptr %62 to i64
  %65 = sub i64 %63, %64
  store i64 %65, ptr %14, align 8, !tbaa !9
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 0, ptr %66, align 1, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = call ptr @strstr(ptr noundef %67, ptr noundef @.str.8) #6
  store ptr %68, ptr %13, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %76, label %70

70:                                               ; preds = %56
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 90, ptr noundef @__FUNCTION__.http_parse_response) #5
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

76:                                               ; preds = %56
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 18
  store ptr %78, ptr %13, align 8, !tbaa !5
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = call i32 @atoi(ptr noundef %79) #6
  %81 = sext i32 %80 to i64
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 %81, ptr %82, align 8, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = load i64, ptr %83, align 8, !tbaa !9
  %85 = icmp ule i64 %84, 0
  br i1 %85, label %90, label %86

86:                                               ; preds = %76
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load i64, ptr %87, align 8, !tbaa !9
  %89 = icmp ugt i64 %88, 2147483647
  br i1 %89, label %90, label %96

90:                                               ; preds = %86, %76
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr @stderr, align 8, !tbaa !5
  %93 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 96, ptr noundef @__FUNCTION__.http_parse_response) #5
  br label %94

94:                                               ; preds = %91
  br label %95

95:                                               ; preds = %94
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

96:                                               ; preds = %86
  %97 = load i64, ptr %14, align 8, !tbaa !9
  %98 = load i64, ptr %8, align 8, !tbaa !9
  %99 = sub i64 %98, %97
  store i64 %99, ptr %8, align 8, !tbaa !9
  %100 = load i64, ptr %8, align 8, !tbaa !9
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = load i64, ptr %101, align 8, !tbaa !9
  %103 = icmp ult i64 %100, %102
  br i1 %103, label %104, label %110

104:                                              ; preds = %96
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  %106 = load i64, ptr %105, align 8, !tbaa !9
  %107 = load i64, ptr %8, align 8, !tbaa !9
  %108 = sub i64 %106, %107
  %109 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %108, ptr %109, align 8, !tbaa !9
  br label %112

110:                                              ; preds = %96
  %111 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %111, align 8, !tbaa !9
  br label %112

112:                                              ; preds = %110, %104
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

113:                                              ; preds = %112, %95, %75, %55, %45, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %114 = load i32, ptr %6, align 4
  ret i32 %114
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

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

attributes #0 = { 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 #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint nounwind willreturn memory(read) 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 #5 = { nounwind }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@__FUNCTION__.http_parse_response = external hidden unnamed_addr constant [20 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 2) i32 @http_parse_response(ptr noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.6) #6
  %7 = icmp ugt i64 %6, %1
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  %bcmp = tail call i32 @bcmp(ptr %0, ptr nonnull @.str.6, i64 %6)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %12, label %9

9:                                                ; preds = %5, %8
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 74, ptr noundef nonnull @__FUNCTION__.http_parse_response) #7
  br label %40

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 %1
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not33 = icmp eq i8 %14, 0
  br i1 %.not33, label %18, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 78, ptr noundef nonnull @__FUNCTION__.http_parse_response) #7
  br label %40

18:                                               ; preds = %12
  %19 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.7) #6
  %.not34 = icmp eq ptr %19, null
  br i1 %.not34, label %20, label %23

20:                                               ; preds = %18
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 82, ptr noundef nonnull @__FUNCTION__.http_parse_response) #7
  br label %40

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %19, i64 4
  store ptr %24, ptr %2, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = ptrtoint ptr %0 to i64
  store i8 0, ptr %19, align 1, !tbaa !9
  %27 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.8) #6
  %.not35 = icmp eq ptr %27, null
  br i1 %.not35, label %28, label %31

28:                                               ; preds = %23
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 90, ptr noundef nonnull @__FUNCTION__.http_parse_response) #7
  br label %40

31:                                               ; preds = %23
  %32 = getelementptr inbounds i8, ptr %27, i64 18
  %33 = tail call i32 @atoi(ptr nocapture noundef %32) #6
  %34 = sext i32 %33 to i64
  store i64 %34, ptr %3, align 8, !tbaa !10
  %or.cond = icmp slt i32 %33, 1
  br i1 %or.cond, label %35, label %38

35:                                               ; preds = %31
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 96, ptr noundef nonnull @__FUNCTION__.http_parse_response) #7
  br label %40

38:                                               ; preds = %31
  %.neg = add i64 %26, %1
  %39 = sub i64 %.neg, %25
  %storemerge = tail call i64 @llvm.usub.sat.i64(i64 %34, i64 %39)
  store i64 %storemerge, ptr %4, align 8, !tbaa !10
  br label %40

40:                                               ; preds = %38, %35, %28, %20, %15, %9
  %.0 = phi i32 [ -1, %9 ], [ -1, %15 ], [ -1, %35 ], [ 1, %38 ], [ -1, %28 ], [ -1, %20 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #5

attributes #0 = { nofree 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 #1 = { nofree 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 = { 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 #3 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #4 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { cold 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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