#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*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in server;
  struct hostent *hp;
  char buff[1024];
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
    perror("falha na criacao do socket.");
    exit(1);
  }
  server.sin_family = AF_INET;
  if ((hp = gethostbyname(argv[1])) == 0) {
    perror("Funcao gethosbyname() falhou.");
    exit(1);
  }
  memcpy(&server.sin_addr, hp->h_addr, hp->h_length);
  server.sin_port = htons(5000);
  if ((connect(sock, (struct sockaddr *)&server, sizeof(server))) < 0) {
    perror("Conexao Falhou.");
    exit(1);
  }
  if ((send(sock, "Olá mundo de Wonderland!",
            sizeof("Olá mundo de Wonderland!"), 0)) < 0) {
    perror("Envio de mensagem pelo socket falhou.");
    exit(1);
  }
  fprintf(stdout, "MSG enviada: %s\n", "Olá mundo de Wonderland!");
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    11f4 <main+0x54>
lea    0xe1b(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1231 <main+0x91>
lea    0xdfa(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1289 <main+0xe9>
lea    0xdc0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    0xdb7(%rip),%rsi
mov    $0x1a,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    12bf <main+0x11f>
lea    0xdb4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
lea    0xd74(%rip),%rdx
call   1070 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    0x2e35(%rip),%r15
mov    (%r15),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
je     1262 <main+0xc2>
mov    %eax,%ebx
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     126b <main+0xcb>
lea    0x4(%rsp),%rdi
mov    (%rax),%edx
mov    0x4(%rax),%esi
call   1080 <memcpy@plt>
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     1274 <main+0xd4>
lea    0xe2a(%rip),%rsi
mov    %ebx,%edi
mov    $0x1a,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     127d <main+0xdd>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
lea    0xe00(%rip),%rdx
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd97(%rip),%rdi
jmp    1284 <main+0xe4>
lea    0xdaa(%rip),%rdi
jmp    1284 <main+0xe4>
lea    0xdbf(%rip),%rdi
jmp    1284 <main+0xe4>
lea    0xde0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [28 x i8] c"falha na criacao do socket.\00"
@.str.1 = [30 x i8] c"Funcao gethosbyname() falhou.\00"
@.str.2 = [16 x i8] c"Conexao Falhou.\00"
@.str.3 = [26 x i8] c"Ol\C3\A1 mundo de Wonderland!\00"
@.str.4 = [38 x i8] c"Envio de mensagem pelo socket falhou.\00"
@stdout = global i32 0
@.str.5 = [17 x i8] c"MSG enviada: %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 [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %8
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %17
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%30 = load %struct.hostent*, %struct.hostent** %8
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load %struct.hostent*, %struct.hostent** %8
%34 = getelementptr inbounds %struct.hostent, %struct.hostent* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @memcpy(i32* %29, i32 %32, i32 %35)
%37 = call i32 @htons(i32 5000)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%41 = call i64 @connect(i32 %39, %struct.sockaddr* %40, i32 12)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %28
%44 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %28
%47 = load i32, i32* %6
%48 = call i64 @send(i32 %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 26, i32 0)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
%54 = load i32, i32* @stdout
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [28 x i8] c"falha na criacao do socket.\00"
@.str.1 = [30 x i8] c"Funcao gethosbyname() falhou.\00"
@.str.2 = [16 x i8] c"Conexao Falhou.\00"
@.str.3 = [26 x i8] c"Ol\C3\A1 mundo de Wonderland!\00"
@.str.4 = [38 x i8] c"Envio de mensagem pelo socket falhou.\00"
@stdout = global i32 0
@.str.5 = [17 x i8] c"MSG enviada: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call %struct.hostent* @gethostbyname(i8* %16)
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %12
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @memcpy(i32* %23, i32 %25, i32 %27)
%29 = call i32 @htons(i32 5000)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %29, i32* %30
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i64 @connect(i32 %7, %struct.sockaddr* %31, i32 12)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %22
%38 = call i64 @send(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 26, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %37
%44 = load i32, i32* @stdout
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @close(i32 %7)
ret i32 0
}