#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 */
unsigned char lee_mensaje(int, int, int *);
int /*<<< orphan*/ printf(char *);
int atiende_cliente(int s_cliente) {
  unsigned char leido1 = 0;
  unsigned char leido2 = 0;
  int checksum = 0;
  int finA = 0;
  int finB = 0;
  printf("Atendiendo peticiones...\n");
  leido1 = lee_mensaje(s_cliente, 10, &finA);
  leido2 = lee_mensaje(s_cliente, 10, &finB);
  while ((0 != finA) || (0 != finB)) {
    checksum += (leido1 << 8) + leido2;
    leido1 = lee_mensaje(s_cliente, 10, &finA);
    leido2 = lee_mensaje(s_cliente, 10, &finB);
    if ((checksum & 0xf0000) != 0) {
      checksum = checksum & 0x0000ffff;
      checksum++;
    }
  }
  checksum = (~checksum);
  checksum = checksum & 0x0000ffff;
  return checksum;
}


x86 assembly (clang, -O0):
<atiende_cliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movb   $0x0,-0x6(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
lea    -0x10(%rbp),%rdx
call   1030 <lee_mensaje@plt>
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
lea    -0x14(%rbp),%rdx
call   1030 <lee_mensaje@plt>
mov    %al,-0x6(%rbp)
mov    $0x1,%al
xor    %ecx,%ecx
cmp    -0x10(%rbp),%ecx
mov    %al,-0x15(%rbp)
jne    1197 <atiende_cliente+0x77>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11a7 <atiende_cliente+0x87>
jmp    120c <atiende_cliente+0xec>
movzbl -0x5(%rbp),%eax
shl    $0x8,%eax
movzbl -0x6(%rbp),%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
lea    -0x10(%rbp),%rdx
call   1030 <lee_mensaje@plt>
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
lea    -0x14(%rbp),%rdx
call   1030 <lee_mensaje@plt>
mov    %al,-0x6(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf0000,%eax
cmp    $0x0,%eax
je     1207 <atiende_cliente+0xe7>
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117c <atiende_cliente+0x5c>
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atiende_cliente>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r12d
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
mov    $0xa,%esi
call   1030 <lee_mensaje@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
mov    $0xa,%esi
call   1030 <lee_mensaje@plt>
mov    0xc(%rsp),%edx
mov    $0xffff,%ecx
or     0x8(%rsp),%edx
je     11dd <atiende_cliente+0xbd>
xor    %ecx,%ecx
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
movzbl %bl,%edx
shl    $0x8,%edx
movzbl %al,%ebp
or     %edx,%ebp
add    %ecx,%ebp
mov    %r12d,%edi
mov    $0xa,%esi
mov    %r14,%rdx
call   1030 <lee_mensaje@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    $0xa,%esi
mov    %r15,%rdx
call   1030 <lee_mensaje@plt>
movzwl %bp,%ecx
add    $0x1,%ecx
test   $0xf0000,%ebp
cmove  %ebp,%ecx
mov    0xc(%rsp),%edx
or     0x8(%rsp),%edx
jne    1190 <atiende_cliente+0x70>
not    %ecx
movzwl %cx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Atendiendo peticiones...\0A\00"
define i32 @atiende_cliente(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i8 0, i8* %3
store i8 0, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %2
%10 = call zeroext i8 @lee_mensaje(i32 %9, i32 10, i32* %6)
store i8 %10, i8* %3
%11 = load i32, i32* %2
%12 = call zeroext i8 @lee_mensaje(i32 %11, i32 10, i32* %7)
store i8 %12, i8* %4
br label %13
13: ; preds = %42, %1
%14 = load i32, i32* %6
%15 = icmp ne i32 0, %14
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp ne i32 0, %17
br label %19
19: ; preds = %16, %13
%20 = phi i1 [ true, %13 ], [ %18, %16 ]
br i1 %20, label %21, label %43
21: ; preds = %19
%22 = load i8, i8* %3
%23 = zext i8 %22 to i32
%24 = shl i32 %23, 8
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = add nsw i32 %24, %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, %27
store i32 %29, i32* %5
%30 = load i32, i32* %2
%31 = call zeroext i8 @lee_mensaje(i32 %30, i32 10, i32* %6)
store i8 %31, i8* %3
%32 = load i32, i32* %2
%33 = call zeroext i8 @lee_mensaje(i32 %32, i32 10, i32* %7)
store i8 %33, i8* %4
%34 = load i32, i32* %5
%35 = and i32 %34, 983040
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %21
%38 = load i32, i32* %5
%39 = and i32 %38, 65535
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %37, %21
br label %13
43: ; preds = %19
%44 = load i32, i32* %5
%45 = xor i32 %44, -1
store i32 %45, i32* %5
%46 = load i32, i32* %5
%47 = and i32 %46, 65535
store i32 %47, i32* %5
%48 = load i32, i32* %5
ret i32 %48
}

LLVM IR (-O2):
@str = [25 x i8] c"Atendiendo peticiones...\00"
define i32 @atiende_cliente(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%7 = call zeroext i8 @lee_mensaje(i32 %0, i32 10, i32* %2)
%8 = call zeroext i8 @lee_mensaje(i32 %0, i32 10, i32* %3)
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %38
14: ; preds = %1, %14
%15 = phi i32 [ %29, %14 ], [ 0, %1 ]
%16 = phi i8 [ %24, %14 ], [ %8, %1 ]
%17 = phi i8 [ %23, %14 ], [ %7, %1 ]
%18 = zext i8 %17 to i32
%19 = shl nuw nsw i32 %18, 8
%20 = zext i8 %16 to i32
%21 = or i32 %19, %20
%22 = add nsw i32 %21, %15
%23 = call zeroext i8 @lee_mensaje(i32 %0, i32 10, i32* %2)
%24 = call zeroext i8 @lee_mensaje(i32 %0, i32 10, i32* %3)
%25 = and i32 %22, 983040
%26 = icmp eq i32 %25, 0
%27 = and i32 %22, 65535
%28 = add nuw nsw i32 %27, 1
%29 = select i1 %26, i32 %22, i32 %28
%30 = load i32, i32* %2
%31 = icmp ne i32 %30, 0
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %14, label %35
35: ; preds = %14
%36 = and i32 %29, 65535
%37 = xor i32 %36, 65535
br label %38
38: ; preds = %35, %1
%39 = phi i32 [ 65535, %1 ], [ %37, %35 ]
ret i32 %39
}