; 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_settings = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.http_parser = type { i32, i32, i64, i16, i16, i32, ptr }

@.str.151 = external hidden unnamed_addr constant [76 x i8], align 1
@stderr = external global ptr, align 8
@.str.309 = external hidden unnamed_addr constant [17 x i8], align 1
@settings_null = external hidden global %struct.http_parser_settings, align 8
@.str.311 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.330 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.test_header_overflow_error = external hidden unnamed_addr constant [37 x i8], align 1
@.str.331 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.332 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.333 = external hidden unnamed_addr constant [58 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: noreturn nounwind
declare void @abort() #1

declare void @http_parser_init(ptr noundef, i32 noundef) #3

declare i64 @http_parser_execute(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @test_header_overflow_error(i32 noundef %0) #5 {
  %2 = alloca i32, align 4
  %3 = alloca %struct.http_parser, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp ne i32 %8, 0
  %10 = zext i1 %9 to i64
  %11 = select i1 %9, i32 0, i32 1
  call void @http_parser_init(ptr noundef %3, i32 noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, ptr @.str.309, ptr @.str.330
  store ptr %15, ptr %5, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = call i64 @strlen(ptr noundef %17) #7
  %19 = call i64 @http_parser_execute(ptr noundef %3, ptr noundef @settings_null, ptr noundef %16, i64 noundef %18)
  store i64 %19, ptr %4, align 8, !tbaa !11
  %20 = load i64, ptr %4, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = call i64 @strlen(ptr noundef %21) #7
  %23 = icmp eq i64 %20, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %1
  br label %26

25:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.311, ptr noundef @.str.151, i32 noundef 3815, ptr noundef @__PRETTY_FUNCTION__.test_header_overflow_error) #8
  unreachable

26:                                               ; preds = %24
  store ptr @.str.331, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = call i64 @strlen(ptr noundef %27) #7
  store i64 %28, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %49, %26
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 10000
  br i1 %31, label %32, label %52

32:                                               ; preds = %29
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !11
  %35 = call i64 @http_parser_execute(ptr noundef %3, ptr noundef @settings_null, ptr noundef %33, i64 noundef %34)
  store i64 %35, ptr %4, align 8, !tbaa !11
  %36 = load i64, ptr %4, align 8, !tbaa !11
  %37 = load i64, ptr %6, align 8, !tbaa !11
  %38 = icmp ne i64 %36, %37
  br i1 %38, label %39, label %48

39:                                               ; preds = %32
  %40 = getelementptr inbounds %struct.http_parser, ptr %3, i32 0, i32 5
  %41 = load i32, ptr %40, align 4
  %42 = lshr i32 %41, 24
  %43 = and i32 %42, 127
  %44 = icmp eq i32 %43, 12
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %47

46:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.332, ptr noundef @.str.151, i32 noundef 3825, ptr noundef @__PRETTY_FUNCTION__.test_header_overflow_error) #8
  unreachable

47:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #6
  ret void

48:                                               ; preds = %32
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !5
  br label %29, !llvm.loop !13

52:                                               ; preds = %29
  %53 = load ptr, ptr @stderr, align 8, !tbaa !9
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.333) #6
  call void @abort() #8
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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_settings = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.http_parser = type { i32, i32, i64, i16, i16, i32, ptr }

@.str.151 = external hidden unnamed_addr constant [76 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.309 = external hidden unnamed_addr constant [17 x i8], align 1
@settings_null = external hidden global %struct.http_parser_settings, align 8
@.str.311 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.330 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.test_header_overflow_error = external hidden unnamed_addr constant [37 x i8], align 1
@.str.331 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.332 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.333 = external hidden unnamed_addr constant [58 x i8], align 1

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

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

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

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

declare void @http_parser_init(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i64 @http_parser_execute(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local void @test_header_overflow_error(i32 noundef %0) local_unnamed_addr #5 {
  %2 = alloca %struct.http_parser, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #6
  %.not = icmp eq i32 %0, 0
  %3 = zext i1 %.not to i32
  call void @http_parser_init(ptr noundef nonnull %2, i32 noundef %3) #6
  %4 = select i1 %.not, ptr @.str.330, ptr @.str.309
  %5 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #7
  %6 = call i64 @http_parser_execute(ptr noundef nonnull %2, ptr noundef nonnull @settings_null, ptr noundef nonnull %4, i64 noundef %5) #6
  %7 = icmp eq i64 %6, %5
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  call void @__assert_fail(ptr noundef nonnull @.str.311, ptr noundef nonnull @.str.151, i32 noundef 3815, ptr noundef nonnull @__PRETTY_FUNCTION__.test_header_overflow_error) #8
  unreachable

9:                                                ; preds = %1
  %10 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.331) #7
  br label %13

11:                                               ; preds = %13
  %12 = add nuw nsw i32 %.013, 1
  %exitcond.not = icmp eq i32 %12, 10000
  br i1 %exitcond.not, label %22, label %13, !llvm.loop !5

13:                                               ; preds = %9, %11
  %.013 = phi i32 [ 0, %9 ], [ %12, %11 ]
  %14 = call i64 @http_parser_execute(ptr noundef nonnull %2, ptr noundef nonnull @settings_null, ptr noundef nonnull @.str.331, i64 noundef %10) #6
  %.not12 = icmp eq i64 %14, %10
  br i1 %.not12, label %11, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %2, i64 20
  %17 = load i32, ptr %16, align 4
  %18 = and i32 %17, 2130706432
  %19 = icmp eq i32 %18, 201326592
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @__assert_fail(ptr noundef nonnull @.str.332, ptr noundef nonnull @.str.151, i32 noundef 3825, ptr noundef nonnull @__PRETTY_FUNCTION__.test_header_overflow_error) #8
  unreachable

21:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #6
  ret void

22:                                               ; preds = %11
  %23 = load ptr, ptr @stderr, align 8, !tbaa !7
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.333) #9
  call void @abort() #8
  unreachable
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass