#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct tipc_sioc_nodeid_req {
  scalar_t__ node_id;
  int /*<<< orphan*/ peer;
};

/* Variables and functions */
int /*<<< orphan*/ AF_TIPC;
int /*<<< orphan*/ SIOCGETNODEID;
int /*<<< orphan*/ SOCK_RDM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/,
                         struct tipc_sioc_nodeid_req *);
int /*<<< orphan*/ nodeid2str(int /*<<< orphan*/ *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void hash2nodestr(uint32_t hash, char *str) {
  struct tipc_sioc_nodeid_req nr = {};
  int sd;
  sd = socket(AF_TIPC, SOCK_RDM, 0);
  if (sd < 0) {
    fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
    return;
  }
  nr.peer = hash;
  if (!ioctl(sd, SIOCGETNODEID, &nr))
    nodeid2str((uint8_t *)nr.node_id, str);
  close(sd);
}


x86 assembly (clang, -O0):
<hash2nodestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11e6 <hash2nodestr+0x76>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
jmp    121f <hash2nodestr+0xaf>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%eax
jne    1217 <hash2nodestr+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <nodeid2str@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash2nodestr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11ca <hash2nodestr+0x6a>
mov    %eax,%ebp
mov    %ebx,0x8(%rsp)
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
jne    11ba <hash2nodestr+0x5a>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1050 <nodeid2str@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%ebx
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe18(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
%struct.tipc_sioc_nodeid_req = type { i64, i32 }
@AF_TIPC = global i32 0
@SOCK_RDM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"opening TIPC socket: %s\0A\00"
@errno = global i32 0
@SIOCGETNODEID = global i32 0
define void @hash2nodestr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.tipc_sioc_nodeid_req
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = bitcast %struct.tipc_sioc_nodeid_req* %5 to i8*
%8 = load i32, i32* @AF_TIPC
%9 = load i32, i32* @SOCK_RDM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %34
18: ; preds = %2
%19 = load i32, i32* %3
%20 = getelementptr inbounds %struct.tipc_sioc_nodeid_req, %struct.tipc_sioc_nodeid_req* %5, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* %6
%22 = load i32, i32* @SIOCGETNODEID
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.tipc_sioc_nodeid_req* %5)
%24 = icmp ne i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %18
%26 = getelementptr inbounds %struct.tipc_sioc_nodeid_req, %struct.tipc_sioc_nodeid_req* %5, i32 0, i32 0
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i32*
%29 = load i8*, i8** %4
%30 = call i32 @nodeid2str(i32* %28, i8* %29)
br label %31
31: ; preds = %25, %18
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %31, %13
ret void
}

LLVM IR (-O2):
%struct.tipc_sioc_nodeid_req = type { i64, i32 }
@AF_TIPC = global i32 0
@SOCK_RDM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"opening TIPC socket: %s\0A\00"
@errno = global i32 0
@SIOCGETNODEID = global i32 0
define void @hash2nodestr(i32 %0, i8* %1) {
%3 = alloca %struct.tipc_sioc_nodeid_req
%4 = bitcast %struct.tipc_sioc_nodeid_req* %3 to i8*
%5 = load i32, i32* @AF_TIPC
%6 = load i32, i32* @SOCK_RDM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %26
14: ; preds = %2
%15 = getelementptr inbounds %struct.tipc_sioc_nodeid_req, %struct.tipc_sioc_nodeid_req* %3, i64 0, i32 1
store i32 %0, i32* %15
%16 = load i32, i32* @SIOCGETNODEID
%17 = call i32 @ioctl(i32 %7, i32 %16, %struct.tipc_sioc_nodeid_req* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = getelementptr inbounds %struct.tipc_sioc_nodeid_req, %struct.tipc_sioc_nodeid_req* %3, i64 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i32*
%23 = call i32 @nodeid2str(i32* %22, i8* %1)
br label %24
24: ; preds = %19, %14
%25 = call i32 @close(i32 %7)
br label %26
26: ; preds = %24, %9
ret void
}