#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 */
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
ssize_t recv_stuff(int sockfd, char *msg) {
  int nread = 0;
  char acc_char;
  while ((recv(sockfd, &acc_char, 1, 0) > 0) && (acc_char != '\n') &&
         (nread < 1024)) {
    if ((acc_char != '\r') && (acc_char != '\n')) {
      msg[nread] = acc_char;
      nread++;
    }
  }
  msg[nread] = '\0';
  return (nread);
}


x86 assembly (clang, -O0):
<recv_stuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x16(%rbp)
jle    116a <recv_stuff+0x5a>
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x16(%rbp)
je     116a <recv_stuff+0x5a>
cmpl   $0x400,-0x14(%rbp)
setl   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    117a <recv_stuff+0x6a>
jmp    11b0 <recv_stuff+0xa0>
movsbl -0x15(%rbp),%eax
cmp    $0xd,%eax
je     11ab <recv_stuff+0x9b>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11ab <recv_stuff+0x9b>
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <recv_stuff+0x16>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_stuff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x7(%rsp),%rsi
xor    %ebx,%ebx
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1185 <recv_stuff+0x75>
mov    0x7(%rsp),%al
cmp    $0xa,%al
je     1185 <recv_stuff+0x75>
xor    %ebx,%ebx
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xd,%al
je     115e <recv_stuff+0x4e>
movslq %ebx,%rbx
mov    %al,(%r14,%rbx,1)
add    $0x1,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jle    1185 <recv_stuff+0x75>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
je     1185 <recv_stuff+0x75>
cmp    $0x400,%ebx
jl     1150 <recv_stuff+0x40>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @recv_stuff(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i8
%4 = call i64 @recv(i32 %0, i8* %3, i32 1, i32 0)
%5 = icmp sgt i64 %4, 0
%6 = load i8, i8* %3
%7 = icmp ne i8 %6, 10
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %26
9: ; preds = %2, %17
%10 = phi i8 [ %21, %17 ], [ %6, %2 ]
%11 = phi i32 [ %18, %17 ], [ 0, %2 ]
%12 = icmp eq i8 %10, 13
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %10, i8* %15
%16 = add nsw i32 %11, 1
br label %17
17: ; preds = %13, %9
%18 = phi i32 [ %16, %13 ], [ %11, %9 ]
%19 = call i64 @recv(i32 %0, i8* %3, i32 1, i32 0)
%20 = icmp sgt i64 %19, 0
%21 = load i8, i8* %3
%22 = icmp ne i8 %21, 10
%23 = select i1 %20, i1 %22, i1 false
%24 = icmp slt i32 %18, 1024
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %9, label %26
26: ; preds = %17, %2
%27 = phi i32 [ 0, %2 ], [ %18, %17 ]
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 0, i8* %29
ret i32 %27
}