#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
int recv(int, char *, int, int /*<<< orphan*/);
char *ProcGets(int sock, char *st, size_t len) {
  ssize_t r;
  char *buf = st;
  while (--len) {
    r = recv(sock, buf, 1, MSG_WAITALL);
    if (r != 1)
      return (NULL);
    if (*buf == '\n')
      break;
    if (*buf != '\r')
      ++buf;
  }
  *buf = '\0';
  return st;
}


x86 assembly (clang, -O0):
<ProcGets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ab <ProcGets+0x9b>
mov    -0xc(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1175 <ProcGets+0x65>
movq   $0x0,-0x8(%rbp)
jmp    11ba <ProcGets+0xaa>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    118a <ProcGets+0x7a>
jmp    11ab <ProcGets+0x9b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     11a6 <ProcGets+0x96>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    112b <ProcGets+0x1b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ProcGets>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rsi,%rbp
add    $0xffffffffffffffff,%rbx
je     116f <ProcGets+0x5f>
mov    %edi,%r15d
mov    0x2ea7(%rip),%r12
mov    %r14,%rbp
jmp    114a <ProcGets+0x3a>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     116f <ProcGets+0x5f>
mov    (%r12),%ecx
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    1175 <ProcGets+0x65>
movzbl 0x0(%rbp),%eax
cmp    $0xd,%al
je     1144 <ProcGets+0x34>
cmp    $0xa,%al
jne    1140 <ProcGets+0x30>
movb   $0x0,0x0(%rbp)
jmp    1178 <ProcGets+0x68>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MSG_WAITALL = global i32 0
define i8* @ProcGets(i32 %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %6
store i8* %10, i8** %9
br label %11
11: ; preds = %37, %3
%12 = load i64, i64* %7
%13 = add i64 %12, -1
store i64 %13, i64* %7
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i8*, i8** %9
%18 = load i32, i32* @MSG_WAITALL
%19 = call i32 @recv(i32 %16, i8* %17, i32 1, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %15
store i8* null, i8** %4
br label %41
23: ; preds = %15
%24 = load i8*, i8** %9
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %23
br label %38
29: ; preds = %23
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 13
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
br label %37
37: ; preds = %34, %29
br label %11
38: ; preds = %28, %11
%39 = load i8*, i8** %9
store i8 0, i8* %39
%40 = load i8*, i8** %6
store i8* %40, i8** %4
br label %41
41: ; preds = %38, %22
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
@MSG_WAITALL = global i32 0
define i8* @ProcGets(i32 %0, i8* %1, i64 %2) {
%4 = add i64 %2, -1
%5 = icmp eq i64 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %3, %16
%7 = phi i64 [ %18, %16 ], [ %4, %3 ]
%8 = phi i8* [ %17, %16 ], [ %1, %3 ]
%9 = load i32, i32* @MSG_WAITALL
%10 = tail call i32 @recv(i32 %0, i8* %8, i32 1, i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = load i8, i8* %8
switch i8 %13, label %14 [
i8 10, label %20
i8 13, label %16
]
14: ; preds = %12
%15 = getelementptr inbounds i8, i8* %8, i64 1
br label %16
16: ; preds = %12, %14
%17 = phi i8* [ %15, %14 ], [ %8, %12 ]
%18 = add i64 %7, -1
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %6
20: ; preds = %16, %12, %3
%21 = phi i8* [ %1, %3 ], [ %8, %12 ], [ %17, %16 ]
store i8 0, i8* %21
br label %22
22: ; preds = %6, %20
%23 = phi i8* [ %1, %20 ], [ null, %6 ]
ret i8* %23
}