#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*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int read(int, char *, int);
void *doProcessingDev(void *socket) {
  int n;
  char buffer[16];
  bzero(buffer, 16);
  n = read(*((int *)socket), buffer, 16);
  if (n < 0) {
    perror("ERROR - Couldn't read from socket.\n");
    pthread_exit(NULL);
  }
  printf("You sent: %s", buffer);
  if (n < 0) {
    perror("ERROR - Couldn't write to socket.\n");
    pthread_exit(NULL);
  }
  close(*((int *)socket));
  free(socket);
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<doProcessingDev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c0 <doProcessingDev+0x50>
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <pthread_exit@plt>
lea    -0x30(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jge    11ef <doProcessingDev+0x7f>
lea    0xe50(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <pthread_exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doProcessingDev>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1090 <bzero@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11ca <doProcessingDev+0x5a>
lea    0xe80(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    (%rbx),%edi
call   1050 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2f(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
lea    0xe40(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
jmp    11ac <doProcessingDev+0x3c>

LLVM IR (-O0):
@.str = [36 x i8] c"ERROR - Couldn't read from socket.\0A\00"
@.str.1 = [13 x i8] c"You sent: %s\00"
@.str.2 = [35 x i8] c"ERROR - Couldn't write to socket.\0A\00"
define i8* @doProcessingDev(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [16 x i8]
store i8* %0, i8** %3
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 16)
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
%10 = load i32, i32* %9
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 16)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @pthread_exit(i32* null)
br label %18
18: ; preds = %15, %1
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @pthread_exit(i32* null)
br label %26
26: ; preds = %23, %18
%27 = load i8*, i8** %3
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
%33 = call i32 @pthread_exit(i32* null)
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [36 x i8] c"ERROR - Couldn't read from socket.\0A\00"
@.str.1 = [13 x i8] c"You sent: %s\00"
@.str.2 = [35 x i8] c"ERROR - Couldn't write to socket.\0A\00"
define noalias i8* @doProcessingDev(i8* nocapture %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 16)
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = call i32 @read(i32 %6, i8* %3, i32 16)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @pthread_exit(i32* null)
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%13 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @pthread_exit(i32* null)
br label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* %5
%19 = call i32 @close(i32 %18)
%20 = call i32 @free(i8* %0)
%21 = call i32 @pthread_exit(i32* null)
ret i8* undef
}