#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*/ FIONBIO;
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*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ puts(char *);
int 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 *);
int /*<<< orphan*/ usleep(int);
void main(int argc, char **argv) {
  struct sockaddr_in me, target;
  int sock, adl, um, timeout;
  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);
  um = 1;
  ioctl(sock, FIONBIO, &um);
  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);
    timeout = 5;
    while (timeout) {
      usleep(1000);
      if (recvfrom(sock, linha, 81, 0, (struct sockaddr *)&target, &adl) != -1)
        break;
      timeout--;
    }
    if (timeout)
      puts(linha);
    else
      puts("Sem resposta\n");
  } while (strcmp(linha, "rias"));
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1222 <main+0x32>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x44(%rbp)
movl   $0x18,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
lea    -0x4c(%rbp),%rdx
call   1060 <ioctl@plt>
lea    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   10e0 <bzero@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d5d(%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   10d0 <bind@plt>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   10e0 <bzero@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    $0xea6b,%edi
call   1040 <htons@plt>
mov    %rax,-0x40(%rbp)
lea    -0xb0(%rbp),%rdi
call   10b0 <gets@plt>
mov    -0x44(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9d
mov    $0x51,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
movl   $0x5,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     135e <main+0x16e>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    -0x44(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x40(%rbp),%r8
mov    $0x51,%edx
xor    %ecx,%ecx
lea    -0x48(%rbp),%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1350 <main+0x160>
jmp    135e <main+0x16e>
mov    -0x50(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x50(%rbp)
jmp    1310 <main+0x120>
cmpl   $0x0,-0x50(%rbp)
je     1379 <main+0x189>
lea    -0xb0(%rbp),%rdi
call   1030 <puts@plt>
jmp    1385 <main+0x195>
lea    0xcac(%rip),%rdi
call   1030 <puts@plt>
jmp    138a <main+0x19a>
lea    -0xb0(%rbp),%rdi
lea    0xca2(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12df <main+0xef>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
cmp    $0x2,%edi
jne    141c <main+0x22c>
mov    %rsi,%r15
mov    0x2dd4(%rip),%r12
mov    (%r12),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebp
movl   $0x18,0x8(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1060 <ioctl@plt>
lea    0x28(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   10e0 <bzero@plt>
mov    (%r12),%rax
mov    %rax,0x38(%rsp)
mov    0x2d6f(%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   10d0 <bind@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   10e0 <bzero@plt>
mov    (%r12),%rax
mov    %rax,0x20(%rsp)
mov    0x8(%r15),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x18(%rsp)
mov    $0xea6b,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
lea    0x40(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0xd4d(%rip),%r12
lea    0xd54(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10b0 <gets@plt>
mov    0x8(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <sendto@plt>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1f0>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1f0>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1f0>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    13e0 <main+0x1f0>
mov    $0x3e8,%edi
call   1100 <usleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     13fe <main+0x20e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    12f0 <main+0x100>
jmp    1403 <main+0x213>
mov    %r12,%rdi
jmp    13e3 <main+0x1f3>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbdd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10f0 <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
@FIONBIO = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [14 x i8] c"Sem resposta\0A\00"
@.str.2 = [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 i32
%10 = alloca i32
%11 = alloca [81 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8*, i8** @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket(i8* %18, i32 %19, i32 0)
store i32 %20, i32* %7
store i32 24, i32* %8
store i32 1, i32* %9
%21 = load i32, i32* %7
%22 = load i32, i32* @FIONBIO
%23 = call i32 @ioctl(i32 %21, i32 %22, i32* %9)
%24 = bitcast %struct.sockaddr_in* %5 to i8*
%25 = load i32, i32* %8
%26 = call i32 @bzero(i8* %24, i32 %25)
%27 = load i8*, i8** @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %27, i8** %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i8* @htons(i32 0)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i8* %33, i8** %34
%35 = load i32, i32* %7
%36 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%37 = load i32, i32* %8
%38 = call i32 @bind(i32 %35, %struct.sockaddr* %36, i32 %37)
%39 = bitcast %struct.sockaddr_in* %6 to i8*
%40 = load i32, i32* %8
%41 = call i32 @bzero(i8* %39, i32 %40)
%42 = load i8*, i8** @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %42, i8** %43
%44 = load i8**, i8*** %4
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @inet_addr(i8* %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = call i8* @htons(i32 60011)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i8* %50, i8** %51
br label %52
52: ; preds = %83, %17
%53 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%54 = call i32 @gets(i8* %53)
%55 = load i32, i32* %7
%56 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%58 = load i32, i32* %8
%59 = call i32 @sendto(i32 %55, i8* %56, i32 81, i32 0, %struct.sockaddr* %57, i32 %58)
store i32 5, i32* %10
br label %60
60: ; preds = %71, %52
%61 = load i32, i32* %10
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %74
63: ; preds = %60
%64 = call i32 @usleep(i32 1000)
%65 = load i32, i32* %7
%66 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%67 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%68 = call i32 @recvfrom(i32 %65, i8* %66, i32 81, i32 0, %struct.sockaddr* %67, i32* %8)
%69 = icmp ne i32 %68, -1
br i1 %69, label %70, label %71
70: ; preds = %63
br label %74
71: ; preds = %63
%72 = load i32, i32* %10
%73 = add nsw i32 %72, -1
store i32 %73, i32* %10
br label %60
74: ; preds = %70, %60
%75 = load i32, i32* %10
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%79 = call i32 @puts(i8* %78)
br label %82
80: ; preds = %74
%81 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %82
82: ; preds = %80, %77
br label %83
83: ; preds = %82
%84 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%86 = icmp ne i64 %85, 0
br i1 %86, label %52, label %87
87: ; preds = %83
%88 = load i32, i32* %7
%89 = call i32 @close(i32 %88)
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
@FIONBIO = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [14 x i8] c"Sem resposta\0A\00"
@.str.2 = [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 i32
%7 = alloca [81 x i8]
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%13 = icmp eq i32 %0, 2
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8*, i8** @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = tail call i32 @socket(i8* %18, i32 %19, i32 0)
store i32 24, i32* %5
store i32 1, i32* %6
%21 = load i32, i32* @FIONBIO
%22 = call i32 @ioctl(i32 %20, i32 %21, i32* %6)
%23 = call i32 @bzero(i8* %8, i32 24)
%24 = load i8*, i8** @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %24, i8** %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = call i8* @htons(i32 0)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %29, i8** %30
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @bind(i32 %20, %struct.sockaddr* %31, i32 24)
%33 = call i32 @bzero(i8* %9, i32 24)
%34 = load i8*, i8** @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %34, i8** %35
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @inet_addr(i8* %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %38, i32* %39
%40 = call i8* @htons(i32 60011)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %40, i8** %41
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %43
43: ; preds = %70, %17
%44 = call i32 @gets(i8* %12)
%45 = load i32, i32* %5
%46 = call i32 @sendto(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32 %45)
%47 = call i32 @usleep(i32 1000)
%48 = call i32 @recvfrom(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32* %5)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %68
50: ; preds = %43
%51 = call i32 @usleep(i32 1000)
%52 = call i32 @recvfrom(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32* %5)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %68
54: ; preds = %50
%55 = call i32 @usleep(i32 1000)
%56 = call i32 @recvfrom(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32* %5)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = call i32 @usleep(i32 1000)
%60 = call i32 @recvfrom(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32* %5)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = call i32 @usleep(i32 1000)
%64 = call i32 @recvfrom(i32 %20, i8* %12, i32 81, i32 0, %struct.sockaddr* %42, i32* %5)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %70
68: ; preds = %62, %58, %54, %50, %43
%69 = call i32 @puts(i8* %12)
br label %70
70: ; preds = %68, %66
%71 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %43
73: ; preds = %70
%74 = call i32 @close(i32 %20)
ret void
}