#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ node;
};
struct TYPE_4__ {
  TYPE_1__ id;
};
struct sockaddr_tipc {
  TYPE_2__ addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ AF_TIPC;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_RDM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
__u32 own_node(void) {
  struct sockaddr_tipc addr;
  socklen_t sz = sizeof(addr);
  int sd;
  sd = socket(AF_TIPC, SOCK_RDM, 0);
  if (sd < 0)
    do {
      printf("TIPC module not installed\n");
      exit(EXIT_FAILURE);
    } while (0);
  if (getsockname(sd, (struct sockaddr *)&addr, &sz) < 0)
    do {
      printf("failed to get TIPC socket address\n");
      exit(EXIT_FAILURE);
    } while (0);
  close(sd);
  return addr.addr.id.node;
}


x86 assembly (clang, -O0):
<own_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x4,-0xc(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11a4 <own_node+0x54>
jmp    118a <own_node+0x3a>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <getsockname@plt>
cmp    $0x0,%rax
jge    11dd <own_node+0x8d>
jmp    11c3 <own_node+0x73>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<own_node>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0xc(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11a3 <own_node+0x53>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1050 <getsockname@plt>
test   %rax,%rax
js     11ac <own_node+0x5c>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe78(%rip),%rdi
jmp    11b3 <own_node+0x63>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_tipc = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_TIPC = global i32 0
@SOCK_RDM = global i32 0
@.str = [27 x i8] c"TIPC module not installed\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [35 x i8] c"failed to get TIPC socket address\0A\00"
define i32 @own_node() {
%1 = alloca %struct.sockaddr_tipc
%2 = alloca i32
%3 = alloca i32
store i32 4, i32* %2
%4 = load i32, i32* @AF_TIPC
%5 = load i32, i32* @SOCK_RDM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
br label %10
10: ; preds = %9
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %0
%16 = load i32, i32* %3
%17 = bitcast %struct.sockaddr_tipc* %1 to %struct.sockaddr*
%18 = call i64 @getsockname(i32 %16, %struct.sockaddr* %17, i32* %2)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
br label %21
21: ; preds = %20
%22 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; No predecessors!
br label %26
26: ; preds = %25, %15
%27 = load i32, i32* %3
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_tipc, %struct.sockaddr_tipc* %1, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %29, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 0
%32 = load i32, i32* %31
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_tipc = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_TIPC = global i32 0
@SOCK_RDM = global i32 0
@EXIT_FAILURE = global i32 0
@str = [34 x i8] c"failed to get TIPC socket address\00"
@str.2 = [26 x i8] c"TIPC module not installed\00"
define i32 @own_node() {
%1 = alloca %struct.sockaddr_tipc
%2 = alloca i32
%3 = bitcast %struct.sockaddr_tipc* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%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 %13
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = bitcast %struct.sockaddr_tipc* %1 to %struct.sockaddr*
%15 = call i64 @getsockname(i32 %7, %struct.sockaddr* %14, i32* %2)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %13
%22 = call i32 @close(i32 %7)
%23 = getelementptr inbounds %struct.sockaddr_tipc, %struct.sockaddr_tipc* %1, i64 0, i32 0, i32 0, i32 0
%24 = load i32, i32* %23
ret i32 %24
}