#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 hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr_in *, int *);
int /*<<< orphan*/ scanf(char *, char **);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr_in *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sock, length, n;
  struct sockaddr_in server, from;
  struct hostent *hp;
  char nick[50], msg[50];
  if (argc != 3) {
    printf("\n\t\"CLIENT error\" - Uso correto: servidor porta\n\n");
    exit(1);
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    error("\n\tCLIENT - error: socket\n\t");
  server.sin_family = AF_INET;
  hp = gethostbyname(argv[1]);
  if (hp == 0)
    error("\n\tCLIENT - error: host desconhecido");
  bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length);
  server.sin_port = htons(atoi(argv[2]));
  length = sizeof(struct sockaddr_in);
  while (1) {
    printf("\nCLIENT: Digite a menssagem - 0 pra sair: ");
    scanf("%s", &msg);
    n = sendto(sock, msg, strlen(msg), 0, &server, length);
    if (n < 0)
      error("\n\tCLIENT - error: Send to - erro ao enviar");
    printf("\nEsperando mensagem do Server...\n");
    n = recvfrom(sock, msg, 256, 0, &from, &length);
    if (n < 0)
      error("\nCLIENT - error: received from - erro ao receber");
    write(1, "Server Diz:  ", 12);
    write(1, msg, n);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1209 <main+0x39>
lea    0xe06(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123b <main+0x6b>
lea    0xdfb(%rip),%rdi
call   10c0 <error@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    126f <main+0x9f>
lea    0xde2(%rip),%rdi
call   10c0 <error@plt>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bcopy@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x18(%rbp)
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   10b0 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0xc0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%r9d
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
call   1070 <sendto@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1321 <main+0x151>
lea    0xd82(%rip),%rdi
call   10c0 <error@plt>
lea    0xda1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x38(%rbp),%r8
lea    -0x18(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1364 <main+0x194>
lea    0xd8c(%rip),%rdi
call   10c0 <error@plt>
mov    $0x1,%edi
lea    0xdac(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
lea    -0xc0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    12a8 <main+0xd8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x3,%edi
jne    133c <main+0x15c>
mov    %rsi,%r14
mov    0x2de7(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1225 <main+0x45>
lea    0xde0(%rip),%rdi
call   10d0 <error@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r14),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1248 <main+0x68>
lea    0xdd8(%rip),%rdi
call   10d0 <error@plt>
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdi
mov    (%rbx),%edx
call   10c0 <memmove@plt>
mov    0x10(%r14),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xe3f(%rip),%r12
jmp    12b2 <main+0xd2>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
lea    0xd86(%rip),%rdi
call   1070 <printf@plt>
lea    0xda5(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
call   1080 <sendto@plt>
test   %eax,%eax
jns    12fd <main+0x11d>
lea    0xd75(%rip),%rdi
call   10d0 <error@plt>
lea    0xdd3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10a0 <recvfrom@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1290 <main+0xb0>
lea    0xd66(%rip),%rdi
call   10d0 <error@plt>
jmp    1290 <main+0xb0>
lea    0xdb5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@.str = [49 x i8] c"\0A\09\22CLIENT error\22 - Uso correto: servidor porta\0A\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [27 x i8] c"\0A\09CLIENT - error: socket\0A\09\00"
@.str.2 = [36 x i8] c"\0A\09CLIENT - error: host desconhecido\00"
@.str.3 = [43 x i8] c"\0ACLIENT: Digite a menssagem - 0 pra sair: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [43 x i8] c"\0A\09CLIENT - error: Send to - erro ao enviar\00"
@.str.6 = [34 x i8] c"\0AEsperando mensagem do Server...\0A\00"
@.str.7 = [49 x i8] c"\0ACLIENT - error: received from - erro ao receber\00"
@.str.8 = [14 x i8] c"Server Diz: \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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca [50 x i8]
%13 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %28, i32* %29
%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** %11
%34 = load %struct.hostent*, %struct.hostent** %11
%35 = icmp eq %struct.hostent* %34, null
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %27
%39 = load %struct.hostent*, %struct.hostent** %11
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 1
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to i8*
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%44 = bitcast i32* %43 to i8*
%45 = load %struct.hostent*, %struct.hostent** %11
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @bcopy(i8* %42, i8* %44, i32 %47)
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %53, i32* %54
store i32 12, i32* %7
br label %55
55: ; preds = %38, %78
%56 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%57 = bitcast [50 x i8]* %13 to i8**
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %57)
%59 = load i32, i32* %6
%60 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%61 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = load i32, i32* %7
%64 = call i32 @sendto(i32 %59, i8* %60, i32 %62, i32 0, %struct.sockaddr_in* %9, i32 %63)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %69
69: ; preds = %67, %55
%70 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%71 = load i32, i32* %6
%72 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%73 = call i32 @recvfrom(i32 %71, i8* %72, i32 256, i32 0, %struct.sockaddr_in* %10, i32* %7)
store i32 %73, i32* %8
%74 = load i32, i32* %8
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %69
%77 = call i32 @error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %76, %69
%79 = call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 12)
%80 = getelementptr inbounds [50 x i8], [50 x i8]* %13, i64 0, i64 0
%81 = load i32, i32* %8
%82 = call i32 @write(i32 1, i8* %80, i32 %81)
br label %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [27 x i8] c"\0A\09CLIENT - error: socket\0A\09\00"
@.str.2 = [36 x i8] c"\0A\09CLIENT - error: host desconhecido\00"
@.str.3 = [43 x i8] c"\0ACLIENT: Digite a menssagem - 0 pra sair: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [43 x i8] c"\0A\09CLIENT - error: Send to - erro ao enviar\00"
@.str.7 = [49 x i8] c"\0ACLIENT - error: received from - erro ao receber\00"
@.str.8 = [14 x i8] c"Server Diz: \00"
@str = [33 x i8] c"\0AEsperando mensagem do Server...\00"
@str.9 = [48 x i8] c"\0A\09\22CLIENT error\22 - Uso correto: servidor porta\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [50 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %23, i32* %24
%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 %31
29: ; preds = %22
%30 = tail call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 1
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to i8*
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%36 = bitcast i32* %35 to i8*
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
%41 = tail call i32 @atoi(i8* %40)
%42 = tail call i32 @htons(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %42, i32* %43
store i32 12, i32* %3
%44 = bitcast [50 x i8]* %6 to i8**
br label %45
45: ; preds = %60, %31
%46 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %44)
%48 = call i32 @strlen(i8* %10)
%49 = load i32, i32* %3
%50 = call i32 @sendto(i32 %18, i8* %10, i32 %48, i32 0, %struct.sockaddr_in* %4, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %45
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%56 = call i32 @recvfrom(i32 %18, i8* %10, i32 256, i32 0, %struct.sockaddr_in* %5, i32* %3)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
%61 = call i32 @write(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 12)
%62 = call i32 @write(i32 1, i8* %10, i32 %56)
br label %45
}