sock_send_recv(fd_sock, send_data, recv_data) char *fd_sock;
char *send_data;
char *recv_data;
{
  int i;
  int fd;
  int ret;
  fd = atoi(fd_sock);
  i = 0;
  ret = write(fd, send_data + i, strlen(send_data + i));
  while (ret >= 0 && ret < strlen(send_data + i)) {
    i += ret;
    ret = write(fd, send_data + i, strlen(send_data + i));
  }
  write(fd, "\n", 1);
  i = 0;
  ret = read(fd, recv_data + i, 1);
  while (ret > 0 && *(recv_data + i) != '\n') {
    i++;
    ret = read(fd, recv_data + i, 1);
  }
  recv_data[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<sock_send_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x35(%rbp)
jl     11d9 <sock_send_recv+0x99>
movslq -0x24(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
setb   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11e9 <sock_send_recv+0xa9>
jmp    1230 <sock_send_recv+0xf0>
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
jmp    11a2 <sock_send_recv+0x62>
mov    -0x20(%rbp),%edi
lea    0xdc6(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x4d(%rbp)
jle    128e <sock_send_recv+0x14e>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    129e <sock_send_recv+0x15e>
jmp    12c9 <sock_send_recv+0x189>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
jmp    126a <sock_send_recv+0x12a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_send_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
xor    %eax,%eax
call   1060 <atoi@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <write@plt>
test   %eax,%eax
js     11b9 <sock_send_recv+0x79>
mov    %eax,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r13d
movslq %ebx,%rdi
add    %r12,%rdi
call   1040 <strlen@plt>
cmp    %r13,%rax
jbe    11b9 <sock_send_recv+0x79>
add    %ebp,%ebx
movslq %ebx,%rbp
add    %r12,%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <write@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1180 <sock_send_recv+0x40>
lea    0xe40(%rip),%rsi
xor    %ebx,%ebx
mov    %r15d,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
jle    1216 <sock_send_recv+0xd6>
xor    %ebx,%ebx
nopl   0x0(%rax)
cmpb   $0xa,(%r14,%rbx,1)
je     1216 <sock_send_recv+0xd6>
lea    (%r14,%rbx,1),%rsi
add    $0x1,%rsi
add    $0x1,%rbx
mov    %r15d,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
jg     11f0 <sock_send_recv+0xb0>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @sock_send_recv(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %10)
store i32 %11, i32* %8
store i32 0, i32* %7
%12 = load i32, i32* %8
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = call i64 @strlen(i8* %20)
%22 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %12, i8* %16, i64 %21)
store i32 %22, i32* %9
br label %23
23: ; preds = %37, %3
%24 = load i32, i32* %9
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = call i64 @strlen(i8* %32)
%34 = icmp ult i64 %28, %33
br label %35
35: ; preds = %26, %23
%36 = phi i1 [ false, %23 ], [ %34, %26 ]
br i1 %36, label %37, label %52
37: ; preds = %35
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = add nsw i32 %39, %38
store i32 %40, i32* %7
%41 = load i32, i32* %8
%42 = load i8*, i8** %5
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8*, i8** %5
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i64 @strlen(i8* %49)
%51 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %41, i8* %45, i64 %50)
store i32 %51, i32* %9
br label %23
52: ; preds = %35
%53 = load i32, i32* %8
%54 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 0, i32* %7
%55 = load i32, i32* %8
%56 = load i8*, i8** %6
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %55, i8* %59, i32 1)
store i32 %60, i32* %9
br label %61
61: ; preds = %74, %52
%62 = load i32, i32* %9
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %61
%65 = load i8*, i8** %6
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 10
br label %72
72: ; preds = %64, %61
%73 = phi i1 [ false, %61 ], [ %71, %64 ]
br i1 %73, label %74, label %83
74: ; preds = %72
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
%77 = load i32, i32* %8
%78 = load i8*, i8** %6
%79 = load i32, i32* %7
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %77, i8* %81, i32 1)
store i32 %82, i32* %9
br label %61
83: ; preds = %72
%84 = load i8*, i8** %6
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
store i8 0, i8* %87
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @sock_send_recv(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = tail call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %4, i8* %1, i64 %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %23
8: ; preds = %3, %16
%9 = phi i32 [ %21, %16 ], [ %6, %3 ]
%10 = phi i32 [ %17, %16 ], [ 0, %3 ]
%11 = zext i32 %9 to i64
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = icmp ugt i64 %14, %11
br i1 %15, label %16, label %23
16: ; preds = %8
%17 = add nsw i32 %9, %10
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = tail call i64 @strlen(i8* dereferenceable(1) %19)
%21 = tail call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 %4, i8* %19, i64 %20)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %8, label %23
23: ; preds = %8, %16, %3
%24 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%25 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* %2, i32 1)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %23, %32
%28 = phi i64 [ %33, %32 ], [ 0, %23 ]
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 10
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = add nuw i64 %28, 1
%34 = getelementptr inbounds i8, i8* %2, i64 %33
%35 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* %34, i32 1)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %27, label %37
37: ; preds = %27, %32, %23
%38 = phi i64 [ 0, %23 ], [ %33, %32 ], [ %28, %27 ]
%39 = and i64 %38, 4294967295
%40 = getelementptr inbounds i8, i8* %2, i64 %39
store i8 0, i8* %40
ret i32 0
}