#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ discard(char *);
int /*<<< orphan*/ error(char *, char *);
char *get_address(int);
int get_port(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
struct sockaddr_in get_remote_server(int node) {
  struct sockaddr_in serveraddr;
  struct hostent *server;
  char *hostname;
  int port;
  hostname = get_address(node);
  port = get_port(node);
  ;
  server = gethostbyname(hostname);
  discard(hostname);
  if (server == NULL) {
    error("ERROR, no such host as %s", hostname);
    assert(0);
  }
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr,
        server->h_length);
  serveraddr.sin_port = htons(port);
  return serveraddr;
}


x86 assembly (clang, -O0):
<get_remote_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <get_address@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <get_port@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <discard@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11ea <get_remote_server+0x5a>
mov    -0x28(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   10a0 <error@plt>
xor    %edi,%edi
call   1070 <assert@plt>
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0xc(%rbp),%rsi
mov    (%rax),%edx
call   1090 <bcopy@plt>
mov    -0x2c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%edx
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_remote_server>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1030 <get_address@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1040 <get_port@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1090 <discard@plt>
test   %rbx,%rbx
jne    11da <get_remote_server+0x4a>
lea    0xe35(%rip),%rdi
mov    %rbp,%rsi
call   10a0 <error@plt>
xor    %edi,%edi
call   1070 <assert@plt>
mov    %rsp,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   1080 <memcpy@plt>
mov    %r14d,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    (%rsp),%rax
mov    0x8(%rsp),%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@.str = [26 x i8] c"ERROR, no such host as %s\00"
@AF_INET = global i32 0
define { i64, i32 } @get_remote_server(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca %struct.hostent*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca { i64, i32 }
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = call i8* @get_address(i32 %8)
store i8* %9, i8** %5
%10 = load i32, i32* %3
%11 = call i32 @get_port(i32 %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %5
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %4
%14 = load i8*, i8** %5
%15 = call i32 @discard(i8* %14)
%16 = load %struct.hostent*, %struct.hostent** %4
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i8*, i8** %5
%20 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @assert(i32 0)
br label %22
22: ; preds = %18, %1
%23 = bitcast %struct.sockaddr_in* %2 to i8*
%24 = call i32 @bzero(i8* %23, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %25, i32* %26
%27 = load %struct.hostent*, %struct.hostent** %4
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = bitcast i32* %32 to i8*
%34 = load %struct.hostent*, %struct.hostent** %4
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @bcopy(i8* %30, i8* %33, i32 %36)
%38 = load i32, i32* %6
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %39, i32* %40
%41 = bitcast { i64, i32 }* %7 to i8*
%42 = bitcast %struct.sockaddr_in* %2 to i8*
%43 = load { i64, i32 }, { i64, i32 }* %7
ret { i64, i32 } %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@.str = [26 x i8] c"ERROR, no such host as %s\00"
@AF_INET = global i32 0
define { i64, i32 } @get_remote_server(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = tail call i8* @get_address(i32 %0)
%4 = tail call i32 @get_port(i32 %0)
%5 = tail call %struct.hostent* @gethostbyname(i8* %3)
%6 = tail call i32 @discard(i8* %3)
%7 = icmp eq %struct.hostent* %5, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = tail call i32 @assert(i32 0)
br label %11
11: ; preds = %8, %1
%12 = bitcast %struct.sockaddr_in* %2 to i8*
%13 = call i32 @bzero(i8* %12, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 1
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%20 = bitcast i32* %19 to i8*
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 @htons(i32 %4)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %2 to i64*
%26 = load i64, i64* %25
%27 = load i32, i32* %15
%28 = insertvalue { i64, i32 } poison, i64 %26, 0
%29 = insertvalue { i64, i32 } %28, i32 %27, 1
ret { i64, i32 } %29
}