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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in server_addr;
  char buf[] = "Mensagem de teste na travessia da pilha TCP/IP\n";
  int bytes;
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr("192.168.28.96");
  server_addr.sin_port = htons(6000);
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket()");
    exit(0);
  }
  if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("connect()");
    exit(0);
  }
  bytes = write(sockfd, buf, strlen(buf));
  printf("Bytes escritos %d\n", bytes);
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0x30,%edx
call   1090 <memcpy@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe24(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1259 <main+0x99>
lea    0xdf1(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    1287 <main+0xc7>
lea    0xdcc(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    0xd98(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe46(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe2a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2df9(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe34(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    1231 <main+0x81>
lea    0xe0f(%rip),%rdi
jmp    124e <main+0x9e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
jns    125a <main+0xaa>
lea    0xdf9(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xdd7(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [48 x i8] c"Mensagem de teste na travessia da pilha TCP/IP\0A\00"
@AF_INET = global i32 0
@.str = [14 x i8] c"192.168.28.96\00"
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [10 x i8] c"connect()\00"
@.str.3 = [19 x i8] c"Bytes escritos %d\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 [48 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [48 x i8]* %8 to i8*
%11 = bitcast %struct.sockaddr_in* %7 to i8*
%12 = call i32 @bzero(i8* %11, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 @htons(i32 6000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = load i32, i32* %6
%29 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%30 = call i64 @connect(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %27
%36 = load i32, i32* %6
%37 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%38 = getelementptr inbounds [48 x i8], [48 x i8]* %8, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @write(i32 %36, i8* %37, i32 %39)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [48 x i8] c"Mensagem de teste na travessia da pilha TCP/IP\0A\00"
@AF_INET = global i32 0
@.str = [14 x i8] c"192.168.28.96\00"
@SOCK_STREAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [10 x i8] c"connect()\00"
@.str.3 = [19 x i8] c"Bytes escritos %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [48 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [48 x i8], [48 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %5, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 6000)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i64 @connect(i32 %16, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %21
%29 = call i32 @strlen(i8* %6)
%30 = call i32 @write(i32 %16, i8* %6, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i32 @close(i32 %16)
%33 = call i32 @exit(i32 0)
unreachable
}