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

/* Variables and functions */
int atol(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ readline(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ writen(int, char *, int);
void web_child(int sockfd) {
  int ntowrite;
  ssize_t nread;
  char line[1024], result[16384];
  while (1) {
    if ((nread = readline(sockfd, line, 1024)) == 0)
      return;
    ntowrite = atol(line);
    if ((ntowrite <= 0) || (ntowrite > 16384)) {
      fprintf(stderr, "client request for %d bytes\n", ntowrite);
      return;
    }
    writen(sockfd, result, ntowrite);
  }
}


x86 assembly (clang, -O0):
<web_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4410,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <readline@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    1173 <web_child+0x33>
jmp    11cd <web_child+0x8d>
lea    -0x410(%rbp),%rdi
call   1050 <atol@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1199 <web_child+0x59>
cmpl   $0x4000,-0x8(%rbp)
jle    11b6 <web_child+0x76>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11cd <web_child+0x8d>
mov    -0x4(%rbp),%edi
lea    -0x4410(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1060 <writen@plt>
jmp    114e <web_child+0xe>
add    $0x4410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<web_child>:
push   %r15
push   %r14
push   %rbx
sub    $0x4400,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1030 <readline@plt>
test   %eax,%eax
je     11c0 <web_child+0x80>
mov    %rsp,%r14
lea    0x400(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <atol@plt>
mov    %eax,%ecx
add    $0xffffbfff,%ecx
cmp    $0xffffbfff,%ecx
jbe    11a9 <web_child+0x69>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <writen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <readline@plt>
test   %eax,%eax
jne    1170 <web_child+0x30>
jmp    11c0 <web_child+0x80>
mov    0x2e30(%rip),%rcx
mov    (%rcx),%edi
lea    0xe47(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
add    $0x4400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"client request for %d bytes\0A\00"
define void @web_child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [16384 x i8]
store i32 %0, i32* %2
br label %7
7: ; preds = %1, %25
%8 = load i32, i32* %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @readline(i32 %8, i8* %9, i32 1024)
store i32 %10, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
br label %30
13: ; preds = %7
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @atol(i8* %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp sle i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 16384
br i1 %20, label %21, label %25
21: ; preds = %18, %13
%22 = load i32, i32* @stderr
%23 = load i32, i32* %3
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %30
25: ; preds = %18
%26 = load i32, i32* %2
%27 = getelementptr inbounds [16384 x i8], [16384 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %3
%29 = call i32 @writen(i32 %26, i8* %27, i32 %28)
br label %7
30: ; preds = %21, %12
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"client request for %d bytes\0A\00"
define void @web_child(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [16384 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [16384 x i8], [16384 x i8]* %3, i64 0, i64 0
%6 = call i32 @readline(i32 %0, i8* %4, i32 1024)
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %1, %15
%9 = call i32 @atol(i8* %4)
%10 = add i32 %9, -16385
%11 = icmp ult i32 %10, -16384
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %19
15: ; preds = %8
%16 = call i32 @writen(i32 %0, i8* %5, i32 %9)
%17 = call i32 @readline(i32 %0, i8* %4, i32 1024)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %8
19: ; preds = %15, %1, %12
ret void
}