#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*/ server_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  void fclient(int, struct sockaddr *, int, char *);
  int socketfd;
  struct sockaddr_in server_addr, cli_addr;
  char *pname, *fname;
  if (argc != 2) {
    perror("Debe escribir:\n./client fichero_tecto.txt");
    exit(0);
  }
  pname = argv[0];
  fname = argv[1];
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  server_addr.sin_port = htons(6544);
  if ((socketfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("client: Can't open datagram socket");
  }
  bzero((char *)&cli_addr, sizeof(cli_addr));
  cli_addr.sin_family = AF_INET;
  cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  cli_addr.sin_port = htons(0);
  if (bind(socketfd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)) < 0) {
    perror("server: can't bind local address");
  }
  fclient(socketfd, (struct sockaddr *)&server_addr, sizeof(server_addr),
          fname);
  close(socketfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d3 <main+0x33>
lea    0xe39(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xe1d(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    $0x1990,%edi
call   1030 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%rdi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1255 <main+0xb5>
lea    0xde4(%rip),%rdi
call   1090 <perror@plt>
lea    -0x48(%rbp),%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x40(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    12b4 <main+0x114>
lea    0xda8(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x58(%rbp),%rcx
mov    $0x18,%edx
call   1060 <fclient@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%edi
jne    12a0 <main+0x100>
mov    0x8(%rsi),%r14
lea    0x8(%rsp),%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    0x2e1b(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
lea    0xe4e(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    $0x1990,%edi
call   1030 <htons@plt>
mov    %rax,0x8(%rsp)
mov    (%r15),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1281 <main+0xe1>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x18,%esi
call   10a0 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x30(%rsp)
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x28(%rsp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,0x20(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     1292 <main+0xf2>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
mov    %r14,%rcx
call   1060 <fclient@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdac(%rip),%rdi
call   1090 <perror@plt>
jmp    120d <main+0x6d>
lea    0xdbe(%rip),%rdi
call   1090 <perror@plt>
jmp    1259 <main+0xb9>
lea    0xd59(%rip),%rdi
call   1090 <perror@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Debe escribir:\0A./client fichero_tecto.txt\00"
@AF_INET = global i8* null
@.str.1 = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [35 x i8] c"client: Can't open datagram socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [33 x i8] c"server: can't bind local address\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.sockaddr_in
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
store i8* %19, i8** %9
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %10
%23 = bitcast %struct.sockaddr_in* %7 to i8*
%24 = call i32 @bzero(i8* %23, i32 24)
%25 = load i8*, i8** @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %25, i8** %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = call i8* @htons(i32 6544)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i8* %30, i8** %31
%32 = load i8*, i8** @AF_INET
%33 = load i32, i32* @SOCK_DGRAM
%34 = call i32 @socket(i8* %32, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %16
%37 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %16
%39 = bitcast %struct.sockaddr_in* %8 to i8*
%40 = call i32 @bzero(i8* %39, i32 24)
%41 = load i8*, i8** @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i8* %41, i8** %42
%43 = load i32, i32* @INADDR_ANY
%44 = call i32 @htonl(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
store i32 %44, i32* %46
%47 = call i8* @htons(i32 0)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i8* %47, i8** %48
%49 = load i32, i32* %6
%50 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%51 = call i64 @bind(i32 %49, %struct.sockaddr* %50, i32 24)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %38
%54 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %38
%56 = load i32, i32* %6
%57 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%58 = load i8*, i8** %10
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [42 x i8] c"Debe escribir:\0A./client fichero_tecto.txt\00"
@AF_INET = global i8* null
@.str.1 = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [35 x i8] c"client: Can't open datagram socket\00"
@INADDR_ANY = global i32 0
@.str.3 = [33 x i8] c"server: can't bind local address\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @bzero(i8* %5, i32 24)
%15 = load i8*, i8** @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %15, i8** %16
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = tail call i8* @htons(i32 6544)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i8* %19, i8** %20
%21 = load i8*, i8** @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = tail call i32 @socket(i8* %21, i32 %22, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %11
%26 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %11
%28 = call i32 @bzero(i8* %6, i32 24)
%29 = load i8*, i8** @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %29, i8** %30
%31 = load i32, i32* @INADDR_ANY
%32 = tail call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %32, i32* %33
%34 = tail call i8* @htons(i32 0)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i8* %34, i8** %35
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i64 @bind(i32 %23, %struct.sockaddr* %36, i32 24)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %27
%42 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%43 = call i32 @close(i32 %23)
ret i32 0
}