#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ phDataReadable(int, int);
int recv(int, char *, int, int /*<<< orphan*/);
int phReadOneLine(int m_hSocket, char *lpszBuf, int nBufLen) {
  int nReadCount = 0;
  int nRecv = 0;
  lpszBuf[0] = '\0';
  for (;;) {
    if (phDataReadable(m_hSocket, 30) <= 0)
      return 0;
    nRecv = recv(m_hSocket, lpszBuf + nReadCount, 1, 0);
    if (nRecv > 0) {
      nReadCount += nRecv;
      if (lpszBuf[nReadCount - 1] == '\n') {
        if (nReadCount > 1 && lpszBuf[nReadCount - 2] == '\r') {
          lpszBuf[nReadCount - 2] = '\0';
        } else {
          lpszBuf[nReadCount - 1] = '\0';
        }
        break;
      }
      if (nReadCount == nBufLen) {
        break;
      }
    } else {
      nReadCount = -1;
      break;
    }
  }
  return nReadCount;
}


x86 assembly (clang, -O0):
<phReadOneLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    $0x1e,%esi
call   1040 <phDataReadable@plt>
cmp    $0x0,%rax
jg     116a <phReadOneLine+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    1231 <phReadOneLine+0x111>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    121a <phReadOneLine+0xfa>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1204 <phReadOneLine+0xe4>
cmpl   $0x1,-0x18(%rbp)
jle    11ee <phReadOneLine+0xce>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    11ee <phReadOneLine+0xce>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ff <phReadOneLine+0xdf>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122b <phReadOneLine+0x10b>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1215 <phReadOneLine+0xf5>
jmp    122b <phReadOneLine+0x10b>
jmp    1226 <phReadOneLine+0x106>
movl   $0xffffffff,-0x18(%rbp)
jmp    122b <phReadOneLine+0x10b>
jmp    1147 <phReadOneLine+0x27>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phReadOneLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0x0,(%rsi)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    $0x1e,%esi
call   1040 <phDataReadable@plt>
test   %rax,%rax
jle    1180 <phReadOneLine+0x60>
movslq %ebx,%rsi
add    %r14,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1184 <phReadOneLine+0x64>
add    %eax,%ebx
movslq %ebx,%rax
cmpb   $0xa,-0x1(%r14,%rax,1)
je     118b <phReadOneLine+0x6b>
cmp    %r15d,%ebx
jne    1140 <phReadOneLine+0x20>
mov    %r15d,%ebx
jmp    11aa <phReadOneLine+0x8a>
xor    %ebx,%ebx
jmp    11aa <phReadOneLine+0x8a>
mov    $0xffffffff,%ebx
jmp    11aa <phReadOneLine+0x8a>
add    $0xffffffffffffffff,%rax
add    %r14,%rax
cmp    $0x2,%ebx
jl     11a7 <phReadOneLine+0x87>
lea    -0x2(%rbx),%ecx
cmpb   $0xd,(%r14,%rcx,1)
jne    11a7 <phReadOneLine+0x87>
add    %rcx,%r14
mov    %r14,%rax
movb   $0x0,(%rax)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @phReadOneLine(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i8*, i8** %6
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
br label %12
12: ; preds = %70, %3
%13 = load i32, i32* %5
%14 = call i64 @phDataReadable(i32 %13, i32 30)
%15 = icmp sle i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 0, i32* %4
br label %73
17: ; preds = %12
%18 = load i32, i32* %5
%19 = load i8*, i8** %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @recv(i32 %18, i8* %22, i32 1, i32 0)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %69
26: ; preds = %17
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = add nsw i32 %28, %27
store i32 %29, i32* %8
%30 = load i8*, i8** %6
%31 = load i32, i32* %8
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %63
38: ; preds = %26
%39 = load i32, i32* %8
%40 = icmp sgt i32 %39, 1
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = load i32, i32* %8
%44 = sub nsw i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 13
br i1 %49, label %50, label %56
50: ; preds = %41
%51 = load i8*, i8** %6
%52 = load i32, i32* %8
%53 = sub nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 0, i8* %55
br label %62
56: ; preds = %41, %38
%57 = load i8*, i8** %6
%58 = load i32, i32* %8
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 0, i8* %61
br label %62
62: ; preds = %56, %50
br label %71
63: ; preds = %26
%64 = load i32, i32* %8
%65 = load i32, i32* %7
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %68
67: ; preds = %63
br label %71
68: ; preds = %63
br label %70
69: ; preds = %17
store i32 -1, i32* %8
br label %71
70: ; preds = %68
br label %12
71: ; preds = %69, %67, %62
%72 = load i32, i32* %8
store i32 %72, i32* %4
br label %73
73: ; preds = %71, %16
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
define i32 @phReadOneLine(i32 %0, i8* %1, i32 %2) {
store i8 0, i8* %1
br label %4
4: ; preds = %30, %3
%5 = phi i32 [ 0, %3 ], [ %14, %30 ]
%6 = tail call i64 @phDataReadable(i32 %0, i32 30)
%7 = icmp slt i64 %6, 1
br i1 %7, label %34, label %8
8: ; preds = %4
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = tail call i32 @recv(i32 %0, i8* %10, i32 1, i32 0)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %8
%14 = add nsw i32 %11, %5
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %30
20: ; preds = %13
%21 = getelementptr inbounds i8, i8* %1, i64 %16
%22 = icmp sgt i32 %14, 1
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = add nsw i32 %14, -2
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 13
br i1 %28, label %32, label %29
29: ; preds = %23, %20
br label %32
30: ; preds = %13
%31 = icmp eq i32 %14, %2
br i1 %31, label %34, label %4
32: ; preds = %23, %29
%33 = phi i8* [ %21, %29 ], [ %26, %23 ]
store i8 0, i8* %33
br label %34
34: ; preds = %30, %8, %4, %32
%35 = phi i32 [ %14, %32 ], [ -1, %8 ], [ %2, %30 ], [ 0, %4 ]
ret i32 %35
}