; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/zeromq/src/socks.ll (ZNK3zmq24socks_response_decoder_t13message_readyEv)

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

%"class.zmq::socks_response_decoder_t" = type { [262 x i8], i64 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [109 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [45 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @fflush(ptr noundef) #3

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3zmq24socks_response_decoder_t13message_readyEv(ptr noundef nonnull align 8 dereferenceable(272) %0) #4 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 1
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 4
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %74

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  %12 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 0
  %13 = getelementptr inbounds [262 x i8], ptr %12, i64 0, i64 3
  %14 = load i8, ptr %13, align 1, !tbaa !12
  store i8 %14, ptr %4, align 1, !tbaa !12
  br label %15

15:                                               ; preds = %11
  %16 = load i8, ptr %4, align 1, !tbaa !12
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %27, label %19

19:                                               ; preds = %15
  %20 = load i8, ptr %4, align 1, !tbaa !12
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 3
  br i1 %22, label %27, label %23

23:                                               ; preds = %19
  %24 = load i8, ptr %4, align 1, !tbaa !12
  %25 = zext i8 %24 to i32
  %26 = icmp eq i32 %25, 4
  br label %27

27:                                               ; preds = %23, %19, %15
  %28 = phi i1 [ true, %19 ], [ true, %15 ], [ %26, %23 ]
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i64
  %31 = call i64 @llvm.expect.i64(i64 %30, i64 0)
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %27
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str, ptr noundef @.str.8, ptr noundef @.str.2, i32 noundef 363) #5
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i32 @fflush(ptr noundef %36)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.8)
  br label %38

38:                                               ; preds = %33, %27
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load i8, ptr %4, align 1, !tbaa !12
  %42 = zext i8 %41 to i32
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %48

44:                                               ; preds = %40
  %45 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = icmp eq i64 %46, 10
  store i1 %47, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %73

48:                                               ; preds = %40
  %49 = load i8, ptr %4, align 1, !tbaa !12
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 3
  br i1 %51, label %52, label %69

52:                                               ; preds = %48
  %53 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = icmp ugt i64 %54, 4
  br i1 %55, label %56, label %67

56:                                               ; preds = %52
  %57 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 0
  %60 = getelementptr inbounds [262 x i8], ptr %59, i64 0, i64 4
  %61 = load i8, ptr %60, align 4, !tbaa !12
  %62 = sext i8 %61 to i32
  %63 = add nsw i32 5, %62
  %64 = add i32 %63, 2
  %65 = zext i32 %64 to i64
  %66 = icmp eq i64 %58, %65
  br label %67

67:                                               ; preds = %56, %52
  %68 = phi i1 [ false, %52 ], [ %66, %56 ]
  store i1 %68, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %73

69:                                               ; preds = %48
  %70 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %6, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !9
  %72 = icmp eq i64 %71, 22
  store i1 %72, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %73

73:                                               ; preds = %69, %67, %44
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  br label %74

74:                                               ; preds = %73, %10
  %75 = load i1, ptr %2, align 1
  ret i1 %75
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind "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 = { mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !11, i64 264}
!10 = !{!"_ZTSN3zmq24socks_response_decoder_tE", !7, i64 0, !11, i64 264}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [109 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [45 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #0

declare void @_ZN3zmq9zmq_abortEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK3zmq24socks_response_decoder_t13message_readyEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(272) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 264
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp ult i64 %3, 4
  br i1 %4, label %26, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 3
  %7 = load i8, ptr %6, align 1, !tbaa !10
  switch i8 %7, label %.critedge [
    i8 3, label %14
    i8 1, label %12
    i8 4, label %23
  ]

.critedge:                                        ; preds = %5
  %8 = load ptr, ptr @stderr, align 8, !tbaa !11
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.2, i32 noundef 363) #3
  %10 = load ptr, ptr @stderr, align 8, !tbaa !11
  %11 = tail call i32 @fflush(ptr noundef %10)
  tail call void @_ZN3zmq9zmq_abortEPKc(ptr noundef nonnull @.str.8)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  br label %23

12:                                               ; preds = %5
  %13 = icmp eq i64 %3, 10
  br label %26

14:                                               ; preds = %5
  %15 = icmp ne i64 %3, 4
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i8, ptr %16, align 4
  %18 = sext i8 %17 to i64
  %19 = add nsw i64 %18, 7
  %20 = and i64 %19, 4294967295
  %21 = icmp eq i64 %3, %20
  %22 = select i1 %15, i1 %21, i1 false
  br label %26

23:                                               ; preds = %.critedge, %5
  %24 = phi i64 [ %.pre, %.critedge ], [ %3, %5 ]
  %25 = icmp eq i64 %24, 22
  br label %26

26:                                               ; preds = %12, %14, %23, %1
  %.1 = phi i1 [ false, %1 ], [ %13, %12 ], [ %22, %14 ], [ %25, %23 ]
  ret i1 %.1
}

attributes #0 = { nofree nounwind "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 = { mustprogress 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 = { cold 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, !9, i64 264}
!6 = !{!"_ZTSN3zmq24socks_response_decoder_tE", !7, i64 0, !9, i64 264}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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