#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*/ printf(char *, ...);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int handle_msg(char request[1500], int sockfd) {
  char response[1500];
  int sent_bytes = -1;
  printf("first char is %c\n", request[0]);
  switch (request[0]) {
  case 'q':
    return 1;
  case 'n':
    printf("Server ask for my name...\n");
    break;
  case 'a':
    printf("Server ask for action...\n");
    printf("Received from server: %s\n", request);
    break;
  }
  strcat(response, "\r\n");
  sent_bytes = send(sockfd, response, strlen(response), 0);
  printf("Sent %d bytes\n", sent_bytes);
  return 0;
}


x86 assembly (clang, -O0):
<handle_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x5f4(%rbp)
ff ff ff
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
lea    0xe96(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x5f8(%rbp)
sub    $0x61,%eax
je     11d3 <handle_msg+0x93>
jmp    118c <handle_msg+0x4c>
mov    -0x5f8(%rbp),%eax
sub    $0x6e,%eax
je     11c0 <handle_msg+0x80>
jmp    11a0 <handle_msg+0x60>
mov    -0x5f8(%rbp),%eax
sub    $0x71,%eax
jne    11f3 <handle_msg+0xb3>
jmp    11b4 <handle_msg+0x74>
movl   $0x1,-0x4(%rbp)
jmp    1260 <handle_msg+0x120>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f3 <handle_msg+0xb3>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x5f0(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x604(%rbp)
lea    -0x5f0(%rbp),%rax
mov    %rax,-0x600(%rbp)
lea    -0x5f0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x604(%rbp),%edi
mov    -0x600(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x5f4(%rbp)
mov    -0x5f4(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x610,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x5e0,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
movsbl (%rdi),%esi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl (%rbx),%eax
cmp    $0x61,%eax
je     1192 <handle_msg+0x42>
cmp    $0x71,%eax
je     11ec <handle_msg+0x9c>
cmp    $0x6e,%eax
jne    11af <handle_msg+0x5f>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
jmp    11af <handle_msg+0x5f>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe76(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1070 <strcat@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xe4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f1 <handle_msg+0xa1>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x5e0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"first char is %c\0A\00"
@.str.1 = [27 x i8] c"Server ask for my name...\0A\00"
@.str.2 = [26 x i8] c"Server ask for action...\0A\00"
@.str.3 = [26 x i8] c"Received from server: %s\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [15 x i8] c"Sent %d bytes\0A\00"
define i32 @handle_msg(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1500 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 -1, i32* %7
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %24 [
i32 113, label %17
i32 110, label %18
i32 97, label %20
]
17: ; preds = %2
store i32 1, i32* %3
br label %34
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %2, %20, %18
%25 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* %5
%28 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds [1500 x i8], [1500 x i8]* %6, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @send(i32 %27, i8* %28, i32 %30, i32 0)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %32)
store i32 0, i32* %3
br label %34
34: ; preds = %24, %17
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [18 x i8] c"first char is %c\0A\00"
@.str.3 = [26 x i8] c"Received from server: %s\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [15 x i8] c"Sent %d bytes\0A\00"
@str = [25 x i8] c"Server ask for action...\00"
@str.6 = [26 x i8] c"Server ask for my name...\00"
define i32 @handle_msg(i8* %0, i32 %1) {
%3 = alloca [1500 x i8]
%4 = getelementptr inbounds [1500 x i8], [1500 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = sext i8 %5 to i32
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i8, i8* %0
%9 = sext i8 %8 to i32
switch i32 %9, label %15 [
i32 113, label %20
i32 110, label %10
i32 97, label %12
]
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
br label %15
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %2, %12, %10
%16 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @strlen(i8* %4)
%18 = call i32 @send(i32 %1, i8* %4, i32 %17, i32 0)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %2, %15
%21 = phi i32 [ 0, %15 ], [ 1, %2 ]
ret i32 %21
}