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

; 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 }
%struct.timeval = type { i64, i64 }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.bench = external hidden unnamed_addr constant [20 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@settings = external hidden global %struct.http_parser_settings, align 8
@data = external hidden constant [519 x i8], align 16
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@stdout = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @bench(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.http_parser, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.timeval, align 8
  %9 = alloca %struct.timeval, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %23, label %16

16:                                               ; preds = %2
  %17 = call i32 @gettimeofday(ptr noundef %8, ptr noundef null) #5
  store i32 %17, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  br label %22

21:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 77, ptr noundef @__PRETTY_FUNCTION__.bench) #6
  unreachable

22:                                               ; preds = %20
  br label %23

23:                                               ; preds = %22, %2
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.2, i32 noundef 518) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %37, %23
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @http_parser_init(ptr noundef %5, i32 noundef 0)
  %31 = call i64 @http_parser_execute(ptr noundef %5, ptr noundef @settings, ptr noundef @data, i64 noundef 518)
  store i64 %31, ptr %10, align 8, !tbaa !11
  %32 = load i64, ptr %10, align 8, !tbaa !11
  %33 = icmp eq i64 %32, 518
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %36

35:                                               ; preds = %30
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__.bench) #6
  unreachable

36:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %6, align 4, !tbaa !5
  br label %26, !llvm.loop !13

40:                                               ; preds = %26
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %86, label %43

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %44 = call i32 @gettimeofday(ptr noundef %9, ptr noundef null) #5
  store i32 %44, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  br label %49

48:                                               ; preds = %43
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 95, ptr noundef @__PRETTY_FUNCTION__.bench) #6
  unreachable

49:                                               ; preds = %47
  %50 = load ptr, ptr @stdout, align 8, !tbaa !9
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.4) #5
  %52 = getelementptr inbounds %struct.timeval, ptr %9, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !15
  %56 = sub nsw i64 %53, %55
  %57 = sitofp i64 %56 to double
  %58 = getelementptr inbounds %struct.timeval, ptr %9, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !17
  %60 = getelementptr inbounds %struct.timeval, ptr %8, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !17
  %62 = sub nsw i64 %59, %61
  %63 = sitofp i64 %62 to float
  %64 = fmul float %63, 0x3EB0C6F7A0000000
  %65 = fpext float %64 to double
  %66 = fadd double %57, %65
  store double %66, ptr %11, align 8, !tbaa !18
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sitofp i32 %67 to double
  %69 = fmul double %68, 5.180000e+02
  store double %69, ptr %13, align 8, !tbaa !18
  %70 = load double, ptr %13, align 8, !tbaa !18
  %71 = load double, ptr %11, align 8, !tbaa !18
  %72 = fdiv double %70, %71
  store double %72, ptr %12, align 8, !tbaa !18
  %73 = load ptr, ptr @stdout, align 8, !tbaa !9
  %74 = load double, ptr %13, align 8, !tbaa !18
  %75 = fdiv double %74, 0x4130000000000000
  %76 = load double, ptr %12, align 8, !tbaa !18
  %77 = fdiv double %76, 0x4130000000000000
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sitofp i32 %78 to double
  %80 = load double, ptr %11, align 8, !tbaa !18
  %81 = fdiv double %79, %80
  %82 = load double, ptr %11, align 8, !tbaa !18
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.5, double noundef %75, double noundef %77, double noundef %81, double noundef %82) #5
  %84 = load ptr, ptr @stdout, align 8, !tbaa !9
  %85 = call i32 @fflush(ptr noundef %84)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %86

86:                                               ; preds = %49, %40
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #5
  ret i32 0
}

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

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

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

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

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

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

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

declare i32 @fflush(ptr noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { "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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 0}
!16 = !{!"timeval", !12, i64 0, !12, i64 8}
!17 = !{!16, !12, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !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 }
%struct.timeval = type { i64, i64 }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__.bench = external hidden unnamed_addr constant [20 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@settings = external hidden global %struct.http_parser_settings, align 8
@data = external hidden constant [519 x i8], align 16
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @bench(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.http_parser, align 8
  %4 = alloca %struct.timeval, align 8
  %5 = alloca %struct.timeval, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %6, label %10

6:                                                ; preds = %2
  %7 = call i32 @gettimeofday(ptr noundef nonnull %4, ptr noundef null) #5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 77, ptr noundef nonnull @__PRETTY_FUNCTION__.bench) #6
  unreachable

10:                                               ; preds = %6, %2
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.2, i32 noundef 518) #7
  %13 = icmp sgt i32 %0, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

14:                                               ; preds = %.lr.ph
  %15 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %15, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %10, %14
  %.016 = phi i32 [ %15, %14 ], [ 0, %10 ]
  call void @http_parser_init(ptr noundef nonnull %3, i32 noundef 0) #5
  %16 = call i64 @http_parser_execute(ptr noundef nonnull %3, ptr noundef nonnull @settings, ptr noundef nonnull @data, i64 noundef 518) #5
  %17 = icmp eq i64 %16, 518
  br i1 %17, label %14, label %18

18:                                               ; preds = %.lr.ph
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 86, ptr noundef nonnull @__PRETTY_FUNCTION__.bench) #6
  unreachable

._crit_edge:                                      ; preds = %14, %10
  br i1 %.not, label %19, label %49

19:                                               ; preds = %._crit_edge
  %20 = call i32 @gettimeofday(ptr noundef nonnull %5, ptr noundef null) #5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 95, ptr noundef nonnull @__PRETTY_FUNCTION__.bench) #6
  unreachable

23:                                               ; preds = %19
  %24 = load ptr, ptr @stdout, align 8, !tbaa !5
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.4) #5
  %26 = load i64, ptr %5, align 8, !tbaa !11
  %27 = load i64, ptr %4, align 8, !tbaa !11
  %28 = sub nsw i64 %26, %27
  %29 = sitofp i64 %28 to double
  %30 = getelementptr inbounds i8, ptr %5, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %4, i64 8
  %33 = load i64, ptr %32, align 8, !tbaa !14
  %34 = sub nsw i64 %31, %33
  %35 = sitofp i64 %34 to float
  %36 = fmul float %35, 0x3EB0C6F7A0000000
  %37 = fpext float %36 to double
  %38 = fadd double %29, %37
  %39 = sitofp i32 %0 to double
  %40 = fmul double %39, 5.180000e+02
  %41 = fdiv double %40, %38
  %42 = load ptr, ptr @stdout, align 8, !tbaa !5
  %43 = fmul double %40, 0x3EB0000000000000
  %44 = fmul double %41, 0x3EB0000000000000
  %45 = fdiv double %39, %38
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str.5, double noundef %43, double noundef %44, double noundef %45, double noundef %38) #5
  %47 = load ptr, ptr @stdout, align 8, !tbaa !5
  %48 = call i32 @fflush(ptr noundef %47)
  br label %49

49:                                               ; preds = %23, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret i32 0
}

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

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

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

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

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

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


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