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

; 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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3zmq24socks_response_decoder_t5inputEi(ptr noundef nonnull align 8 dereferenceable(272) %0, i32 noundef %1) #4 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  %12 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = icmp ult i64 %13, 5
  br i1 %14, label %15, label %19

15:                                               ; preds = %2
  %16 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = sub i64 5, %17
  store i64 %18, ptr %6, align 8, !tbaa !11
  br label %72

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  %20 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %21 = getelementptr inbounds [262 x i8], ptr %20, i64 0, i64 3
  %22 = load i8, ptr %21, align 1, !tbaa !15
  store i8 %22, ptr %7, align 1, !tbaa !15
  br label %23

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

27:                                               ; preds = %23
  %28 = load i8, ptr %7, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  %30 = icmp eq i32 %29, 3
  br i1 %30, label %35, label %31

31:                                               ; preds = %27
  %32 = load i8, ptr %7, align 1, !tbaa !15
  %33 = zext i8 %32 to i32
  %34 = icmp eq i32 %33, 4
  br label %35

35:                                               ; preds = %31, %27, %23
  %36 = phi i1 [ true, %27 ], [ true, %23 ], [ %34, %31 ]
  %37 = xor i1 %36, true
  %38 = zext i1 %37 to i64
  %39 = call i64 @llvm.expect.i64(i64 %38, i64 0)
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %35
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.8, ptr noundef @.str.2, i32 noundef 329) #5
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = call i32 @fflush(ptr noundef %44)
  call void @_ZN3zmq9zmq_abortEPKc(ptr noundef @.str.8)
  br label %46

46:                                               ; preds = %41, %35
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load i8, ptr %7, align 1, !tbaa !15
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  store i64 5, ptr %6, align 8, !tbaa !11
  br label %71

53:                                               ; preds = %48
  %54 = load i8, ptr %7, align 1, !tbaa !15
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 3
  br i1 %56, label %57, label %64

57:                                               ; preds = %53
  %58 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %59 = getelementptr inbounds [262 x i8], ptr %58, i64 0, i64 4
  %60 = load i8, ptr %59, align 4, !tbaa !15
  %61 = sext i8 %60 to i32
  %62 = add nsw i32 %61, 2
  %63 = sext i32 %62 to i64
  store i64 %63, ptr %6, align 8, !tbaa !11
  br label %70

64:                                               ; preds = %53
  %65 = load i8, ptr %7, align 1, !tbaa !15
  %66 = zext i8 %65 to i32
  %67 = icmp eq i32 %66, 4
  br i1 %67, label %68, label %69

68:                                               ; preds = %64
  store i64 17, ptr %6, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %68, %64
  br label %70

70:                                               ; preds = %69, %57
  br label %71

71:                                               ; preds = %70, %52
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  br label %72

72:                                               ; preds = %71, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %75 = getelementptr inbounds [262 x i8], ptr %74, i64 0, i64 0
  %76 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %77 = load i64, ptr %76, align 8, !tbaa !13
  %78 = getelementptr inbounds i8, ptr %75, i64 %77
  %79 = load i64, ptr %6, align 8, !tbaa !11
  %80 = call noundef i32 @_ZN3zmq8tcp_readEiPvm(i32 noundef %73, ptr noundef %78, i64 noundef %79)
  store i32 %80, ptr %8, align 4, !tbaa !9
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = icmp sgt i32 %81, 0
  br i1 %82, label %83, label %144

83:                                               ; preds = %72
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !13
  %88 = add i64 %87, %85
  store i64 %88, ptr %86, align 8, !tbaa !13
  %89 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %90 = getelementptr inbounds [262 x i8], ptr %89, i64 0, i64 0
  %91 = load i8, ptr %90, align 8, !tbaa !15
  %92 = sext i8 %91 to i32
  %93 = icmp ne i32 %92, 5
  br i1 %93, label %94, label %95

94:                                               ; preds = %83
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %146

95:                                               ; preds = %83
  %96 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !13
  %98 = icmp uge i64 %97, 2
  br i1 %98, label %99, label %107

99:                                               ; preds = %95
  %100 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %101 = getelementptr inbounds [262 x i8], ptr %100, i64 0, i64 1
  %102 = load i8, ptr %101, align 1, !tbaa !15
  %103 = sext i8 %102 to i32
  %104 = icmp sgt i32 %103, 8
  br i1 %104, label %105, label %106

105:                                              ; preds = %99
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %146

106:                                              ; preds = %99
  br label %107

107:                                              ; preds = %106, %95
  %108 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %109 = load i64, ptr %108, align 8, !tbaa !13
  %110 = icmp uge i64 %109, 3
  br i1 %110, label %111, label %119

111:                                              ; preds = %107
  %112 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %113 = getelementptr inbounds [262 x i8], ptr %112, i64 0, i64 2
  %114 = load i8, ptr %113, align 2, !tbaa !15
  %115 = sext i8 %114 to i32
  %116 = icmp ne i32 %115, 0
  br i1 %116, label %117, label %118

117:                                              ; preds = %111
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %146

118:                                              ; preds = %111
  br label %119

