#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*/ requestCode;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ handle_get(int);
int /*<<< orphan*/ handle_help(int);
int /*<<< orphan*/ handle_list(int);
int /*<<< orphan*/ handle_put(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ send(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
funcao_do_cliente(int fd) {
  char prompt[100] = "";
  char parameter[100] = "";
  int requestCode = 0;
  int responseCode = 0;
  int tam;
  while (requestCode - 5) {
    recv(fd, prompt, 100, 0);
    printf("%s", prompt);
    scanf("%d", &requestCode);
    send(fd, &requestCode, sizeof(requestCode), 0);
    recv(fd, &responseCode, sizeof(responseCode), 0);
    if (responseCode != 1) {
      fprintf(stderr, "SERVER RETURNED ERROR CODE: [%d].\n\n", responseCode);
    } else {
      fprintf(stdout, "SERVER RETURNED CODE: [%d].\n\n", responseCode);
      switch (requestCode) {
      case 1:
        handle_list(fd);
        break;
      case 2:
        handle_put(fd);
        break;
      case 3:
        handle_get(fd);
        break;
      case 4:
        handle_help(fd);
        break;
      }
    }
  }
  fprintf(stdout, "BYE!\n");
}


x86 assembly (clang, -O0):
<funcao_do_cliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movl   $0x0,-0xe4(%rbp)
movl   $0x0,-0xe8(%rbp)
mov    -0xe4(%rbp),%eax
sub    $0x5,%eax
cmp    $0x0,%eax
je     1314 <funcao_do_cliente+0x174>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <recv@plt>
lea    -0x70(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
lea    0xdf0(%rip),%rdi
lea    -0xe4(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x8(%rbp),%edi
lea    -0xe4(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0xe8(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <recv@plt>
cmpl   $0x1,-0xe8(%rbp)
je     128c <funcao_do_cliente+0xec>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0xe8(%rbp),%edx
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    130f <funcao_do_cliente+0x16f>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    -0xe8(%rbp),%edx
lea    0xd98(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0xe4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0xf8(%rbp)
sub    $0x3,%eax
ja     130a <funcao_do_cliente+0x16a>
mov    -0xf8(%rbp),%rax
lea    0xd2e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
call   10c0 <handle_list@plt>
jmp    130a <funcao_do_cliente+0x16a>
mov    -0x8(%rbp),%edi
call   1070 <handle_put@plt>
jmp    130a <funcao_do_cliente+0x16a>
mov    -0x8(%rbp),%edi
call   10b0 <handle_get@plt>
jmp    130a <funcao_do_cliente+0x16a>
mov    -0x8(%rbp),%edi
call   10a0 <handle_help@plt>
jmp    130f <funcao_do_cliente+0x16f>
jmp    11e5 <funcao_do_cliente+0x45>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<funcao_do_cliente>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%r14
lea    0xe2b(%rip),%r15
lea    0xe27(%rip),%r12
lea    0x8(%rsp),%r13
lea    0xc(%rsp),%rbp
jmp    1224 <funcao_do_cliente+0x94>
nopl   0x0(%rax,%rax,1)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x8(%rsp),%eax
cmp    $0x5,%eax
je     12e6 <funcao_do_cliente+0x156>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <recv@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <scanf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <recv@plt>
mov    0xc(%rsp),%edx
cmp    $0x1,%edx
jne    1200 <funcao_do_cliente+0x70>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
cmp    $0x3,%ecx
ja     121b <funcao_do_cliente+0x8b>
lea    0xd53(%rip),%rdx
movslq (%rdx,%rcx,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %ebx,%edi
call   10b0 <handle_list@plt>
jmp    1217 <funcao_do_cliente+0x87>
mov    %ebx,%edi
call   1060 <handle_put@plt>
jmp    1217 <funcao_do_cliente+0x87>
mov    %ebx,%edi
call   10a0 <handle_get@plt>
jmp    1217 <funcao_do_cliente+0x87>
mov    %ebx,%edi
call   1090 <handle_help@plt>
jmp    1217 <funcao_do_cliente+0x87>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"SERVER RETURNED ERROR CODE: [%d].\0A\0A\00"
@stdout = global i32 0
@.str.3 = [30 x i8] c"SERVER RETURNED CODE: [%d].\0A\0A\00"
@.str.4 = [6 x i8] c"BYE!\0A\00"
define i32 @funcao_do_cliente(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 = bitcast [100 x i8]* %4 to i8*
%10 = bitcast [100 x i8]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
br label %11
11: ; preds = %50, %1
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %51
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, ...) @recv(i32 %16, i8* %17, i32 100, i32 0)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%22 = load i32, i32* %3
%23 = call i32 @send(i32 %22, i32* %6, i32 4, i32 0)
%24 = load i32, i32* %3
%25 = call i32 (i32, ...) @recv(i32 %24, i32* %7, i64 4, i32 0)
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %32
28: ; preds = %15
%29 = load i32, i32* @stderr
%30 = load i32, i32* %7
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %50
32: ; preds = %15
%33 = load i32, i32* @stdout
%34 = load i32, i32* %7
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %6
switch i32 %36, label %49 [
i32 1, label %37
i32 2, label %40
i32 3, label %43
i32 4, label %46
]
37: ; preds = %32
%38 = load i32, i32* %3
%39 = call i32 @handle_list(i32 %38)
br label %49
40: ; preds = %32
%41 = load i32, i32* %3
%42 = call i32 @handle_put(i32 %41)
br label %49
43: ; preds = %32
%44 = load i32, i32* %3
%45 = call i32 @handle_get(i32 %44)
br label %49
46: ; preds = %32
%47 = load i32, i32* %3
%48 = call i32 @handle_help(i32 %47)
br label %49
49: ; preds = %32, %46, %43, %40, %37
br label %50
50: ; preds = %49, %28
br label %11
51: ; preds = %11
%52 = load i32, i32* @stdout
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"SERVER RETURNED ERROR CODE: [%d].\0A\0A\00"
@stdout = global i32 0
@.str.3 = [30 x i8] c"SERVER RETURNED CODE: [%d].\0A\0A\00"
@.str.4 = [6 x i8] c"BYE!\0A\00"
define i32 @funcao_do_cliente(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 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %8
8: ; preds = %1, %33
%9 = call i32 (i32, ...) @recv(i32 %0, i8* %5, i32 100, i32 0)
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = call i32 @send(i32 %0, i32* %3, i32 4, i32 0)
%13 = call i32 (i32, ...) @recv(i32 %0, i32* %4, i64 4, i32 0)
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %31
19: ; preds = %8
%20 = load i32, i32* @stdout
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 1)
%22 = load i32, i32* %3
switch i32 %22, label %33 [
i32 1, label %23
i32 2, label %25
i32 3, label %27
i32 4, label %29
]
23: ; preds = %19
%24 = call i32 @handle_list(i32 %0)
br label %31
25: ; preds = %19
%26 = call i32 @handle_put(i32 %0)
br label %31
27: ; preds = %19
%28 = call i32 @handle_get(i32 %0)
br label %31
29: ; preds = %19
%30 = call i32 @handle_help(i32 %0)
br label %31
31: ; preds = %16, %29, %27, %25, %23
%32 = load i32, i32* %3
br label %33
33: ; preds = %31, %19
%34 = phi i32 [ %32, %31 ], [ %22, %19 ]
%35 = icmp eq i32 %34, 5
br i1 %35, label %36, label %8
36: ; preds = %33
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 undef
}