; LLVM IR from buaazp/zimg :: deps/hiredis (sds)

; 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.sdshdr = type { i32, i32, [0 x i8] }

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #0

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

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

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

19:                                               ; preds = %32, %2
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ule ptr %20, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %19
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = call ptr @strchr(ptr noundef %24, i32 noundef %27) #6
  %29 = icmp ne ptr %28, null
  br label %30

30:                                               ; preds = %23, %19
  %31 = phi i1 [ false, %19 ], [ %29, %23 ]
  br i1 %31, label %32, label %35

32:                                               ; preds = %30
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i32 1
  store ptr %34, ptr %8, align 8, !tbaa !5
  br label %19, !llvm.loop !10

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %49, %35
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = icmp ugt ptr %37, %38
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = call ptr @strchr(ptr noundef %41, i32 noundef %44) #6
  %46 = icmp ne ptr %45, null
  br label %47

47:                                               ; preds = %40, %36
  %48 = phi i1 [ false, %36 ], [ %46, %40 ]
  br i1 %48, label %49, label %52

49:                                               ; preds = %47
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 -1
  store ptr %51, ptr %9, align 8, !tbaa !5
  br label %36, !llvm.loop !12

52:                                               ; preds = %47
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = icmp ugt ptr %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %64

57:                                               ; preds = %52
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = ptrtoint ptr %58 to i64
  %61 = ptrtoint ptr %59 to i64
  %62 = sub i64 %60, %61
  %63 = add nsw i64 %62, 1
  br label %64

64:                                               ; preds = %57, %56
  %65 = phi i64 [ 0, %56 ], [ %63, %57 ]
  store i64 %65, ptr %10, align 8, !tbaa !13
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.sdshdr, ptr %66, i32 0, i32 2
  %68 = getelementptr inbounds [0 x i8], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = icmp ne ptr %68, %69
  br i1 %70, label %71, label %77

71:                                               ; preds = %64
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.sdshdr, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds [0 x i8], ptr %73, i64 0, i64 0
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load i64, ptr %10, align 8, !tbaa !13
  call void @llvm.memmove.p0.p0.i64(ptr align 4 %74, ptr align 1 %75, i64 %76, i1 false)
  br label %77

77:                                               ; preds = %71, %64
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.sdshdr, ptr %78, i32 0, i32 2
  %80 = load i64, ptr %10, align 8, !tbaa !13
  %81 = getelementptr inbounds [0 x i8], ptr %79, i64 0, i64 %80
  store i8 0, ptr %81, align 1, !tbaa !9
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.sdshdr, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !15
  %85 = sext i32 %84 to i64
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sdshdr, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 4, !tbaa !15
  %89 = sext i32 %88 to i64
  %90 = load i64, ptr %10, align 8, !tbaa !13
  %91 = sub i64 %89, %90
  %92 = add i64 %85, %91
  %93 = trunc i64 %92 to i32
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.sdshdr, ptr %94, i32 0, i32 1
  store i32 %93, ptr %95, align 4, !tbaa !15
  %96 = load i64, ptr %10, align 8, !tbaa !13
  %97 = trunc i64 %96 to i32
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.sdshdr, ptr %98, i32 0, i32 0
  store i32 %97, ptr %99, align 4, !tbaa !15
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, 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 8, ptr %5) #5
  ret ptr %100
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @sdstrim(ptr noundef returned %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call i64 @sdslen(ptr noundef %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 -1
  %.not39 = icmp ult ptr %5, %0
  br i1 %.not39, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %9
  %.040 = phi ptr [ %10, %9 ], [ %0, %2 ]
  %6 = load i8, ptr %.040, align 1, !tbaa !5
  %7 = sext i8 %6 to i32
  %8 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef %7) #4
  %.not35 = icmp eq ptr %8, null
  br i1 %.not35, label %.critedge, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.040, i64 1
  %.not = icmp ugt ptr %10, %5
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !8

.critedge:                                        ; preds = %.lr.ph, %9, %2
  %.0.lcssa = phi ptr [ %0, %2 ], [ %10, %9 ], [ %.040, %.lr.ph ]
  %11 = icmp ugt ptr %5, %0
  br i1 %11, label %.lr.ph44, label %.critedge2

.lr.ph44:                                         ; preds = %.critedge, %15
  %.03343 = phi ptr [ %16, %15 ], [ %5, %.critedge ]
  %12 = load i8, ptr %.03343, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef %13) #4
  %.not36 = icmp eq ptr %14, null
  br i1 %.not36, label %.critedge2, label %15

15:                                               ; preds = %.lr.ph44
  %16 = getelementptr inbounds i8, ptr %.03343, i64 -1
  %17 = icmp ugt ptr %16, %0
  br i1 %17, label %.lr.ph44, label %.critedge2, !llvm.loop !10

.critedge2:                                       ; preds = %.lr.ph44, %15, %.critedge
  %.033.lcssa = phi ptr [ %5, %.critedge ], [ %0, %15 ], [ %.03343, %.lr.ph44 ]
  %18 = icmp ugt ptr %.0.lcssa, %.033.lcssa
  %19 = ptrtoint ptr %.033.lcssa to i64
  %20 = ptrtoint ptr %.0.lcssa to i64
  %reass.sub = sub i64 %19, %20
  %21 = add i64 %reass.sub, 1
  %22 = select i1 %18, i64 0, i64 %21
  %.not37 = icmp eq ptr %.0.lcssa, %0
  br i1 %.not37, label %24, label %23

23:                                               ; preds = %.critedge2
  tail call void @llvm.memmove.p0.p0.i64(ptr align 4 %0, ptr nonnull align 1 %.0.lcssa, i64 %22, i1 false)
  br label %24

24:                                               ; preds = %23, %.critedge2
  %25 = getelementptr inbounds i8, ptr %0, i64 -8
  %26 = getelementptr inbounds [0 x i8], ptr %0, i64 0, i64 %22
  store i8 0, ptr %26, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 -4
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = load i32, ptr %25, align 4, !tbaa !11
  %30 = trunc i64 %22 to i32
  %31 = sub i32 %28, %30
  %32 = add i32 %31, %29
  store i32 %32, ptr %27, align 4, !tbaa !11
  store i32 %30, ptr %25, align 4, !tbaa !11
  ret ptr %0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3

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


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