119:                                              ; preds = %118, %107
  %120 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 1
  %121 = load i64, ptr %120, align 8, !tbaa !13
  %122 = icmp uge i64 %121, 4
  br i1 %122, label %123, label %143

123:                                              ; preds = %119
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %124 = getelementptr inbounds %"class.zmq::socks_response_decoder_t", ptr %11, i32 0, i32 0
  %125 = getelementptr inbounds [262 x i8], ptr %124, i64 0, i64 3
  %126 = load i8, ptr %125, align 1, !tbaa !15
  store i8 %126, ptr %10, align 1, !tbaa !15
  %127 = load i8, ptr %10, align 1, !tbaa !15
  %128 = zext i8 %127 to i32
  %129 = icmp ne i32 %128, 1
  br i1 %129, label %130, label %139

130:                                              ; preds = %123
  %131 = load i8, ptr %10, align 1, !tbaa !15
  %132 = zext i8 %131 to i32
  %133 = icmp ne i32 %132, 3
  br i1 %133, label %134, label %139

134:                                              ; preds = %130
  %135 = load i8, ptr %10, align 1, !tbaa !15
  %136 = zext i8 %135 to i32
  %137 = icmp ne i32 %136, 4
  br i1 %137, label %138, label %139

138:                                              ; preds = %134
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %140

139:                                              ; preds = %134, %130, %123
  store i32 0, ptr %9, align 4
  br label %140

140:                                              ; preds = %139, %138
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  %141 = load i32, ptr %9, align 4
  switch i32 %141, label %146 [
    i32 0, label %142
  ]

142:                                              ; preds = %140
  br label %143

143:                                              ; preds = %142, %119
  br label %144

144:                                              ; preds = %143, %72
  %145 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %145, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %146

146:                                              ; preds = %144, %140, %117, %105, %94
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %147 = load i32, ptr %3, align 4
  ret i32 %147
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 264}
!14 = !{!"_ZTSN3zmq24socks_response_decoder_tE", !7, i64 0, !12, i64 264}
!15 = !{!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

declare noundef i32 @_ZN3zmq8tcp_readEiPvm(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

6:                                                ; preds = %2
  %7 = sub nuw nsw i64 5, %4
  br label %21

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 3
  %10 = load i8, ptr %9, align 1, !tbaa !10
  switch i8 %10, label %.critedge [
    i8 3, label %15
    i8 1, label %21
    i8 4, label %20
  ]

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

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i8, ptr %16, align 4, !tbaa !10
  %18 = sext i8 %17 to i64
  %19 = add nsw i64 %18, 2
  br label %21

20:                                               ; preds = %8
  br label %21

21:                                               ; preds = %8, %20, %15, %.critedge, %6
  %22 = phi i64 [ %4, %6 ], [ %4, %15 ], [ %4, %20 ], [ %4, %8 ], [ %.pre, %.critedge ]
  %.126 = phi i64 [ %7, %6 ], [ %19, %15 ], [ 17, %20 ], [ 5, %8 ], [ 0, %.critedge ]
  %23 = getelementptr inbounds i8, ptr %0, i64 %22
  %24 = tail call noundef i32 @_ZN3zmq8tcp_readEiPvm(i32 noundef %1, ptr noundef nonnull %23, i64 noundef %.126)
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %45

26:                                               ; preds = %21
  %27 = zext nneg i32 %24 to i64
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = add i64 %28, %27
  store i64 %29, ptr %3, align 8, !tbaa !5
  %30 = load i8, ptr %0, align 8, !tbaa !10
  %.not = icmp eq i8 %30, 5
  br i1 %.not, label %31, label %46

31:                                               ; preds = %26
  %32 = icmp ugt i64 %29, 1
  %33 = getelementptr inbounds i8, ptr %0, i64 1
  %34 = load i8, ptr %33, align 1
  %35 = icmp sgt i8 %34, 8
  %or.cond = select i1 %32, i1 %35, i1 false
  br i1 %or.cond, label %46, label %36

36:                                               ; preds = %31
  %37 = icmp ult i64 %29, 3
  %38 = getelementptr inbounds i8, ptr %0, i64 2
  %39 = load i8, ptr %38, align 2
  %.not29 = icmp eq i8 %39, 0
  %or.cond34 = select i1 %37, i1 true, i1 %.not29
  br i1 %or.cond34, label %40, label %46

40:                                               ; preds = %36
  %41 = icmp ugt i64 %29, 3
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = getelementptr inbounds i8, ptr %0, i64 3
  %44 = load i8, ptr %43, align 1, !tbaa !10
  switch i8 %44, label %46 [
    i8 4, label %45
    i8 3, label %45
    i8 1, label %45
  ]

45:                                               ; preds = %42, %42, %42, %40, %21
  br label %46

46:                                               ; preds = %42, %36, %31, %26, %45
  %.1 = phi i32 [ %24, %45 ], [ -1, %42 ], [ -1, %26 ], [ -1, %31 ], [ -1, %36 ]
  ret i32 %.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,SROAPass,SimplifyCFGPass,TailCallElimPass