; LLVM IR from apigee/apib :: third_party/http_parser (test)

; 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.http_parser = type { i32, i32, i64, i16, i16, i32, ptr }
%struct.message = type { ptr, ptr, i32, i32, i32, [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], i64, ptr, ptr, i16, i32, i32, [13 x [2 x [2048 x i8]]], i32, i32, i32, [16 x i32], ptr, i16, i16, i32, i32, i32, i32, i32, i32 }

@.str.151 = external hidden unnamed_addr constant [76 x i8], align 1
@parser = external hidden global %struct.http_parser, align 8
@.str.153 = external hidden unnamed_addr constant [13 x i8], align 1
@messages = external hidden global [5 x %struct.message], align 16
@num_messages = external hidden global i32, align 4
@__PRETTY_FUNCTION__.header_field_cb = external hidden unnamed_addr constant [57 x i8], align 1

; 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
declare dso_local i64 @strlncat(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @header_field_cb(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, @parser
  br i1 %9, label %10, label %11

10:                                               ; preds = %3
  br label %12

11:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.153, ptr noundef @.str.151, i32 noundef 2119, ptr noundef @__PRETTY_FUNCTION__.header_field_cb) #3
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load i32, ptr @num_messages, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [5 x %struct.message], ptr @messages, i64 0, i64 %14
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.message, ptr %16, i32 0, i32 16
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %25

20:                                               ; preds = %12
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.message, ptr %21, i32 0, i32 15
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !16
  br label %25

25:                                               ; preds = %20, %12
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.message, ptr %26, i32 0, i32 17
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.message, ptr %28, i32 0, i32 15
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [13 x [2 x [2048 x i8]]], ptr %27, i64 0, i64 %32
  %34 = getelementptr inbounds [2 x [2048 x i8]], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds [2048 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = call i64 @strlncat(ptr noundef %35, i64 noundef 2048, ptr noundef %36, i64 noundef %37)
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.message, ptr %39, i32 0, i32 16
  store i32 1, ptr %40, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 0
}

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 = { noreturn 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 #3 = { noreturn nounwind }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 12352}
!14 = !{!"message", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !7, i64 28, !7, i64 2076, !7, i64 4124, !7, i64 6172, !7, i64 8220, !7, i64 10268, !10, i64 12320, !6, i64 12328, !6, i64 12336, !15, i64 12344, !12, i64 12348, !12, i64 12352, !7, i64 12356, !12, i64 65604, !12, i64 65608, !12, i64 65612, !7, i64 65616, !6, i64 65680, !15, i64 65688, !15, i64 65690, !12, i64 65692, !12, i64 65696, !12, i64 65700, !12, i64 65704, !12, i64 65708, !12, i64 65712}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !12, i64 12348}


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

%struct.http_parser = type { i32, i32, i64, i16, i16, i32, ptr }
%struct.message = type { ptr, ptr, i32, i32, i32, [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], [2048 x i8], i64, ptr, ptr, i16, i32, i32, [13 x [2 x [2048 x i8]]], i32, i32, i32, [16 x i32], ptr, i16, i16, i32, i32, i32, i32, i32, i32 }

@.str.151 = external hidden unnamed_addr constant [76 x i8], align 1
@parser = external hidden global %struct.http_parser, align 8
@.str.153 = external hidden unnamed_addr constant [13 x i8], align 1
@messages = external hidden global [5 x %struct.message], align 16
@num_messages = external hidden local_unnamed_addr global i32, align 4
@__PRETTY_FUNCTION__.header_field_cb = external hidden unnamed_addr constant [57 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @strlncat(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @header_field_cb(ptr noundef readnone %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, @parser
  br i1 %4, label %6, label %5

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.153, ptr noundef nonnull @.str.151, i32 noundef 2119, ptr noundef nonnull @__PRETTY_FUNCTION__.header_field_cb) #2
  unreachable

6:                                                ; preds = %3
  %7 = load i32, ptr @num_messages, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [5 x %struct.message], ptr @messages, i64 0, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 12352
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %.not = icmp eq i32 %11, 1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %9, i64 12348
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !14
  br i1 %.not, label %._crit_edge, label %13

._crit_edge:                                      ; preds = %6
  %12 = add nsw i32 %.pre, -1
  br label %15

13:                                               ; preds = %6
  %14 = add nsw i32 %.pre, 1
  store i32 %14, ptr %.phi.trans.insert, align 4, !tbaa !14
  br label %15

15:                                               ; preds = %._crit_edge, %13
  %16 = phi i32 [ %12, %._crit_edge ], [ %.pre, %13 ]
  %17 = getelementptr inbounds i8, ptr %9, i64 12356
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds [13 x [2 x [2048 x i8]]], ptr %17, i64 0, i64 %18
  %20 = tail call i64 @strlncat(ptr noundef nonnull %19, i64 noundef 2048, ptr noundef %1, i64 noundef %2)
  store i32 1, ptr %10, align 8, !tbaa !9
  ret i32 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" }
attributes #1 = { noreturn 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 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 12352}
!10 = !{!"message", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !7, i64 28, !7, i64 2076, !7, i64 4124, !7, i64 6172, !7, i64 8220, !7, i64 10268, !12, i64 12320, !11, i64 12328, !11, i64 12336, !13, i64 12344, !6, i64 12348, !6, i64 12352, !7, i64 12356, !6, i64 65604, !6, i64 65608, !6, i64 65612, !7, i64 65616, !11, i64 65680, !13, i64 65688, !13, i64 65690, !6, i64 65692, !6, i64 65696, !6, i64 65700, !6, i64 65704, !6, i64 65708, !6, i64 65712}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 12348}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass