#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int N, char *P[]) {
  int sock;
  struct sockaddr_in sin;
  struct hostent *h;
  char nom[100], addr[100];
  if (N != 3) {
    fprintf(stderr, "Utilisation : %s nom_serveur port\n", P[0]);
    exit(1);
  }
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    perror("socket");
    exit(2);
  }
  if (!(h = gethostbyname(P[1]))) {
    perror("gethostbyname");
    exit(3);
  }
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  bcopy(h->h_addr, &sin.sin_addr, h->h_length);
  sin.sin_port = htons(atoi(P[2]));
  if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    perror("connect");
    exit(4);
  }
  printf("Donner un nom de machine\n");
  fgets(nom, 100, stdin);
  write(sock, nom, strlen(nom));
  read(sock, addr, 100);
  nom[strlen(nom) - 1] = '\0';
  if (strncmp(addr, "erreur !! ", 9) == 0)
    printf("La machine %s n'existe pas !\n", nom);
  else
    printf("La machine %s a pour adresse IP %s\n", nom, addr);
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1259 <main+0x49>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb6(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    129b <main+0x8b>
lea    0xd97(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12cc <main+0xbc>
lea    0xd6d(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bcopy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jge    1348 <main+0x138>
lea    0xcff(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x4,%edi
call   1110 <exit@plt>
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2c7c(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10c(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x10c(%rbp),%edi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x64,%edx
call   1090 <read@plt>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x100(%rbp),%rdi
lea    0xc78(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1410 <main+0x200>
lea    -0x90(%rbp),%rsi
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    142c <main+0x21c>
lea    -0x90(%rbp),%rsi
lea    -0x100(%rbp),%rdx
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf0,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1391 <main+0x171>
mov    0x2da6(%rip),%r12
mov    (%r12),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
test   %eax,%eax
js     13b3 <main+0x193>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     13c9 <main+0x1a9>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%edi
lea    0x4(%rsp),%rsi
call   10e0 <bcopy@plt>
mov    0x10(%r14),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
test   %rax,%rax
js     13df <main+0x1bf>
lea    0xdb8(%rip),%rdi
call   1040 <puts@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    0x80(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   10a0 <read@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xd0a(%rip),%rsi
mov    %r14,%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1365 <main+0x145>
lea    0xd1a(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x80(%rsp),%rdx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1378 <main+0x158>
lea    0xcdf(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xc5c(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xc69(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
lea    0xc5a(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x3,%edi
call   1120 <exit@plt>
lea    0xc52(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x4,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Utilisation : %s nom_serveur port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [26 x i8] c"Donner un nom de machine\0A\00"
@stdin = global i32 0
@.str.5 = [11 x i8] c"erreur !! \00"
@.str.6 = [30 x i8] c"La machine %s n'existe pas !\0A\00"
@.str.7 = [36 x i8] c"La machine %s a pour adresse IP %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent*
%9 = alloca [100 x i8]
%10 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = load i32, i32* @IPPROTO_TCP
%24 = call i32 @socket(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %20
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call %struct.hostent* @gethostbyname(i8* %32)
store %struct.hostent* %33, %struct.hostent** %8
%34 = icmp ne %struct.hostent* %33, null
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 3)
unreachable
38: ; preds = %29
%39 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %40, i32* %41
%42 = load %struct.hostent*, %struct.hostent** %8
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%46 = load %struct.hostent*, %struct.hostent** %8
%47 = getelementptr inbounds %struct.hostent, %struct.hostent* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @bcopy(i32 %44, i32* %45, i32 %48)
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @atoi(i8* %52)
%54 = call i32 @htons(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %54, i32* %55
%56 = load i32, i32* %6
%57 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%58 = call i64 @connect(i32 %56, %struct.sockaddr* %57, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %38
%61 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%62 = call i32 @exit(i32 4)
unreachable
63: ; preds = %38
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%66 = load i32, i32* @stdin
%67 = call i32 @fgets(i8* %65, i32 100, i32 %66)
%68 = load i32, i32* %6
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @write(i32 %68, i8* %69, i32 %71)
%73 = load i32, i32* %6
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%75 = call i32 @read(i32 %73, i8* %74, i32 100)
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = sub nsw i32 %77, 1
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %79
store i8 0, i8* %80
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%82 = call i64 @strncmp(i8* %81, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 9)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %63
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %85)
br label %91
87: ; preds = %63
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %88, i8* %89)
br label %91
91: ; preds = %87, %84
%92 = load i32, i32* %6
%93 = call i32 @close(i32 %92)
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Utilisation : %s nom_serveur port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [8 x i8] c"connect\00"
@stdin = global i32 0
@.str.5 = [11 x i8] c"erreur !! \00"
@.str.6 = [30 x i8] c"La machine %s n'existe pas !\0A\00"
@.str.7 = [36 x i8] c"La machine %s a pour adresse IP %s\0A\00"
@str = [25 x i8] c"Donner un nom de machine\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = load i32, i32* @IPPROTO_TCP
%19 = tail call i32 @socket(i32 %16, i32 %17, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %15
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call %struct.hostent* @gethostbyname(i8* %26)
%28 = icmp eq %struct.hostent* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 3)
unreachable
32: ; preds = %24
%33 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @bcopy(i32 %37, i32* %38, i32 %40)
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = call i32 @htons(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %45, i32* %46
%47 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%48 = call i64 @connect(i32 %19, %struct.sockaddr* %47, i32 12)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %32
%51 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 @exit(i32 4)
unreachable
53: ; preds = %32
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%55 = load i32, i32* @stdin
%56 = call i32 @fgets(i8* %7, i32 100, i32 %55)
%57 = call i32 @strlen(i8* %7)
%58 = call i32 @write(i32 %19, i8* %7, i32 %57)
%59 = call i32 @read(i32 %19, i8* %8, i32 100)
%60 = call i32 @strlen(i8* %7)
%61 = add nsw i32 %60, -1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %62
store i8 0, i8* %63
%64 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 9)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %53
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %7)
br label %70
68: ; preds = %53
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %7, i8* %8)
br label %70
70: ; preds = %68, %66
%71 = call i32 @close(i32 %19)
ret i32 0
}