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

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
void main(int argc, char **argv) {
  struct sockaddr_in me, target;
  int sock, adl;
  char linha[81];
  if (argc != 2) {
    puts("falha a indicar endereço de IP do servidor");
    exit(1);
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  adl = sizeof(me);
  bzero((char *)&me, adl);
  me.sin_family = AF_INET;
  me.sin_addr.s_addr = htonl(INADDR_ANY);
  me.sin_port = htons(0);
  bind(sock, (struct sockaddr *)&me, adl);
  bzero((char *)&target, adl);
  target.sin_family = AF_INET;
  target.sin_addr.s_addr = inet_addr(argv[1]);
  target.sin_port = htons(60011);
  do {
    gets(linha);
    sendto(sock, linha, 81, 0, (struct sockaddr *)&target, adl);
    recvfrom(sock, linha, 81, 0, (struct sockaddr *)&target, &adl);
    puts(linha);
  } while (strcmp(linha, "rias"));
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1202 <main+0x32>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x44(%rbp)
movl   $0x18,-0x48(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   10d0 <bzero@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%edx
call   10c0 <bind@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   10d0 <bzero@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    $0xea6b,%edi
call   1040 <htons@plt>
mov    %rax,-0x40(%rbp)
lea    -0xa0(%rbp),%rdi
call   10a0 <gets@plt>
mov    -0x44(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9d
mov    $0x51,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    -0x44(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x51,%edx
xor    %ecx,%ecx
lea    -0x48(%rbp),%r9
call   10b0 <recvfrom@plt>
lea    -0xa0(%rbp),%rdi
call   1030 <puts@plt>
lea    -0xa0(%rbp),%rdi
lea    0xd27(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a3 <main+0xd3>
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
cmp    $0x2,%edi
jne    1307 <main+0x137>
mov    %rsi,%r15
mov    0x2df6(%rip),%r12
mov    (%r12),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
movl   $0x18,0xc(%rsp)
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x30(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,0x28(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%r15),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x18(%rsp)
mov    $0xea6b,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0x40(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xd8c(%rip),%r12
mov    %rbx,%rdi
call   10a0 <gets@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1060 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10b0 <recvfrom@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    12a0 <main+0xd0>
mov    %ebp,%edi
call   1070 <close@plt>
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [44 x i8] c"falha a indicar endere\C3\A7o de IP do servidor\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"rias\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca [81 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = call i32 @socket(i8* %16, i32 %17, i32 0)
store i32 %18, i32* %7
store i32 24, i32* %8
%19 = bitcast %struct.sockaddr_in* %5 to i8*
%20 = load i32, i32* %8
%21 = call i32 @bzero(i8* %19, i32 %20)
%22 = load i8*, i8** @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %22, i8** %23
%24 = load i32, i32* @INADDR_ANY
%25 = call i32 @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = call i8* @htons(i32 0)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i8* %28, i8** %29
%30 = load i32, i32* %7
%31 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%32 = load i32, i32* %8
%33 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 %32)
%34 = bitcast %struct.sockaddr_in* %6 to i8*
%35 = load i32, i32* %8
%36 = call i32 @bzero(i8* %34, i32 %35)
%37 = load i8*, i8** @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %37, i8** %38
%39 = load i8**, i8*** %4
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @inet_addr(i8* %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%44 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %43, i32 0, i32 0
store i32 %42, i32* %44
%45 = call i8* @htons(i32 60011)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i8* %45, i8** %46
br label %47
47: ; preds = %61, %15
%48 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%49 = call i32 @gets(i8* %48)
%50 = load i32, i32* %7
%51 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%52 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%53 = load i32, i32* %8
%54 = call i32 @sendto(i32 %50, i8* %51, i32 81, i32 0, %struct.sockaddr* %52, i32 %53)
%55 = load i32, i32* %7
%56 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%58 = call i32 @recvfrom(i32 %55, i8* %56, i32 81, i32 0, %struct.sockaddr* %57, i32* %8)
%59 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%60 = call i32 @puts(i8* %59)
br label %61
61: ; preds = %47
%62 = getelementptr inbounds [81 x i8], [81 x i8]* %9, i64 0, i64 0
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%64 = icmp ne i64 %63, 0
br i1 %64, label %47, label %65
65: ; preds = %61
%66 = load i32, i32* %7
%67 = call i32 @close(i32 %66)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [44 x i8] c"falha a indicar endere\C3\A7o de IP do servidor\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [5 x i8] c"rias\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [81 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i8* %16, i32 %17, i32 0)
store i32 24, i32* %5
%19 = call i32 @bzero(i8* %7, i32 24)
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %20, i8** %21
%22 = load i32, i32* @INADDR_ANY
%23 = tail call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = tail call i8* @htons(i32 0)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %25, i8** %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @bind(i32 %18, %struct.sockaddr* %27, i32 24)
%29 = call i32 @bzero(i8* %8, i32 24)
%30 = load i8*, i8** @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %30, i8** %31
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %34, i32* %35
%36 = call i8* @htons(i32 60011)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %36, i8** %37
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %39
39: ; preds = %39, %15
%40 = call i32 @gets(i8* %10)
%41 = load i32, i32* %5
%42 = call i32 @sendto(i32 %18, i8* %10, i32 81, i32 0, %struct.sockaddr* %38, i32 %41)
%43 = call i32 @recvfrom(i32 %18, i8* %10, i32 81, i32 0, %struct.sockaddr* %38, i32* %5)
%44 = call i32 @puts(i8* %10)
%45 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %39
47: ; preds = %39
%48 = call i32 @close(i32 %18)
ret void
}