#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*/ u_long;
struct utsname {
  int /*<<< orphan*/ nodename;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
long INADDR_NONE;
struct hostent *gethostbyname(int /*<<< orphan*/);
long htonl(int /*<<< orphan*/);
scalar_t__ uname(struct utsname *);
long int __gethostid(void) {
  struct utsname uts_name;
  struct hostent *hp = NULL;
  if (uname(&uts_name) == 0) {
    hp = gethostbyname(uts_name.nodename);
  }
  return hp ? htonl(*(u_long *)hp->h_addr) : INADDR_NONE;
}


x86 assembly (clang, -O0):
<__gethostid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <uname@plt>
cmp    $0x0,%rax
jne    115f <__gethostid+0x2f>
mov    -0x8(%rbp),%edi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1181 <__gethostid+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %rax,-0x18(%rbp)
jmp    118f <__gethostid+0x5f>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__gethostid>:
push   %rax
mov    %rsp,%rdi
call   1030 <uname@plt>
test   %rax,%rax
je     114a <__gethostid+0x1a>
mov    0x2ea3(%rip),%rax
mov    (%rax),%rax
pop    %rcx
ret
mov    (%rsp),%edi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     113e <__gethostid+0xe>
mov    (%rax),%rax
mov    (%rax),%edi
pop    %rax
jmp    1040 <htonl@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
%struct.hostent = type { i64 }
@INADDR_NONE = global i64 0
define i64 @__gethostid() {
%1 = alloca %struct.utsname
%2 = alloca %struct.hostent*
store %struct.hostent* null, %struct.hostent** %2
%3 = call i64 @uname(%struct.utsname* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = call %struct.hostent* @gethostbyname(i32 %7)
store %struct.hostent* %8, %struct.hostent** %2
br label %9
9: ; preds = %5, %0
%10 = load %struct.hostent*, %struct.hostent** %2
%11 = icmp ne %struct.hostent* %10, null
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load %struct.hostent*, %struct.hostent** %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to i32*
%17 = load i32, i32* %16
%18 = call i64 @htonl(i32 %17)
br label %21
19: ; preds = %9
%20 = load i64, i64* @INADDR_NONE
br label %21
21: ; preds = %19, %12
%22 = phi i64 [ %18, %12 ], [ %20, %19 ]
ret i64 %22
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
%struct.hostent = type { i64 }
@INADDR_NONE = global i64 0
define i64 @__gethostid() {
%1 = alloca %struct.utsname
%2 = bitcast %struct.utsname* %1 to i8*
%3 = call i64 @uname(%struct.utsname* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %0
%6 = getelementptr inbounds %struct.utsname, %struct.utsname* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call %struct.hostent* @gethostbyname(i32 %7)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to i32*
%14 = load i32, i32* %13
%15 = tail call i64 @htonl(i32 %14)
br label %18
16: ; preds = %0, %5
%17 = load i64, i64* @INADDR_NONE
br label %18
18: ; preds = %16, %10
%19 = phi i64 [ %15, %10 ], [ %17, %16 ]
ret i64 %19
}