#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 */
int /*<<< orphan*/ log_printf(int, char *, char *);
scalar_t__ netRecv(char *, int);
scalar_t__ netUpdateBuffer(char *, int, int);
char *netReadLine() {
  static int bufferBenutzt = 0;
  static int bufferEnde = 0;
  static char bufferGet[251];
  if (bufferBenutzt > 0 && bufferEnde > 0) {
    bufferBenutzt -= netUpdateBuffer(bufferGet, bufferBenutzt, bufferEnde);
  }
  while (1) {
    for (int i = 0; i < bufferBenutzt; i++) {
      if (bufferGet[i] == '\n') {
        bufferGet[i] = '\0';
        bufferEnde = i;
        log_printf(2,
                   "\033[1m\033[33m"
                   "S: "
                   "\033[0m"
                   "%s\n",
                   bufferGet);
        return bufferGet;
      }
    }
    bufferBenutzt += netRecv(bufferGet + bufferBenutzt, 251 - bufferBenutzt);
  }
}


x86 assembly (clang, -O0):
<netReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f11(%rip)
jle    117d <netReadLine+0x4d>
cmpl   $0x0,0x2f08(%rip)
jle    117d <netReadLine+0x4d>
mov    0x2ef8(%rip),%esi
mov    0x2ef6(%rip),%edx
lea    0x2efb(%rip),%rdi
call   1030 <netUpdateBuffer@plt>
mov    %rax,%rcx
movslq 0x2edc(%rip),%rax
sub    %rcx,%rax
mov    %eax,0x2ed3(%rip)
jmp    1182 <netReadLine+0x52>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    0x2ebe(%rip),%eax
jge    1200 <netReadLine+0xd0>
movslq -0x4(%rbp),%rcx
lea    0x2ebd(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ed <netReadLine+0xbd>
movslq -0x4(%rbp),%rcx
lea    0x2ea5(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    %eax,0x2e8c(%rip)
mov    $0x2,%edi
lea    0xe2c(%rip),%rsi
lea    0x2e85(%rip),%rdx
call   1040 <log_printf@plt>
lea    0x2e79(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret
jmp    11f2 <netReadLine+0xc2>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <netReadLine+0x59>
movslq 0x2e49(%rip),%rax
lea    0x2e52(%rip),%rdi
add    %rax,%rdi
mov    $0xfb,%esi
sub    0x2e34(%rip),%esi
call   1050 <netRecv@plt>
mov    %rax,%rcx
movslq 0x2e25(%rip),%rax
add    %rcx,%rax
mov    %eax,0x2e1c(%rip)
jmp    1182 <netReadLine+0x52>

x86 assembly (clang, -O2):
<netReadLine>:
push   %rbx
mov    0x2f19(%rip),%eax
mov    0x2f17(%rip),%edx
test   %eax,%eax
jle    1164 <netReadLine+0x34>
test   %edx,%edx
jle    1164 <netReadLine+0x34>
lea    0x2f14(%rip),%rdi
mov    %eax,%esi
call   1030 <netUpdateBuffer@plt>
mov    %rax,%rcx
mov    0x2ef4(%rip),%eax
sub    %ecx,%eax
mov    %eax,0x2eec(%rip)
test   %eax,%eax
jle    118f <netReadLine+0x5f>
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x2eed(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0xa,(%rcx,%rbx,1)
je     11b0 <netReadLine+0x80>
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    1180 <netReadLine+0x50>
movslq %eax,%rcx
lea    0x2ec7(%rip),%rdi
add    %rcx,%rdi
mov    $0xfb,%esi
sub    %eax,%esi
call   1050 <netRecv@plt>
add    0x2ea2(%rip),%eax
jmp    115e <netReadLine+0x2e>
movb   $0x0,(%rcx,%rbx,1)
mov    %ecx,0x2e9a(%rip)
lea    0xe3f(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
call   1040 <log_printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@netReadLine.bufferBenutzt = internal global i32 0
@netReadLine.bufferEnde = internal global i32 0
@netReadLine.bufferGet = internal global [251 x i8] zeroinitializer
@.str = [20 x i8] c"\1B[1m\1B[33mS: \1B[0m%s\0A\00"
define i8* @netReadLine() {
%1 = alloca i32
%2 = load i32, i32* @netReadLine.bufferBenutzt
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %0
%5 = load i32, i32* @netReadLine.bufferEnde
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = load i32, i32* @netReadLine.bufferBenutzt
%9 = load i32, i32* @netReadLine.bufferEnde
%10 = call i64 @netUpdateBuffer(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* @netReadLine.bufferBenutzt
%12 = sext i32 %11 to i64
%13 = sub nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* @netReadLine.bufferBenutzt
br label %15
15: ; preds = %7, %4, %0
br label %16
16: ; preds = %15, %38
store i32 0, i32* %1
br label %17
17: ; preds = %35, %16
%18 = load i32, i32* %1
%19 = load i32, i32* @netReadLine.bufferBenutzt
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %1
store i32 %32, i32* @netReadLine.bufferEnde
%33 = call i32 @log_printf(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0))
ret i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0)
34: ; preds = %21
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %17
38: ; preds = %17
%39 = load i32, i32* @netReadLine.bufferBenutzt
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0), i64 %40
%42 = load i32, i32* @netReadLine.bufferBenutzt
%43 = sub nsw i32 251, %42
%44 = call i64 @netRecv(i8* %41, i32 %43)
%45 = load i32, i32* @netReadLine.bufferBenutzt
%46 = sext i32 %45 to i64
%47 = add nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* @netReadLine.bufferBenutzt
br label %16
}

LLVM IR (-O2):
@netReadLine.bufferBenutzt = internal unnamed_addr global i32 0
@netReadLine.bufferEnde = internal unnamed_addr global i32 0
@netReadLine.bufferGet = internal global [251 x i8] zeroinitializer
@.str = [20 x i8] c"\1B[1m\1B[33mS: \1B[0m%s\0A\00"
define i8* @netReadLine() {
%1 = load i32, i32* @netReadLine.bufferBenutzt
%2 = icmp sgt i32 %1, 0
%3 = load i32, i32* @netReadLine.bufferEnde
%4 = icmp sgt i32 %3, 0
%5 = select i1 %2, i1 %4, i1 false
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = tail call i64 @netUpdateBuffer(i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0), i32 %1, i32 %3)
%8 = load i32, i32* @netReadLine.bufferBenutzt
%9 = trunc i64 %7 to i32
%10 = sub i32 %8, %9
br label %11
11: ; preds = %26, %6
%12 = phi i32 [ %10, %6 ], [ %33, %26 ]
store i32 %12, i32* @netReadLine.bufferBenutzt
br label %13
13: ; preds = %11, %0
%14 = phi i32 [ %1, %0 ], [ %12, %11 ]
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = zext i32 %14 to i64
br label %18
18: ; preds = %16, %23
%19 = phi i64 [ 0, %16 ], [ %24, %23 ]
%20 = getelementptr inbounds [251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %34, label %23
23: ; preds = %18
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, %17
br i1 %25, label %26, label %18
26: ; preds = %23, %13
%27 = sext i32 %14 to i64
%28 = getelementptr inbounds [251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 %27
%29 = sub nsw i32 251, %14
%30 = tail call i64 @netRecv(i8* %28, i32 %29)
%31 = load i32, i32* @netReadLine.bufferBenutzt
%32 = trunc i64 %30 to i32
%33 = add i32 %31, %32
br label %11
34: ; preds = %18
%35 = trunc i64 %19 to i32
%36 = and i64 %19, 4294967295
%37 = getelementptr inbounds [251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 %36
store i8 0, i8* %37
store i32 %35, i32* @netReadLine.bufferEnde
%38 = tail call i32 @log_printf(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0))
ret i8* getelementptr inbounds ([251 x i8], [251 x i8]* @netReadLine.bufferGet, i64 0, i64 0)
}