#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ sendline;
typedef int /*<<< orphan*/ recvline;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void str_echo(int sockfd) {
  ssize_t n;
  char recvline[256] = {'\0'};
  char sendline[256] = {'\0'};
  while (1) {
    bzero(sendline, sizeof(sendline));
    bzero(recvline, sizeof(recvline));
    n = read(sockfd, recvline, sizeof(recvline));
    if (n < 0) {
      if (EINTR == errno) {
        continue;
      }
      perror("read");
      exit(EXIT_FAILURE);
    }
    sprintf(sendline, "[response] %s", recvline);
    if (write(sockfd, sendline, strlen(sendline)) < 0) {
      perror("write");
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<str_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x210(%rbp),%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1232 <str_echo+0xb2>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rax
mov    0x2dd6(%rip),%rcx
cmp    (%rcx),%rax
jne    1218 <str_echo+0x98>
jmp    11b4 <str_echo+0x34>
lea    0xde1(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xdbe(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x21c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x21c(%rbp),%edi
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12a7 <str_echo+0x127>
lea    0xd7f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    11b4 <str_echo+0x34>

x86 assembly (clang, -O2):
<str_echo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
lea    0x100(%rsp),%rbp
mov    0x2d50(%rip),%r12
mov    0x2d59(%rip),%r13
lea    0xd77(%rip),%r15
jmp    129a <str_echo+0x12a>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    12fa <str_echo+0x18a>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
call   1070 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %rax,%rax
js     1290 <str_echo+0x120>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    129a <str_echo+0x12a>
lea    0xd1b(%rip),%rdi
jmp    1301 <str_echo+0x191>
lea    0xcff(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EINTR = global i64 0
@errno = global i64 0
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"[response] %s\00"
@.str.2 = [6 x i8] c"write\00"
define void @str_echo(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
store i32 %0, i32* %2
%6 = bitcast [256 x i8]* %4 to i8*
%7 = bitcast [256 x i8]* %5 to i8*
br label %8
8: ; preds = %1, %22, %41
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @bzero(i8* %9, i32 256)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = call i32 @bzero(i8* %11, i32 256)
%13 = load i32, i32* %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 256)
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %8
%19 = load i64, i64* @EINTR
%20 = load i64, i64* @errno
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %8
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %8
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%30 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* %2
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i64 @write(i32 %31, i8* %32, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %27
%38 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %27
br label %8
}

LLVM IR (-O2):
@EINTR = global i64 0
@errno = global i64 0
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"[response] %s\00"
@.str.2 = [6 x i8] c"write\00"
define void @str_echo(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %15, %1
%7 = call i32 @bzero(i8* %5, i32 256)
%8 = call i32 @bzero(i8* %4, i32 256)
%9 = call i64 @read(i32 %0, i8* %4, i32 256)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i64, i64* @EINTR
%13 = load i64, i64* @errno
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11, %20
br label %6
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %6
%21 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%22 = call i32 @strlen(i8* %5)
%23 = call i64 @write(i32 %0, i8* %5, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
}