#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 {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int send_to_host(char *msg, char *remotehost) {
  int sockfd, numbytes;
  char buf[100];
  struct addrinfo hints, *servinfo, *p;
  int rv;
  char s[INET6_ADDRSTRLEN];
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  getaddrinfo(remotehost, "3491", &hints, &servinfo);
  sockfd =
      socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen);
  inet_ntop(servinfo->ai_family,
            get_in_addr((struct sockaddr *)servinfo->ai_addr), s, sizeof s);
  freeaddrinfo(servinfo);
  send(sockfd, msg, strlen(msg), 0);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<send_to_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xd8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xc0(%rbp)
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
lea    -0x98(%rbp),%rdx
lea    -0xa0(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    -0xa0(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0xa0(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0xa0(%rbp),%rax
mov    0x10(%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xa0(%rbp),%rax
mov    (%rax),%rsi
mov    -0xa0(%rbp),%rax
mov    0xc(%rax),%edx
call   1090 <connect@plt>
mov    -0xa0(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    -0xa0(%rbp),%rax
mov    (%rax),%rdi
call   1040 <get_in_addr@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe0(%rbp),%rdx
mov    %eax,%esi
mov    -0xd8(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa0(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xcc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_host>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    %rdi,-0x38(%rbp)
mov    %rsp,-0x40(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r14
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    -0x58(%rbp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
lea    0xdf4(%rip),%rsi
lea    -0x30(%rbp),%rcx
mov    %r12,%rdi
mov    %r13,%rdx
call   10a0 <getaddrinfo@plt>
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%esi
mov    0x8(%rax),%edi
mov    0x10(%rax),%edx
call   10c0 <socket@plt>
mov    %eax,%r12d
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
mov    0xc(%rax),%edx
mov    %r12d,%edi
call   1090 <connect@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%ebx
mov    (%rax),%rdi
call   1040 <get_in_addr@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <inet_ntop@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <freeaddrinfo@plt>
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [5 x i8] c"3491\00"
define i32 @send_to_host(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%14 = load i32, i32* @INET6_ADDRSTRLEN
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %12
%17 = alloca i8, i64 %15
store i64 %15, i64* %13
%18 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%19 = load i32, i32* @AF_UNSPEC
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @SOCK_STREAM
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %21, i32* %22
%23 = load i8*, i8** %4
%24 = call i32 @getaddrinfo(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %9)
%25 = load %struct.addrinfo*, %struct.addrinfo** %9
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load %struct.addrinfo*, %struct.addrinfo** %9
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = load %struct.addrinfo*, %struct.addrinfo** %9
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 3
%33 = load i32, i32* %32
%34 = call i32 @socket(i32 %27, i32 %30, i32 %33)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = load %struct.addrinfo*, %struct.addrinfo** %9
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load %struct.addrinfo*, %struct.addrinfo** %9
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @connect(i32 %35, i64 %38, i32 %41)
%43 = load %struct.addrinfo*, %struct.addrinfo** %9
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = load %struct.addrinfo*, %struct.addrinfo** %9
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 0
%48 = load i64, i64* %47
%49 = inttoptr i64 %48 to %struct.sockaddr*
%50 = call i32 @get_in_addr(%struct.sockaddr* %49)
%51 = trunc i64 %15 to i32
%52 = call i32 @inet_ntop(i32 %45, i32 %50, i8* %17, i32 %51)
%53 = load %struct.addrinfo*, %struct.addrinfo** %9
%54 = call i32 @freeaddrinfo(%struct.addrinfo* %53)
%55 = load i32, i32* %5
%56 = load i8*, i8** %3
%57 = load i8*, i8** %3
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @send(i32 %55, i8* %56, i32 %58, i32 0)
%60 = load i32, i32* %5
%61 = call i32 @close(i32 %60)
%62 = load i8*, i8** %12
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [5 x i8] c"3491\00"
define i32 @send_to_host(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %14, i32* %15
%16 = call i32 @getaddrinfo(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%17 = load %struct.addrinfo*, %struct.addrinfo** %4
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 3
%23 = load i32, i32* %22
%24 = call i32 @socket(i32 %19, i32 %21, i32 %23)
%25 = load %struct.addrinfo*, %struct.addrinfo** %4
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 0
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 @connect(i32 %24, i64 %27, i32 %29)
%31 = load %struct.addrinfo*, %struct.addrinfo** %4
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 0
%35 = load i64, i64* %34
%36 = inttoptr i64 %35 to %struct.sockaddr*
%37 = call i32 @get_in_addr(%struct.sockaddr* %36)
%38 = call i32 @inet_ntop(i32 %33, i32 %37, i8* %10, i32 %7)
%39 = load %struct.addrinfo*, %struct.addrinfo** %4
%40 = call i32 @freeaddrinfo(%struct.addrinfo* %39)
%41 = call i32 @strlen(i8* %0)
%42 = call i32 @send(i32 %24, i8* %0, i32 %41, i32 0)
%43 = call i32 @close(i32 %24)
ret i32 0
}