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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned short);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int enviar_tcp(char *ipdestino, unsigned short dpuerto, unsigned short puerto) {
  char buf[256], *p;
  struct sockaddr_in dire;
  int soc;
  if ((soc = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Error al crear el socket.\n");
    exit(-1);
  }
  bzero((void *)&dire, sizeof(dire));
  dire.sin_family = AF_INET;
  dire.sin_port = htons(dpuerto);
  dire.sin_addr.s_addr = inet_addr(ipdestino);
  if (connect(soc, (struct sockaddr *)&dire, sizeof(dire)) == -1) {
    perror("Error al conectar al puerto destino.\n");
    exit(-1);
  }
  bzero(buf, sizeof(buf));
  strcpy(buf, "ENYELKMTCPKEY");
  p = buf + strlen("ENYELKMTCPKEY");
  *((unsigned short *)p) = puerto;
  printf("Enviando firma TCP al puerto %d ...\n", dpuerto);
  fflush(stdout);
  write(soc, buf, strlen("ENYELKMTCPKEY") + sizeof(unsigned short));
  close(soc);
  return (0);
}


x86 assembly (clang, -O0):
<enviar_tcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x12c(%rbp)
cmp    $0xffffffff,%eax
jne    122b <enviar_tcp+0x5b>
lea    0xde4(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    -0x128(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
movzwl -0xa(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x128(%rbp)
mov    -0x12c(%rbp),%edi
lea    -0x128(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    129f <enviar_tcp+0xcf>
lea    0xd8b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    -0x110(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    0xd69(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x118(%rbp)
mov    -0xc(%rbp),%cx
mov    -0x118(%rbp),%rax
mov    %cx,(%rax)
lea    0xd47(%rip),%rdi
movzwl -0xa(%rbp),%esi
call   1070 <printf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    0xd01(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
cltq
add    $0x2,%rax
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x12c(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enviar_tcp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2df8(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12d8 <enviar_tcp+0x108>
mov    %eax,%ebx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
movzwl %bp,%ebp
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1090 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     12e1 <enviar_tcp+0x111>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    0xdd0(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
mov    %r14w,0x10(%rsp,%rax,1)
lea    0xdbc(%rip),%rdi
mov    %ebp,%esi
call   1070 <printf@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd21(%rip),%rdi
jmp    12e8 <enviar_tcp+0x118>
lea    0xd33(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"Error al crear el socket.\0A\00"
@.str.1 = [38 x i8] c"Error al conectar al puerto destino.\0A\00"
@.str.2 = [14 x i8] c"ENYELKMTCPKEY\00"
@.str.3 = [37 x i8] c"Enviando firma TCP al puerto %d ...\0A\00"
@stdout = global i32 0
define i32 @enviar_tcp(i8* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i16
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
store i8* %0, i8** %4
store i16 %1, i16* %5
store i16 %2, i16* %6
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %10
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %3
%19 = bitcast %struct.sockaddr_in* %9 to i8*
%20 = call i32 @bzero(i8* %19, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i16, i16* %5
%24 = call i32 @htons(i16 zeroext %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %24, i32* %25
%26 = load i8*, i8** %4
%27 = call i32 @inet_addr(i8* %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %10
%31 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%32 = call i32 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %18
%35 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %18
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%39 = call i32 @bzero(i8* %38, i32 256)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%43 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8* %45, i8** %8
%46 = load i16, i16* %6
%47 = load i8*, i8** %8
%48 = bitcast i8* %47 to i16*
store i16 %46, i16* %48
%49 = load i16, i16* %5
%50 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %49)
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
%53 = load i32, i32* %10
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%55 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%56 = sext i32 %55 to i64
%57 = add i64 %56, 2
%58 = trunc i64 %57 to i32
%59 = call i32 @write(i32 %53, i8* %54, i32 %58)
%60 = load i32, i32* %10
%61 = call i32 @close(i32 %60)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"Error al crear el socket.\0A\00"
@.str.1 = [38 x i8] c"Error al conectar al puerto destino.\0A\00"
@.str.2 = [14 x i8] c"ENYELKMTCPKEY\00"
@.str.3 = [37 x i8] c"Enviando firma TCP al puerto %d ...\0A\00"
@stdout = global i32 0
define i32 @enviar_tcp(i8* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca [256 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %3
%16 = call i32 @bzero(i8* %7, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i16 zeroext %1)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %19, i32* %20
%21 = tail call i32 @inet_addr(i8* %0)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%24 = call i32 @connect(i32 %10, %struct.sockaddr* %23, i32 12)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %15
%30 = call i32 @bzero(i8* %6, i32 256)
%31 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %33
%35 = bitcast i8* %34 to i16*
store i16 %2, i16* %35
%36 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i16 zeroext %1)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%40 = add i32 %39, 2
%41 = call i32 @write(i32 %10, i8* %6, i32 %40)
%42 = call i32 @close(i32 %10)
ret i32 0
}