#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 int /*<<< orphan*/ responseCode;
typedef int /*<<< orphan*/ option;

/* Variables and functions */
int /*<<< orphan*/ handle_get(int);
int /*<<< orphan*/ handle_help(int);
int /*<<< orphan*/ handle_list(int);
int /*<<< orphan*/ handle_put(int);
int /*<<< orphan*/ handle_quit(int);
int /*<<< orphan*/ recv(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int);
funcao_do_servidor(int fd) {
  char prompt[100];
  sprintf(prompt,
          "Hello! Server says:\n%d-LIST\n%d-PUT\n%d-GET\n%d-HELP\n%d-QUIT\n\n",
          1, 2, 3, 4, 5);
  char parameter[100];
  int option = 0;
  int tam = 0;
  int responseCode = 2;
  while (option - 5) {
    send(fd, prompt, 100, 0);
    recv(fd, &option, sizeof(option), 0);
    switch (option) {
    case 1:
      handle_list(fd);
    case 2:
      handle_put(fd);
    case 3:
      handle_get(fd);
    case 4:
      send(fd, &responseCode, sizeof(responseCode), 0);
      handle_help(fd);
      break;
    default:
      handle_quit(fd);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<funcao_do_servidor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
movl   $0x5,(%rsp)
call   1070 <sprintf@plt>
movl   $0x0,-0xe4(%rbp)
movl   $0x0,-0xe8(%rbp)
movl   $0x2,-0xec(%rbp)
mov    -0xe4(%rbp),%eax
sub    $0x5,%eax
cmp    $0x0,%eax
je     129c <funcao_do_servidor+0x11c>
mov    -0x8(%rbp),%edi
xor    %ecx,%ecx
mov    %ecx,-0xfc(%rbp)
mov    %cl,%al
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1040 <send@plt>
mov    -0xfc(%rbp),%ecx
mov    -0x8(%rbp),%edi
lea    -0xe4(%rbp),%rsi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    -0xe4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xf8(%rbp)
sub    $0x3,%eax
ja     128f <funcao_do_servidor+0x10f>
mov    -0xf8(%rbp),%rax
lea    0xdb7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
call   10a0 <handle_list@plt>
mov    -0x8(%rbp),%edi
call   1050 <handle_put@plt>
mov    -0x8(%rbp),%edi
call   1090 <handle_get@plt>
mov    -0x8(%rbp),%edi
lea    -0xec(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <send@plt>
mov    -0x8(%rbp),%edi
call   1060 <handle_help@plt>
jmp    1297 <funcao_do_servidor+0x117>
mov    -0x8(%rbp),%edi
call   1080 <handle_quit@plt>
jmp    11d9 <funcao_do_servidor+0x59>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<funcao_do_servidor>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ebx
movl   $0x5,(%rsp)
lea    0xe70(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%edx
mov    $0x2,%ecx
mov    $0x3,%r8d
mov    $0x4,%r9d
call   1070 <sprintf@plt>
movl   $0x0,0x8(%rsp)
movl   $0x2,0xc(%rsp)
lea    0x8(%rsp),%r15
lea    0xe21(%rip),%r13
lea    0xc(%rsp),%r12
jmp    1200 <funcao_do_servidor+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <handle_quit@plt>
cmpl   $0x5,0x8(%rsp)
je     1270 <funcao_do_servidor+0xf0>
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <send@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x8(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     11f0 <funcao_do_servidor+0x70>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %ebx,%edi
call   10a0 <handle_list@plt>
mov    %ebx,%edi
call   1050 <handle_put@plt>
mov    %ebx,%edi
call   1090 <handle_get@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <send@plt>
mov    %ebx,%edi
call   1060 <handle_help@plt>
cmpl   $0x5,0x8(%rsp)
jne    1200 <funcao_do_servidor+0x80>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [60 x i8] c"Hello! Server says:\0A%d-LIST\0A%d-PUT\0A%d-GET\0A%d-HELP\0A%d-QUIT\0A\0A\00"
define i32 @funcao_do_servidor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3, i32 4, i32 5)
store i32 0, i32* %6
store i32 0, i32* %7
store i32 2, i32* %8
br label %11
11: ; preds = %39, %1
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = load i32, i32* %3
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = call i32 (i32, ...) @send(i32 %16, i8* %17, i32 100, i32 0)
%19 = load i32, i32* %3
%20 = call i32 @recv(i32 %19, i32* %6, i32 4, i32 0)
%21 = load i32, i32* %6
switch i32 %21, label %36 [
i32 1, label %22
i32 2, label %25
i32 3, label %28
i32 4, label %31
]
22: ; preds = %15
%23 = load i32, i32* %3
%24 = call i32 @handle_list(i32 %23)
br label %25
25: ; preds = %15, %22
%26 = load i32, i32* %3
%27 = call i32 @handle_put(i32 %26)
br label %28
28: ; preds = %15, %25
%29 = load i32, i32* %3
%30 = call i32 @handle_get(i32 %29)
br label %31
31: ; preds = %15, %28
%32 = load i32, i32* %3
%33 = call i32 (i32, ...) @send(i32 %32, i32* %8, i64 4, i32 0)
%34 = load i32, i32* %3
%35 = call i32 @handle_help(i32 %34)
br label %39
36: ; preds = %15
%37 = load i32, i32* %3
%38 = call i32 @handle_quit(i32 %37)
br label %39
39: ; preds = %36, %31
br label %11
40: ; preds = %11
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [60 x i8] c"Hello! Server says:\0A%d-LIST\0A%d-PUT\0A%d-GET\0A%d-HELP\0A%d-QUIT\0A\0A\00"
define i32 @funcao_do_servidor(i32 %0) {
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3, i32 4, i32 5)
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 2, i32* %4
br label %9
9: ; preds = %1, %24
%10 = call i32 (i32, ...) @send(i32 %0, i8* %5, i32 100, i32 0)
%11 = call i32 @recv(i32 %0, i32* %3, i32 4, i32 0)
%12 = load i32, i32* %3
switch i32 %12, label %22 [
i32 1, label %13
i32 2, label %15
i32 3, label %17
i32 4, label %19
]
13: ; preds = %9
%14 = call i32 @handle_list(i32 %0)
br label %15
15: ; preds = %9, %13
%16 = call i32 @handle_put(i32 %0)
br label %17
17: ; preds = %9, %15
%18 = call i32 @handle_get(i32 %0)
br label %19
19: ; preds = %9, %17
%20 = call i32 (i32, ...) @send(i32 %0, i32* %4, i64 4, i32 0)
%21 = call i32 @handle_help(i32 %0)
br label %24
22: ; preds = %9
%23 = call i32 @handle_quit(i32 %0)
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %9
27: ; preds = %24
ret i32 undef
}