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

; 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
define dso_local i32 @agoo_req_query_decode(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  store ptr %16, ptr %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %66, %57, %2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp ult ptr %18, %19
  br i1 %20, label %21, label %67

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 37, %24
  br i1 %25, label %26, label %60

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = sext i8 %30 to i32
  %32 = call i32 @hexVal(i32 noundef %31)
  store i32 %32, ptr %9, align 4, !tbaa !9
  %33 = icmp sgt i32 0, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %26
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %5, align 8, !tbaa !5
  store i8 37, ptr %35, align 1, !tbaa !11
  store i32 2, ptr %10, align 4
  br label %57, !llvm.loop !12

37:                                               ; preds = %26
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = sext i8 %41 to i32
  %43 = call i32 @hexVal(i32 noundef %42)
  store i32 %43, ptr %8, align 4, !tbaa !9
  %44 = icmp sgt i32 0, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 2, ptr %10, align 4
  br label %57, !llvm.loop !12

46:                                               ; preds = %37
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = shl i32 %47, 4
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = add nsw i32 %48, %49
  store i32 %50, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = trunc i32 %53 to i8
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %5, align 8, !tbaa !5
  store i8 %54, ptr %55, align 1, !tbaa !11
  store i32 0, ptr %10, align 4
  br label %57

57:                                               ; preds = %46, %45, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %58 = load i32, ptr %10, align 4
  switch i32 %58, label %75 [
    i32 0, label %59
    i32 2, label %17
  ]

59:                                               ; preds = %57
  br label %66

60:                                               ; preds = %21
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %6, align 8, !tbaa !5
  %63 = load i8, ptr %61, align 1, !tbaa !11
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i32 1
  store ptr %65, ptr %5, align 8, !tbaa !5
  store i8 %63, ptr %64, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %60, %59
  br label %17, !llvm.loop !12

67:                                               ; preds = %17
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %68, align 1, !tbaa !11
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = ptrtoint ptr %69 to i64
  %72 = ptrtoint ptr %70 to i64
  %73 = sub i64 %71, %72
  %74 = trunc i64 %73 to i32
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %74

75:                                               ; preds = %57
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @hexVal(i32 noundef) #1

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @agoo_req_query_decode(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds i8, ptr %0, i64 %3
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.backedge
  %.02233 = phi ptr [ %.022.be, %.backedge ], [ %0, %2 ]
  %.02332 = phi ptr [ %.023.be, %.backedge ], [ %0, %2 ]
  %6 = load i8, ptr %.02332, align 1, !tbaa !5
  %7 = icmp eq i8 %6, 37
  %8 = getelementptr inbounds i8, ptr %.02332, i64 1
  br i1 %7, label %9, label %.backedge.sink.split

9:                                                ; preds = %.lr.ph
  %10 = load i8, ptr %8, align 1, !tbaa !5
  %11 = sext i8 %10 to i32
  %12 = tail call i32 @hexVal(i32 noundef %11)
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %.backedge.sink.split, label %14, !llvm.loop !8

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %.02332, i64 2
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  %18 = tail call i32 @hexVal(i32 noundef %17)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %.backedge, label %.thread, !llvm.loop !8

.thread:                                          ; preds = %14
  %20 = shl i32 %12, 4
  %21 = add nsw i32 %18, %20
  %22 = getelementptr inbounds i8, ptr %.02332, i64 3
  %23 = trunc i32 %21 to i8
  br label %.backedge.sink.split

.backedge.sink.split:                             ; preds = %.thread, %.lr.ph, %9
  %.sink = phi i8 [ 37, %9 ], [ %23, %.thread ], [ %6, %.lr.ph ]
  %.023.be.ph = phi ptr [ %8, %9 ], [ %22, %.thread ], [ %8, %.lr.ph ]
  %24 = getelementptr inbounds i8, ptr %.02233, i64 1
  store i8 %.sink, ptr %.02233, align 1, !tbaa !5
  br label %.backedge

.backedge:                                        ; preds = %.backedge.sink.split, %14
  %.023.be = phi ptr [ %15, %14 ], [ %.023.be.ph, %.backedge.sink.split ]
  %.022.be = phi ptr [ %.02233, %14 ], [ %24, %.backedge.sink.split ]
  %25 = icmp ult ptr %.023.be, %4
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.backedge, %2
  %.022.lcssa = phi ptr [ %0, %2 ], [ %.022.be, %.backedge ]
  store i8 0, ptr %.022.lcssa, align 1, !tbaa !5
  %26 = ptrtoint ptr %.022.lcssa to i64
  %27 = ptrtoint ptr %0 to i64
  %28 = sub i64 %26, %27
  %29 = trunc i64 %28 to i32
  ret i32 %29
}

; Function Attrs: nounwind uwtable
declare hidden i32 @hexVal(i32 noundef) local_unnamed_addr #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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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