#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 in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  scalar_t__ h_addrtype;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
scalar_t__ gethostname(char *, int);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
const char *orta_host_addr() {
  static char hname[256];
  struct hostent *hent;
  struct in_addr iaddr;
  if (gethostname(hname, 256) != 0) {
    perror("orta_host_addr");
    abort();
  }
  hent = gethostbyname(hname);
  if (hent == NULL) {
    fprintf(stderr, "Can't resolve IP address for %s", hname);
    return NULL;
  }
  assert(hent->h_addrtype == AF_INET);
  memcpy(&iaddr.s_addr, hent->h_addr, sizeof(iaddr.s_addr));
  strncpy(hname, inet_ntoa(iaddr), 256);
  return (const char *)hname;
}


x86 assembly (clang, -O0):
<orta_host_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0x2ee1(%rip),%rdi
mov    $0x100,%esi
call   10b0 <gethostname@plt>
cmp    $0x0,%rax
je     11c6 <orta_host_addr+0x36>
lea    0xe46(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0x2eb3(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120a <orta_host_addr+0x7a>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
lea    0x2e88(%rip),%rdx
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1263 <orta_host_addr+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    -0x18(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %eax,%esi
lea    0x2e32(%rip),%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
lea    0x2e21(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orta_host_addr>:
push   %r14
push   %rbx
push   %rax
lea    0x2ee5(%rip),%rdi
mov    $0x100,%esi
call   10b0 <gethostname@plt>
test   %rax,%rax
jne    1230 <orta_host_addr+0xa0>
lea    0x2ecb(%rip),%r14
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1206 <orta_host_addr+0x76>
mov    %rax,%rbx
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%rax
sete   %dil
call   1070 <assert@plt>
mov    0x8(%rbx),%esi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    (%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x100,%edx
call   1040 <strncpy@plt>
jmp    1225 <orta_host_addr+0x95>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
lea    0x2e63(%rip),%rdx
call   1080 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdc9(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.hostent = type { i64, i32 }
%struct.in_addr = type { i32 }
@orta_host_addr.hname = internal global [256 x i8] zeroinitializer
@.str = [15 x i8] c"orta_host_addr\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't resolve IP address for %s\00"
@AF_INET = global i64 0
define i8* @orta_host_addr() {
%1 = alloca i8*
%2 = alloca %struct.hostent*
%3 = alloca %struct.in_addr
%4 = call i64 @gethostname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), i32 256)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0))
store %struct.hostent* %10, %struct.hostent** %2
%11 = load %struct.hostent*, %struct.hostent** %2
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0))
store i8* null, i8** %1
br label %33
16: ; preds = %9
%17 = load %struct.hostent*, %struct.hostent** %2
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @AF_INET
%21 = icmp eq i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%25 = load %struct.hostent*, %struct.hostent** %2
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 @memcpy(i32* %24, i32 %27, i32 4)
%29 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @inet_ntoa(i32 %30)
%32 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), i32 %31, i32 256)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), i8** %1
br label %33
33: ; preds = %16, %13
%34 = load i8*, i8** %1
ret i8* %34
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i64, i32 }
@orta_host_addr.hname = internal global [256 x i8] zeroinitializer
@.str = [15 x i8] c"orta_host_addr\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Can't resolve IP address for %s\00"
@AF_INET = global i64 0
define i8* @orta_host_addr() {
%1 = alloca %struct.in_addr
%2 = bitcast %struct.in_addr* %1 to i8*
%3 = tail call i64 @gethostname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), i32 256)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %0
%9 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0))
%10 = icmp eq %struct.hostent* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0))
br label %28
14: ; preds = %8
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET
%18 = icmp eq i64 %16, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %9, i64 0, i32 1
%23 = load i32, i32* %22
%24 = call i32 @memcpy(i32* %21, i32 %23, i32 4)
%25 = load i32, i32* %21
%26 = call i32 @inet_ntoa(i32 %25)
%27 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), i32 %26, i32 256)
br label %28
28: ; preds = %14, %11
%29 = phi i8* [ null, %11 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @orta_host_addr.hname, i64 0, i64 0), %14 ]
ret i8* %29
}