#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 */
struct sockaddr_un {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int NI_MAXHOST;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getnameinfo(struct sockaddr *, int /*<<< orphan*/, char *, int,
                int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void communication(int ns, struct sockaddr_un from, socklen_t fromlen) {
  int s;
  char buf[512];
  ssize_t nread, nwrite;
  char host[NI_MAXHOST];
  char *message = "I am server : Message a envoyer: ";
  s = getnameinfo((struct sockaddr *)&from, fromlen, host, NI_MAXHOST, NULL, 0,
                  NI_NUMERICHOST);
  if (s == 0)
    printf("Debut avec client '%s'\n", host);
  else
    fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
  for (;;) {
    nwrite = write(ns, message, strlen(message));
    if (nwrite < 0) {
      perror("write");
      close(ns);
      break;
    }
    nread = read(ns, buf, 512);
    if (nread == 0) {
      printf("Fin avec client '%s'\n", host);
      close(ns);
      break;
    } else if (nread < 0) {
      perror("read");
      close(ns);
      break;
    }
    buf[nread] = '\0';
    printf("Message recu '%s'\n", buf);
  }
}


x86 assembly (clang, -O0):
<communication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x238(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x250(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x240(%rbp)
lea    0xe20(%rip),%rax
mov    %rax,-0x248(%rbp)
lea    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%ecx
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
xor    %r8d,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    123b <communication+0xab>
mov    -0x250(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
jmp    1267 <communication+0xd7>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x254(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x254(%rbp),%edi
mov    %rax,%rdx
lea    0xdd8(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    126c <communication+0xdc>
mov    -0xc(%rbp),%eax
mov    %eax,-0x264(%rbp)
mov    -0x248(%rbp),%rax
mov    %rax,-0x260(%rbp)
mov    -0x248(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x264(%rbp),%edi
mov    -0x260(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jge    12d1 <communication+0x141>
lea    0xd8c(%rip),%rdi
call   10b0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
jmp    136d <communication+0x1dd>
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    131a <communication+0x18a>
mov    -0x250(%rbp),%rsi
lea    0xd49(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
jmp    136d <communication+0x1dd>
cmpq   $0x0,-0x228(%rbp)
jge    1341 <communication+0x1b1>
lea    0xd38(%rip),%rdi
call   10b0 <perror@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
jmp    136d <communication+0x1dd>
jmp    1346 <communication+0x1b6>
mov    -0x228(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xd09(%rip),%rdi
call   1050 <printf@plt>
jmp    126c <communication+0xdc>
mov    -0x238(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<communication>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %edi,%r15d
mov    %rsp,%rbx
mov    %esi,-0x38(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r14
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
mov    (%rax),%ecx
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    -0x38(%rbp),%rdi
mov    %edx,%esi
mov    %r14,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %rax
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
mov    %rbx,-0x30(%rbp)
je     121a <communication+0x8a>
mov    0x2de2(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xe2c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
jmp    1229 <communication+0x99>
lea    0xe01(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
lea    0xdd0(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
js     12a4 <communication+0x114>
lea    -0x240(%rbp),%r13
lea    0xe14(%rip),%r12
lea    0xda1(%rip),%rbx
nop
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
test   %rax,%rax
je     12b2 <communication+0x122>
js     12df <communication+0x14f>
movb   $0x0,-0x240(%rbp,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %rax,%rax
jns    1260 <communication+0xd0>
lea    0xda0(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c1 <communication+0x131>
lea    0xd98(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rbx
mov    %r15d,%edi
call   1070 <close@plt>
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd81(%rip),%rdi
call   10b0 <perror@plt>
jmp    12c1 <communication+0x131>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [34 x i8] c"I am server : Message a envoyer: \00"
@NI_NUMERICHOST = global i32 0
@.str.1 = [24 x i8] c"Debut avec client '%s'\0A\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [22 x i8] c"Fin avec client '%s'\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [19 x i8] c"Message recu '%s'\0A\00"
define void @communication(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
store i32 %1, i32* %14
store i32 %0, i32* %5
store i32 %2, i32* %6
%15 = load i32, i32* @NI_MAXHOST
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %13
%19 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%20 = load i32, i32* %6
%21 = load i32, i32* @NI_MAXHOST
%22 = load i32, i32* @NI_NUMERICHOST
%23 = call i32 @getnameinfo(%struct.sockaddr* %19, i32 %20, i8* %18, i32 %21, i32* null, i32 0, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %33
28: ; preds = %3
%29 = load i32, i32* @stderr
%30 = load i32, i32* %7
%31 = call i8* @gai_strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %26
br label %34
34: ; preds = %64, %33
%35 = load i32, i32* %5
%36 = load i8*, i8** %13
%37 = load i8*, i8** %13
%38 = call i32 @strlen(i8* %37)
%39 = call i64 @write(i32 %35, i8* %36, i32 %38)
store i64 %39, i64* %10
%40 = load i64, i64* %10
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %34
%43 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* %5
%45 = call i32 @close(i32 %44)
br label %69
46: ; preds = %34
%47 = load i32, i32* %5
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%49 = call i64 @read(i32 %47, i8* %48, i32 512)
store i64 %49, i64* %9
%50 = load i64, i64* %9
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %46
%53 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%54 = load i32, i32* %5
%55 = call i32 @close(i32 %54)
br label %69
56: ; preds = %46
%57 = load i64, i64* %9
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%61 = load i32, i32* %5
%62 = call i32 @close(i32 %61)
br label %69
63: ; preds = %56
br label %64
64: ; preds = %63
%65 = load i64, i64* %9
%66 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%68 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %67)
br label %34
69: ; preds = %59, %52, %42
%70 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@.str = [34 x i8] c"I am server : Message a envoyer: \00"
@NI_NUMERICHOST = global i32 0
@.str.1 = [24 x i8] c"Debut avec client '%s'\0A\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [22 x i8] c"Fin avec client '%s'\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [19 x i8] c"Message recu '%s'\0A\00"
define void @communication(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_un
%5 = alloca [512 x i8]
%6 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* @NI_MAXHOST
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%13 = load i32, i32* @NI_MAXHOST
%14 = load i32, i32* @NI_NUMERICHOST
%15 = call i32 @getnameinfo(%struct.sockaddr* %12, i32 %2, i8* %11, i32 %13, i32* null, i32 0, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i8* @gai_strerror(i32 %15)
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %17
%24 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%25 = call i64 @write(i32 %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %38, %23
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %44
29: ; preds = %23, %38
%30 = call i64 @read(i32 %0, i8* %7, i32 512)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %11)
br label %44
34: ; preds = %29
%35 = icmp slt i64 %30, 0
br i1 %35, label %36, label %38
36: ; preds = %34
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %44
38: ; preds = %34
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %39
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%41 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%42 = call i64 @write(i32 %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %27, label %29
44: ; preds = %36, %32, %27
%45 = call i32 @close(i32 %0)
ret void
}