#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ 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*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(void *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  struct sockaddr_in servaddr;
  int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock == -1)
    perror("Socket");
  bzero((void *)&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(6782);
  servaddr.sin_addr.s_addr = inet_addr("localhost");
  if (-1 == connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)))
    perror("Connect");
  while (1) {
    char message[6];
    fgets(message, 6, stdin);
    message[5] = '\0';
    send(sock, message, 6, 0);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11cf <main+0x4f>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1a7e,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe0a(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1231 <main+0xb1>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
jmp    1236 <main+0xb6>
lea    -0x2a(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1050 <fgets@plt>
movb   $0x0,-0x25(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x2a(%rbp),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    1236 <main+0xb6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e57(%rip),%r14
mov    (%r14),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1239 <main+0xb9>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x1a7e,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe24(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     124a <main+0xca>
mov    0x2dd9(%rip),%rbp
lea    0x12(%rsp),%rbx
nopl   0x0(%rax)
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1050 <fgets@plt>
movb   $0x0,0x17(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    1210 <main+0x90>
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
jmp    11b7 <main+0x37>
lea    0xdc0(%rip),%rdi
call   1070 <perror@plt>
jmp    1200 <main+0x80>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"Socket\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [8 x i8] c"Connect\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = bitcast %struct.sockaddr_in* %6 to i8*
%19 = call i32 @bzero(i8* %18, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 6782)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %7
%28 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%29 = call i32 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp eq i32 -1, %29
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %17
br label %34
34: ; preds = %33, %34
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 6, i32 %36)
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 5
store i8 0, i8* %38
%39 = load i32, i32* %7
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%41 = call i32 @send(i32 %39, i8* %40, i32 6, i32 0)
br label %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"Socket\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [8 x i8] c"Connect\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [6 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = load i32, i32* @IPPROTO_TCP
%9 = tail call i32 @socket(i32 %6, i32 %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = call i32 @bzero(i8* %5, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 6782)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @connect(i32 %9, %struct.sockaddr* %21, i32 12)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %13
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
br label %29
29: ; preds = %29, %26
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %27, i32 6, i32 %30)
store i8 0, i8* %28
%32 = call i32 @send(i32 %9, i8* %27, i32 6, i32 0)
br label %29
}