; LLVM IR from ohler55/agoo :: ext/agoo (req)

; 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._agooReq = type { i32, ptr, i32, ptr, %struct._agooStr, %struct._agooStr, %struct._agooStr, %struct._agooStr, %struct._agooStr, [46 x i8], ptr, ptr, i64, [8 x i8] }
%struct._agooStr = type { ptr, i32 }

; 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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @agoo_req_header_value(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._agooReq, ptr %13, i32 0, i32 7
  %15 = getelementptr inbounds %struct._agooStr, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._agooReq, ptr %18, i32 0, i32 7
  %20 = getelementptr inbounds %struct._agooStr, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %17, i64 %22
  store ptr %23, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call i64 @strlen(ptr noundef %24) #4
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %11, align 4, !tbaa !15
  br label %27

27:                                               ; preds = %111, %3
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp ult ptr %28, %29
  br i1 %30, label %31, label %112

31:                                               ; preds = %27
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !15
  %35 = sext i32 %34 to i64
  %36 = call i32 @strncasecmp(ptr noundef %32, ptr noundef %33, i64 noundef %35) #4
  %37 = icmp eq i32 0, %36
  br i1 %37, label %38, label %88

38:                                               ; preds = %31
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !15
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !16
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 58, %44
  br i1 %45, label %46, label %88

46:                                               ; preds = %38
  %47 = load i32, ptr %11, align 4, !tbaa !15
  %48 = add nsw i32 %47, 1
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  store ptr %51, ptr %8, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %58, %46
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !16
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 32, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %8, align 8, !tbaa !5
  br label %52, !llvm.loop !17

61:                                               ; preds = %52
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %62, ptr %10, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %76, %61
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i8, ptr %64, align 1, !tbaa !16
  %66 = sext i8 %65 to i32
  %67 = icmp ne i32 13, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %63
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i8, ptr %69, align 1, !tbaa !16
  %71 = sext i8 %70 to i32
  %72 = icmp ne i32 0, %71
  br label %73

73:                                               ; preds = %68, %63
  %74 = phi i1 [ false, %63 ], [ %72, %68 ]
  br i1 %74, label %75, label %79

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i32 1
  store ptr %78, ptr %8, align 8, !tbaa !5
  br label %63, !llvm.loop !19

79:                                               ; preds = %73
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = ptrtoint ptr %80 to i64
  %83 = ptrtoint ptr %81 to i64
  %84 = sub i64 %82, %83
  %85 = trunc i64 %84 to i32
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %85, ptr %86, align 4, !tbaa !15
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %87, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %113

88:                                               ; preds = %38, %31
  br label %89

89:                                               ; preds = %108, %88
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = icmp ult ptr %90, %91
  br i1 %92, label %93, label %111

93:                                               ; preds = %89
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = load i8, ptr %94, align 1, !tbaa !16
  %96 = sext i8 %95 to i32
  %97 = icmp eq i32 13, %96
  br i1 %97, label %98, label %107

98:                                               ; preds = %93
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = getelementptr inbounds i8, ptr %99, i64 1
  %101 = load i8, ptr %100, align 1, !tbaa !16
  %102 = sext i8 %101 to i32
  %103 = icmp eq i32 10, %102
  br i1 %103, label %104, label %107

104:                                              ; preds = %98
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i64 2
  store ptr %106, ptr %8, align 8, !tbaa !5
  br label %111

107:                                              ; preds = %98, %93
  br label %108

108:                                              ; preds = %107
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds i8, ptr %109, i32 1
  store ptr %110, ptr %8, align 8, !tbaa !5
  br label %89, !llvm.loop !20

111:                                              ; preds = %104, %89
  br label %27, !llvm.loop !21

112:                                              ; preds = %27
  store ptr null, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %113

113:                                              ; preds = %112, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %114 = load ptr, ptr %4, align 8
  ret ptr %114
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { 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, !6, i64 80}
!10 = !{!"_agooReq", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !12, i64 48, !12, i64 64, !12, i64 80, !12, i64 96, !7, i64 112, !6, i64 160, !6, i64 168, !13, i64 176, !7, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_agooStr", !6, i64 0, !11, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !11, i64 88}
!15 = !{!11, !11, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}


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

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

; Function Attrs: nofree nounwind memory(read, argmem: readwrite) uwtable
define dso_local noundef ptr @agoo_req_header_value(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 88
  %7 = load i32, ptr %6, align 8, !tbaa !13
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %5, i64 %8
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.loopexit34, label %.lr.ph39

.lr.ph39:                                         ; preds = %3
  %10 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %sext = shl i64 %10, 32
  %11 = ashr exact i64 %sext, 32
  br label %12

12:                                               ; preds = %.lr.ph39, %.loopexit
  %.02938 = phi ptr [ %5, %.lr.ph39 ], [ %.4, %.loopexit ]
  %13 = tail call i32 @strncasecmp(ptr noundef %1, ptr noundef %.02938, i64 noundef %11) #3
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %33

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %.02938, i64 %11
  %17 = load i8, ptr %16, align 1, !tbaa !14
  %18 = icmp eq i8 %17, 58
  br i1 %18, label %19, label %33

19:                                               ; preds = %15
  %sext32 = add i64 %sext, 4294967296
  %20 = ashr exact i64 %sext32, 32
  %21 = getelementptr inbounds i8, ptr %.02938, i64 %20
  br label %22

22:                                               ; preds = %22, %19
  %.1 = phi ptr [ %21, %19 ], [ %25, %22 ]
  %23 = load i8, ptr %.1, align 1, !tbaa !14
  %24 = icmp eq i8 %23, 32
  %25 = getelementptr inbounds i8, ptr %.1, i64 1
  br i1 %24, label %22, label %.preheader, !llvm.loop !15

.preheader:                                       ; preds = %22, %27
  %26 = phi i8 [ %.pr, %27 ], [ %23, %22 ]
  %.2 = phi ptr [ %28, %27 ], [ %.1, %22 ]
  switch i8 %26, label %27 [
    i8 13, label %.critedge
    i8 0, label %.critedge
  ]

27:                                               ; preds = %.preheader
  %28 = getelementptr inbounds i8, ptr %.2, i64 1
  %.pr = load i8, ptr %28, align 1, !tbaa !14
  br label %.preheader, !llvm.loop !17

.critedge:                                        ; preds = %.preheader, %.preheader
  %29 = ptrtoint ptr %.2 to i64
  %30 = ptrtoint ptr %.1 to i64
  %31 = sub i64 %29, %30
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %2, align 4, !tbaa !18
  br label %.loopexit34

33:                                               ; preds = %15, %12
  %34 = icmp ult ptr %.02938, %9
  br i1 %34, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %33, %43
  %.337 = phi ptr [ %44, %43 ], [ %.02938, %33 ]
  %35 = load i8, ptr %.337, align 1, !tbaa !14
  %36 = icmp eq i8 %35, 13
  br i1 %36, label %37, label %43

37:                                               ; preds = %.lr.ph
  %38 = getelementptr inbounds i8, ptr %.337, i64 1
  %39 = load i8, ptr %38, align 1, !tbaa !14
  %40 = icmp eq i8 %39, 10
  br i1 %40, label %41, label %43

41:                                               ; preds = %37
  %42 = getelementptr inbounds i8, ptr %.337, i64 2
  br label %.loopexit

43:                                               ; preds = %.lr.ph, %37
  %44 = getelementptr inbounds i8, ptr %.337, i64 1
  %45 = icmp ult ptr %44, %9
  br i1 %45, label %.lr.ph, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %43, %33, %41
  %.4 = phi ptr [ %42, %41 ], [ %.02938, %33 ], [ %44, %43 ]
  %46 = icmp ult ptr %.4, %9
  br i1 %46, label %12, label %.loopexit34, !llvm.loop !20

.loopexit34:                                      ; preds = %.loopexit, %3, %.critedge
  %.0 = phi ptr [ %.1, %.critedge ], [ null, %3 ], [ null, %.loopexit ]
  ret ptr %.0
}

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

attributes #0 = { 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 #1 = { nofree nounwind memory(read, argmem: readwrite) 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(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 = { 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, !10, i64 80}
!6 = !{!"_agooReq", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !11, i64 32, !11, i64 48, !11, i64 64, !11, i64 80, !11, i64 96, !8, i64 112, !10, i64 160, !10, i64 168, !12, i64 176, !8, i64 184}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_agooStr", !10, i64 0, !7, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 88}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass