#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 */
char socreadByte(int);
int socreadln(int sockfd, char *s, int size) {
  char c;
  unsigned char *p = (unsigned char *)s;
  if (!s)
    return 0;
  while (--size && ((c = socreadByte(sockfd)) > 0)) {
    *p++ = c;
    if (c == '\n' || c == '\0')
      break;
  }
  *p = 0;
  return 1;
}


x86 assembly (clang, -O0):
<socreadln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1141 <socreadln+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11ca <socreadln+0xba>
jmp    1146 <socreadln+0x36>
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1174 <socreadln+0x64>
mov    -0x8(%rbp),%edi
call   1030 <socreadByte@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1184 <socreadln+0x74>
jmp    11bc <socreadln+0xac>
mov    -0x15(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11b2 <socreadln+0xa2>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    11b7 <socreadln+0xa7>
jmp    11bc <socreadln+0xac>
jmp    1146 <socreadln+0x36>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socreadln>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
je     1155 <socreadln+0x45>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
add    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
sub    $0x1,%ebp
jb     114b <socreadln+0x3b>
mov    %r14d,%edi
call   1030 <socreadByte@plt>
test   %al,%al
jle    114b <socreadln+0x3b>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1130 <socreadln+0x20>
movb   $0x0,(%rbx)
mov    $0x1,%eax
jmp    1157 <socreadln+0x47>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @socreadln(i32 %0, i8* writeonly %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %18, label %5
5: ; preds = %3, %13
%6 = phi i32 [ %8, %13 ], [ %2, %3 ]
%7 = phi i8* [ %14, %13 ], [ %1, %3 ]
%8 = add nsw i32 %6, -1
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = tail call signext i8 @socreadByte(i32 %0)
%12 = icmp sgt i8 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%15 = icmp eq i8 %11, 10
br i1 %15, label %16, label %5
16: ; preds = %5, %13, %10
%17 = phi i8* [ %14, %13 ], [ %7, %10 ], [ %7, %5 ]
store i8 0, i8* %17
br label %18
18: ; preds = %3, %16
%19 = phi i32 [ 1, %16 ], [ 0, %3 ]
ret i32 %19
}