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

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

; 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

declare ptr @sdsempty() #2

declare void @sdsfree(ptr noundef) #2

declare ptr @sdsrange(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @__redisSetError(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

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

12:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.redisContext, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = call i64 @sdslen(ptr noundef %16)
  %18 = icmp ugt i64 %17, 0
  br i1 %18, label %19, label %77

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.redisContext, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.redisContext, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.redisContext, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = call i64 @sdslen(ptr noundef %28)
  %30 = call i64 @write(i32 noundef %22, ptr noundef %25, i64 noundef %29)
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr %6, align 4, !tbaa !14
  %32 = load i32, ptr %6, align 4, !tbaa !14
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %48

34:                                               ; preds = %19
  %35 = call ptr @__errno_location() #6
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = icmp eq i32 %36, 11
  br i1 %37, label %38, label %45

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.redisContext, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %38
  br label %47

45:                                               ; preds = %38, %34
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  call void @__redisSetError(ptr noundef %46, i32 noundef 1, ptr noundef null)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

47:                                               ; preds = %44
  br label %76

48:                                               ; preds = %19
  %49 = load i32, ptr %6, align 4, !tbaa !14
  %50 = icmp sgt i32 %49, 0
  br i1 %50, label %51, label %75

51:                                               ; preds = %48
  %52 = load i32, ptr %6, align 4, !tbaa !14
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.redisContext, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = call i64 @sdslen(ptr noundef %55)
  %57 = trunc i64 %56 to i32
  %58 = icmp eq i32 %52, %57
  br i1 %58, label %59, label %66

59:                                               ; preds = %51
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.redisContext, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  call void @sdsfree(ptr noundef %62)
  %63 = call ptr @sdsempty()
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.redisContext, ptr %64, i32 0, i32 4
  store ptr %63, ptr %65, align 8, !tbaa !12
  br label %74

66:                                               ; preds = %51
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.redisContext, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !12
  %70 = load i32, ptr %6, align 4, !tbaa !14
  %71 = call ptr @sdsrange(ptr noundef %69, i32 noundef %70, i32 noundef -1)
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.redisContext, ptr %72, i32 0, i32 4
  store ptr %71, ptr %73, align 8, !tbaa !12
  br label %74

74:                                               ; preds = %66, %59
  br label %75

75:                                               ; preds = %74, %48
  br label %76

76:                                               ; preds = %75, %47
  br label %77

77:                                               ; preds = %76, %13
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %88

80:                                               ; preds = %77
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.redisContext, ptr %81, i32 0, i32 4
  %83 = load ptr, ptr %82, align 8, !tbaa !12
  %84 = call i64 @sdslen(ptr noundef %83)
  %85 = icmp eq i64 %84, 0
  %86 = zext i1 %85 to i32
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %86, ptr %87, align 4, !tbaa !14
  br label %88

88:                                               ; preds = %80, %77
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

89:                                               ; preds = %88, %45, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %90 = load i32, ptr %3, align 4
  ret i32 %90
}

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #2

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 = { "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 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 #4 = { nounwind willreturn memory(none) "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 = { nounwind willreturn memory(none) }

!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, !11, i64 0}
!10 = !{!"redisContext", !11, i64 0, !7, i64 4, !11, i64 132, !11, i64 136, !6, i64 144, !6, i64 152}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 144}
!13 = !{!10, !11, i64 132}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 136}


; 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

declare ptr @sdsempty() local_unnamed_addr #1

declare void @sdsfree(ptr noundef) local_unnamed_addr #1

declare ptr @sdsrange(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @__redisSetError(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @redisBufferWrite(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #2 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %43

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 144
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = tail call i64 @sdslen(ptr noundef %6)
  %.not21 = icmp eq i64 %7, 0
  br i1 %.not21, label %37, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 132
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = load ptr, ptr %5, align 8, !tbaa !11
  %12 = tail call i64 @sdslen(ptr noundef %11)
  %13 = tail call i64 @write(i32 noundef %10, ptr noundef %11, i64 noundef %12) #5
  %14 = trunc i64 %13 to i32
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %25

16:                                               ; preds = %8
  %17 = tail call ptr @__errno_location() #6
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = icmp eq i32 %18, 11
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 136
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = and i32 %22, 1
  %.not22 = icmp eq i32 %23, 0
  br i1 %.not22, label %37, label %24

24:                                               ; preds = %20, %16
  tail call void @__redisSetError(ptr noundef nonnull %0, i32 noundef 1, ptr noundef null)
  br label %43

25:                                               ; preds = %8
  %26 = icmp sgt i32 %14, 0
  br i1 %26, label %27, label %37

27:                                               ; preds = %25
  %28 = load ptr, ptr %5, align 8, !tbaa !11
  %29 = tail call i64 @sdslen(ptr noundef %28)
  %30 = trunc i64 %29 to i32
  %31 = icmp eq i32 %14, %30
  %32 = load ptr, ptr %5, align 8, !tbaa !11
  br i1 %31, label %33, label %35

33:                                               ; preds = %27
  tail call void @sdsfree(ptr noundef %32) #5
  %34 = tail call ptr @sdsempty() #5
  br label %.sink.split

35:                                               ; preds = %27
  %36 = tail call ptr @sdsrange(ptr noundef %32, i32 noundef %14, i32 noundef -1) #5
  br label %.sink.split

.sink.split:                                      ; preds = %35, %33
  %.sink = phi ptr [ %34, %33 ], [ %36, %35 ]
  store ptr %.sink, ptr %5, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %.sink.split, %20, %25, %4
  %.not23 = icmp eq ptr %1, null
  br i1 %.not23, label %43, label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %5, align 8, !tbaa !11
  %40 = tail call i64 @sdslen(ptr noundef %39)
  %41 = icmp eq i64 %40, 0
  %42 = zext i1 %41 to i32
  store i32 %42, ptr %1, align 4, !tbaa !13
  br label %43

43:                                               ; preds = %37, %38, %2, %24
  %.0 = phi i32 [ -1, %24 ], [ -1, %2 ], [ 0, %38 ], [ 0, %37 ]
  ret i32 %.0
}

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #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 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nofree "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 = { nounwind willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"redisContext", !7, i64 0, !8, i64 4, !7, i64 132, !7, i64 136, !10, i64 144, !10, i64 152}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 144}
!12 = !{!6, !7, i64 132}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 136}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass