#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_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  char *h_name;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyaddr(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int communication(struct sockaddr_in from, int sockfd) {
  int r;
  struct hostent *hp;
  char buf[512];
  char *message = "Envoyez votre message : ";
  hp = gethostbyaddr(&from.sin_addr, sizeof(struct in_addr), from.sin_family);
  if (hp == NULL) {
    fprintf(stderr, "Erreurs gethostbyaddr\n");
    shutdown(sockfd, 2);
    return -1;
  } else
    printf("Machine appellante: %s\n", hp->h_name);
  for (;;) {
    r = write(sockfd, message, strlen(message));
    r = read(sockfd, buf, 512);
    if (r <= 0) {
      printf("fin client\n");
      break;
    }
    buf[r] = '\0';
    printf("%s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<communication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x228(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%edx
mov    $0x4,%esi
call   1090 <gethostbyaddr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <communication+0x72>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <communication+0x127>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11fc <communication+0x8c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x234(%rbp)
mov    -0x228(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x228(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x234(%rbp),%edi
mov    -0x230(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     126a <communication+0xfa>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1290 <communication+0x120>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rsi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11fc <communication+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<communication>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    %esi,%ebx
mov    %rdi,%rdx
mov    %rdi,0x8(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   10a0 <gethostbyaddr@plt>
test   %rax,%rax
je     1244 <communication+0xc4>
mov    (%rax),%rsi
lea    0xe77(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe36(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1236 <communication+0xb6>
lea    0x10(%rsp),%r15
lea    0xe01(%rip),%rbp
nop
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   1080 <read@plt>
test   %eax,%eax
jg     1200 <communication+0x80>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
jmp    126b <communication+0xeb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1090 <fprintf@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i8* }
@.str = [25 x i8] c"Envoyez votre message : \00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Erreurs gethostbyaddr\0A\00"
@.str.2 = [24 x i8] c"Machine appellante: %s\0A\00"
@.str.3 = [12 x i8] c"fin client\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @communication(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca [512 x i8]
%9 = alloca i8*
%10 = bitcast %struct.sockaddr_in* %4 to i64*
store i64 %0, i64* %10
store i32 %1, i32* %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %9
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call %struct.hostent* @gethostbyaddr(i32* %11, i32 4, i32 %13)
store %struct.hostent* %14, %struct.hostent** %7
%15 = load %struct.hostent*, %struct.hostent** %7
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %5
%21 = call i32 @shutdown(i32 %20, i32 2)
store i32 -1, i32* %3
br label %48
22: ; preds = %2
%23 = load %struct.hostent*, %struct.hostent** %7
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22
br label %28
28: ; preds = %41, %27
%29 = load i32, i32* %5
%30 = load i8*, i8** %9
%31 = load i8*, i8** %9
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @write(i32 %29, i8* %30, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %5
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 512)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %28
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %47
41: ; preds = %28
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %43
store i8 0, i8* %44
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %45)
br label %28
47: ; preds = %39
store i32 0, i32* %3
br label %48
48: ; preds = %47, %17
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i8* }
@.str = [25 x i8] c"Envoyez votre message : \00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Erreurs gethostbyaddr\0A\00"
@.str.2 = [24 x i8] c"Machine appellante: %s\0A\00"
@str = [11 x i8] c"fin client\00"
define i32 @communication(i64 %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.sockaddr_in*
%5 = alloca [512 x i8]
store i64 %0, i64* %3
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%8 = trunc i64 %0 to i32
%9 = call %struct.hostent* @gethostbyaddr(i32* %7, i32 4, i32 %8)
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @shutdown(i32 %1, i32 2)
br label %34
15: ; preds = %2
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @write(i32 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @read(i32 %1, i8* %6, i32 512)
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %25, %15
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %34
25: ; preds = %15, %25
%26 = phi i32 [ %32, %25 ], [ %21, %15 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @puts(i8* %6)
%30 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @write(i32 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = call i32 @read(i32 %1, i8* %6, i32 512)
%33 = icmp slt i32 %32, 1
br i1 %33, label %23, label %25
34: ; preds = %23, %11
%35 = phi i32 [ -1, %11 ], [ 0, %23 ]
ret i32 %35
}