#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 */
typedef int /*<<< orphan*/ uint16_t;
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void set_socket(struct sockaddr_in *socket_conf) {
  struct hostent *host;
  if ((host = gethostbyname("localhost")) == NULL) {
    perror("gethostbyname");
    fprintf(stderr, "Cannot get IP address for domain: '%s'\n", "localhost");
    abort();
  }
  socket_conf->sin_family = PF_INET;
  socket_conf->sin_port = htons((uint16_t)6667);
  socket_conf->sin_addr = *((struct in_addr *)host->h_addr_list[0]);
  memset(&(socket_conf->sin_zero), '\0', 2);
}


x86 assembly (clang, -O0):
<set_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b5 <set_socket+0x55>
lea    0xe7d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
lea    0xe57(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    $0x1a0b,%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe92(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11b5 <set_socket+0x55>
mov    %rax,%r14
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rbx)
mov    $0x1a0b,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rbx)
mov    (%r14),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <memset@plt>
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
lea    0xe28(%rip),%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Cannot get IP address for domain: '%s'\0A\00"
@PF_INET = global i32 0
define void @set_socket(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
%3 = alloca %struct.hostent*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %2
%4 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %4, %struct.hostent** %3
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %1
%12 = load i32, i32* @PF_INET
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 3
store i32 %12, i32* %14
%15 = call i32 @htons(i32 6667)
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %15, i32* %17
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
%20 = load %struct.hostent*, %struct.hostent** %3
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 0
%22 = load i64*, i64** %21
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to %struct.in_addr*
%26 = bitcast %struct.in_addr* %19 to i8*
%27 = bitcast %struct.in_addr* %25 to i8*
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %28, i32 0, i32 0
%30 = call i32 @memset(i32* %29, i8 signext 0, i32 2)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
@.str = [10 x i8] c"localhost\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Cannot get IP address for domain: '%s'\0A\00"
@PF_INET = global i32 0
define void @set_socket(%struct.sockaddr_in* %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %1
%10 = load i32, i32* @PF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 3
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 6667)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%15 = load i64*, i64** %14
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i32*
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1, i32 0
%19 = load i32, i32* %17
store i32 %19, i32* %18
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%21 = tail call i32 @memset(i32* %20, i8 signext 0, i32 2)
ret void
}