; 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 }
%struct.redisReader = type { i32, [128 x i8], ptr, i64, i64, i64, [9 x %struct.redisReadTask], i32, ptr, ptr, ptr }
%struct.redisReadTask = type { i32, i32, i32, ptr, ptr, ptr }

@.str.8 = external hidden unnamed_addr constant [29 x i8], align 1

; 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
declare dso_local i32 @redisReaderFeed(ptr noundef, ptr noundef, i64 noundef) #1

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

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

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

11:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.redisContext, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = getelementptr inbounds [16384 x i8], ptr %4, i64 0, i64 0
  %17 = call i64 @read(i32 noundef %15, ptr noundef %16, i64 noundef 16384)
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %5, align 4, !tbaa !13
  %19 = load i32, ptr %5, align 4, !tbaa !13
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %35

21:                                               ; preds = %12
  %22 = call ptr @__errno_location() #5
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp eq i32 %23, 11
  br i1 %24, label %25, label %32

25:                                               ; preds = %21
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.redisContext, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = and i32 %28, 1
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  br label %34

32:                                               ; preds = %25, %21
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @__redisSetError(ptr noundef %33, i32 noundef 1, ptr noundef null)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

34:                                               ; preds = %31
  br label %63

35:                                               ; preds = %12
  %36 = load i32, ptr %5, align 4, !tbaa !13
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  call void @__redisSetError(ptr noundef %39, i32 noundef 3, ptr noundef @.str.8)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

40:                                               ; preds = %35
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.redisContext, ptr %41, i32 0, i32 5
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = getelementptr inbounds [16384 x i8], ptr %4, i64 0, i64 0
  %45 = load i32, ptr %5, align 4, !tbaa !13
  %46 = sext i32 %45 to i64
  %47 = call i32 @redisReaderFeed(ptr noundef %43, ptr noundef %44, i64 noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %61

49:                                               ; preds = %40
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.redisContext, ptr %51, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = getelementptr inbounds %struct.redisReader, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.redisContext, ptr %56, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.redisReader, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds [128 x i8], ptr %59, i64 0, i64 0
  call void @__redisSetError(ptr noundef %50, i32 noundef %55, ptr noundef %60)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

61:                                               ; preds = %40
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %34
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %64

64:                                               ; preds = %63, %49, %38, %32, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16384, ptr %4) #4
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #3

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 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 #3 = { "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 }
attributes #5 = { 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, !11, i64 132}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 136}
!15 = !{!10, !6, i64 152}
!16 = !{!17, !11, i64 0}
!17 = !{!"redisReader", !11, i64 0, !7, i64 4, !6, i64 136, !18, i64 144, !18, i64 152, !18, i64 160, !7, i64 168, !11, i64 528, !6, i64 536, !6, i64 544, !6, i64 552}
!18 = !{!"long", !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"

@.str.8 = external hidden unnamed_addr constant [29 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @redisReaderFeed(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @redisBufferRead(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [16384 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16384, ptr nonnull %2) #4
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %28

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 132
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = call i64 @read(i32 noundef %6, ptr noundef nonnull %2, i64 noundef 16384) #4
  %8 = trunc i64 %7 to i32
  switch i32 %8, label %19 [
    i32 -1, label %9
    i32 0, label %18
  ]

9:                                                ; preds = %4
  %10 = tail call ptr @__errno_location() #5
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = icmp eq i32 %11, 11
  br i1 %12, label %13, label %17

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 136
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = and i32 %15, 1
  %.not14 = icmp eq i32 %16, 0
  br i1 %.not14, label %28, label %17

17:                                               ; preds = %13, %9
  tail call void @__redisSetError(ptr noundef nonnull %0, i32 noundef 1, ptr noundef null)
  br label %28

18:                                               ; preds = %4
  tail call void @__redisSetError(ptr noundef nonnull %0, i32 noundef 3, ptr noundef nonnull @.str.8)
  br label %28

19:                                               ; preds = %4
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %sext = shl i64 %7, 32
  %22 = ashr exact i64 %sext, 32
  %23 = call i32 @redisReaderFeed(ptr noundef %21, ptr noundef nonnull %2, i64 noundef %22)
  %.not13 = icmp eq i32 %23, 0
  br i1 %.not13, label %28, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %20, align 8, !tbaa !14
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %25, i64 4
  call void @__redisSetError(ptr noundef nonnull %0, i32 noundef %26, ptr noundef nonnull %27)
  br label %28

28:                                               ; preds = %13, %19, %1, %24, %18, %17
  %.0 = phi i32 [ -1, %17 ], [ -1, %18 ], [ -1, %24 ], [ -1, %1 ], [ 0, %19 ], [ 0, %13 ]
  call void @llvm.lifetime.end.p0(i64 16384, ptr nonnull %2) #4
  ret i32 %.0
}

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !7, i64 132}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 136}
!14 = !{!6, !10, i64 152}
!15 = !{!16, !7, i64 0}
!16 = !{!"redisReader", !7, i64 0, !8, i64 4, !10, i64 136, !17, i64 144, !17, i64 152, !17, i64 160, !8, i64 168, !7, i64 528, !10, i64 536, !10, i64 544, !10, i64 552}
!17 = !{!"long", !8, i64 0}


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