#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd, n;
  char sendline[100];
  char recvline[100];
  int taille;
  struct sockaddr_in servaddr;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof servaddr);
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(22000);
  inet_pton(AF_INET, "127.0.0.1", &(servaddr.sin_addr));
  connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  do {
    taille = read(0, sendline, 100);
    sendline[taille] = 0;
    write(sockfd, sendline, taille + 1);
    taille = read(sockfd, recvline, 100);
    recvline[taille] = 0;
    printf("Nous avons reçu %s", recvline);
  } while (recvline[0] != '.');
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x100(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf8(%rbp)
mov    $0x55f0,%edi
call   1040 <htons@plt>
mov    %eax,-0xfc(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    -0x100(%rbp),%rdx
lea    0xe04(%rip),%rsi
call   1070 <inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
lea    -0x80(%rbp),%rsi
xor    %edi,%edi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0xf4(%rbp)
movslq -0xf4(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0xf4(%rbp),%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0xf4(%rbp)
movslq -0xf4(%rbp),%rax
movb   $0x0,-0xf0(%rbp,%rax,1)
lea    -0xf0(%rbp),%rsi
lea    0xd87(%rip),%rdi
call   1050 <printf@plt>
movsbl -0xf0(%rbp),%eax
cmp    $0x2e,%eax
jne    1215 <main+0x95>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    0x2e53(%rip),%r15
mov    (%r15),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0x55f0,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r15),%edi
lea    0xe27(%rip),%rsi
mov    %r14,%rdx
call   1070 <inet_pton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
lea    0x80(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe06(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
movslq %eax,%rdx
movb   $0x0,0x80(%rsp,%rdx,1)
add    $0x1,%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
cmpb   $0x2e,0x10(%rsp)
jne    1210 <main+0x90>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [20 x i8] c"Nous avons re\C3\A7u %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 22000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%22 = call i32 @inet_pton(i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %21)
%23 = load i32, i32* %6
%24 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%25 = call i32 @connect(i32 %23, %struct.sockaddr* %24, i32 12)
br label %26
26: ; preds = %45, %2
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%28 = call i32 @read(i32 0, i8* %27, i32 100)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %6
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
%36 = call i32 @write(i32 %32, i8* %33, i32 %35)
%37 = load i32, i32* %6
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 100)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %26
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 46
br i1 %49, label %26, label %50
50: ; preds = %45
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [20 x i8] c"Nous avons re\C3\A7u %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 22000)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%19 = call i32 @inet_pton(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%21 = call i32 @connect(i32 %11, %struct.sockaddr* %20, i32 12)
br label %22
22: ; preds = %22, %2
%23 = call i32 @read(i32 0, i8* %6, i32 100)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = add nsw i32 %23, 1
%27 = call i32 @write(i32 %11, i8* %6, i32 %26)
%28 = call i32 @read(i32 %11, i8* %7, i32 100)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%32 = load i8, i8* %7
%33 = icmp eq i8 %32, 46
br i1 %33, label %34, label %22
34: ; preds = %22
ret i32 0
}