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

@stderr = external global ptr, align 8
@settings_null = external hidden global %struct.http_parser_settings, align 8
@.str.336 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.337 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.338 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.339 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.340 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.341 = external hidden unnamed_addr constant [9 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

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 uwtable
define dso_local void @test_no_overflow_long_body(i32 noundef %0, i64 noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca %struct.http_parser, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca [3000 x i8], align 16
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #5
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  %14 = zext i1 %13 to i64
  %15 = select i1 %13, i32 0, i32 1
  call void @http_parser_init(ptr noundef %5, i32 noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 3000, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %16 = getelementptr inbounds [3000 x i8], ptr %8, i64 0, i64 0
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, ptr @.str.337, ptr @.str.338
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %16, ptr noundef @.str.336, ptr noundef %20, i64 noundef %21) #5
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %9, align 8, !tbaa !9
  %24 = getelementptr inbounds [3000 x i8], ptr %8, i64 0, i64 0
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = call i64 @http_parser_execute(ptr noundef %5, ptr noundef @settings_null, ptr noundef %24, i64 noundef %25)
  store i64 %26, ptr %6, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = icmp ne i64 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %2
  br label %57

31:                                               ; preds = %2
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %45, %31
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %36, label %48

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  store i8 97, ptr %10, align 1, !tbaa !11
  %37 = call i64 @http_parser_execute(ptr noundef %5, ptr noundef @settings_null, ptr noundef %10, i64 noundef 1)
  store i64 %37, ptr %6, align 8, !tbaa !9
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = icmp ne i64 %38, 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  store i32 2, ptr %11, align 4
  br label %42

41:                                               ; preds = %36
  store i32 0, ptr %11, align 4
  br label %42

42:                                               ; preds = %41, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  %43 = load i32, ptr %11, align 4
  switch i32 %43, label %65 [
    i32 0, label %44
    i32 2, label %57
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %7, align 8, !tbaa !9
  br label %32, !llvm.loop !12

48:                                               ; preds = %32
  %49 = getelementptr inbounds [3000 x i8], ptr %8, i64 0, i64 0
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = call i64 @http_parser_execute(ptr noundef %5, ptr noundef @settings_null, ptr noundef %49, i64 noundef %50)
  store i64 %51, ptr %6, align 8, !tbaa !9
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = icmp ne i64 %52, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  br label %57

56:                                               ; preds = %48
  store i32 1, ptr %11, align 4
  br label %65

57:                                               ; preds = %55, %42, %30
  %58 = load ptr, ptr @stderr, align 8, !tbaa !14
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  %61 = zext i1 %60 to i64
  %62 = select i1 %60, ptr @.str.340, ptr @.str.341
  %63 = load i64, ptr %4, align 8, !tbaa !9
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.339, ptr noundef %62, i64 noundef %63) #5
  call void @abort() #6
  unreachable

65:                                               ; preds = %56, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 3000, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

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

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

@stderr = external local_unnamed_addr global ptr, align 8
@settings_null = external hidden global %struct.http_parser_settings, align 8
@.str.336 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.337 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.338 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.339 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.340 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.341 = external hidden unnamed_addr constant [9 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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: nounwind uwtable
define dso_local void @test_no_overflow_long_body(i32 noundef %0, i64 noundef %1) local_unnamed_addr #4 {
  %3 = alloca %struct.http_parser, align 8
  %4 = alloca [3000 x i8], align 16
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  %.not = icmp eq i32 %0, 0
  %6 = zext i1 %.not to i32
  call void @http_parser_init(ptr noundef nonnull %3, i32 noundef %6) #5
  call void @llvm.lifetime.start.p0(i64 3000, ptr nonnull %4) #5
  %7 = select i1 %.not, ptr @.str.338, ptr @.str.337
  %8 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) @.str.336, ptr noundef nonnull %7, i64 noundef %1) #5
  %9 = sext i32 %8 to i64
  %10 = call i64 @http_parser_execute(ptr noundef nonnull %3, ptr noundef nonnull @settings_null, ptr noundef nonnull %4, i64 noundef %9) #5
  %.not18 = icmp eq i64 %10, %9
  br i1 %.not18, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %.not22 = icmp eq i64 %1, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph

11:                                               ; preds = %.lr.ph
  %12 = add nuw i64 %.01621, 1
  %exitcond.not = icmp eq i64 %12, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %11
  %.01621 = phi i64 [ %12, %11 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #5
  store i8 97, ptr %5, align 1, !tbaa !7
  %13 = call i64 @http_parser_execute(ptr noundef nonnull %3, ptr noundef nonnull @settings_null, ptr noundef nonnull %5, i64 noundef 1) #5
  %.not20 = icmp eq i64 %13, 1
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #5
  br i1 %.not20, label %11, label %.loopexit

._crit_edge:                                      ; preds = %11, %.preheader
  %14 = call i64 @http_parser_execute(ptr noundef nonnull %3, ptr noundef nonnull @settings_null, ptr noundef nonnull %4, i64 noundef %9) #5
  %.not19 = icmp eq i64 %14, %9
  br i1 %.not19, label %18, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %._crit_edge, %2
  %15 = load ptr, ptr @stderr, align 8, !tbaa !10
  %16 = select i1 %.not, ptr @.str.341, ptr @.str.340
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.339, ptr noundef nonnull %16, i64 noundef %1) #6
  call void @abort() #7
  unreachable

18:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 3000, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass