#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*/ envia_mensaje(int, char *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *lee_mensaje(int, int, int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ procesa(char *, int);
int /*<<< orphan*/ stderr;
void atiende_cliente(int s_cliente) {
  char *datos = NULL;
  int longitud = 0;
  printf("Atendiendo peticiones...\n");
  do {
    datos = lee_mensaje(s_cliente, 20, &longitud);
    if (NULL != datos) {
      procesa(datos, longitud);
      if (!envia_mensaje(s_cliente, datos, longitud, 20))
        fprintf(stderr, "Fallo al enviar la respuesta\n");
      else
        printf("Peticion atendida\n");
      free(datos);
    }
  } while (NULL != datos);
}


x86 assembly (clang, -O0):
<atiende_cliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x14,%esi
lea    -0x14(%rbp),%rdx
call   1040 <lee_mensaje@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     11ff <atiende_cliente+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <procesa@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x14,%ecx
call   1080 <envia_mensaje@plt>
cmp    $0x0,%eax
jne    11ea <atiende_cliente+0x8a>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f6 <atiende_cliente+0x96>
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1204 <atiende_cliente+0xa4>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1186 <atiende_cliente+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atiende_cliente>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
lea    0xea2(%rip),%rdi
call   1050 <puts@plt>
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x14,%esi
call   1040 <lee_mensaje@plt>
test   %rax,%rax
je     1218 <atiende_cliente+0xb8>
mov    %rax,%rbx
mov    0x2e3b(%rip),%r13
lea    0xe54(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe7f(%rip),%r12
jmp    11e7 <atiende_cliente+0x87>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
mov    $0x14,%esi
mov    %r15,%rdx
call   1040 <lee_mensaje@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1218 <atiende_cliente+0xb8>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1060 <procesa@plt>
mov    0x4(%rsp),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%ecx
call   1080 <envia_mensaje@plt>
test   %eax,%eax
jne    11c0 <atiende_cliente+0x60>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1070 <fprintf@plt>
jmp    11c8 <atiende_cliente+0x68>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Atendiendo peticiones...\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Fallo al enviar la respuesta\0A\00"
@.str.2 = [19 x i8] c"Peticion atendida\0A\00"
define void @atiende_cliente(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %3
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %29, %1
%7 = load i32, i32* %2
%8 = call i8* @lee_mensaje(i32 %7, i32 20, i32* %4)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* null, %9
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = call i32 @procesa(i8* %12, i32 %13)
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = call i32 @envia_mensaje(i32 %15, i8* %16, i32 %17, i32 20)
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %11
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %6
br label %29
29: ; preds = %28
%30 = load i8*, i8** %3
%31 = icmp ne i8* null, %30
br i1 %31, label %6, label %32
32: ; preds = %29
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [30 x i8] c"Fallo al enviar la respuesta\0A\00"
@str = [25 x i8] c"Atendiendo peticiones...\00"
@str.3 = [18 x i8] c"Peticion atendida\00"
define void @atiende_cliente(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%5 = call i8* @lee_mensaje(i32 %0, i32 20, i32* %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %23, label %7
7: ; preds = %1, %19
%8 = phi i8* [ %21, %19 ], [ %5, %1 ]
%9 = load i32, i32* %2
%10 = call i32 @procesa(i8* %8, i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @envia_mensaje(i32 %0, i8* %8, i32 %11, i32 20)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %19
17: ; preds = %7
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = call i32 @free(i8* %8)
%21 = call i8* @lee_mensaje(i32 %0, i32 20, i32* %2)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %7
23: ; preds = %19, %1
ret void
}