#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 recv_socket(int, char *, int);
int /*<<< orphan*/ send_socket(int, char *, int);
void do_processing(int sockfd) {
  if (sockfd != -1) {
    int read;
    char buffer[256] = {0};
    while (1) {
      if ((read = recv_socket(sockfd, buffer, 255)) >= 0) {
        send_socket(sockfd, buffer, read);
      } else {
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<do_processing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     11a1 <do_processing+0x71>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1040 <recv_socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     1192 <do_processing+0x62>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <send_socket@plt>
jmp    1197 <do_processing+0x67>
jmp    119c <do_processing+0x6c>
jmp    115b <do_processing+0x2b>
jmp    11a1 <do_processing+0x71>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_processing>:
cmp    $0xffffffff,%edi
je     11e9 <do_processing+0xc9>
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
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,%rsi
mov    $0xff,%edx
call   1030 <recv_socket@plt>
test   %eax,%eax
js     11df <do_processing+0xbf>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <send_socket@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xff,%edx
call   1030 <recv_socket@plt>
test   %eax,%eax
jns    11c0 <do_processing+0xa0>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @do_processing(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, -1
br i1 %6, label %7, label %22
7: ; preds = %1
%8 = bitcast [256 x i8]* %4 to i8*
br label %9
9: ; preds = %7, %20
%10 = load i32, i32* %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = call i32 @recv_socket(i32 %10, i8* %11, i32 255)
store i32 %12, i32* %3
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 @send_socket(i32 %15, i8* %16, i32 %17)
br label %20
19: ; preds = %9
br label %21
20: ; preds = %14
br label %9
21: ; preds = %19
br label %22
22: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
define void @do_processing(i32 %0) {
%2 = alloca [256 x i8]
%3 = icmp eq i32 %0, -1
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = call i32 @recv_socket(i32 %0, i8* %5, i32 255)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %4, %8
%9 = phi i32 [ %11, %8 ], [ %6, %4 ]
%10 = call i32 @send_socket(i32 %0, i8* %5, i32 %9)
%11 = call i32 @recv_socket(i32 %0, i8* %5, i32 255)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %8, label %13
13: ; preds = %8, %4
br label %14
14: ; preds = %13, %1
ret void
}