#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int intf_numa_node(const char *iface) {
  int fd, numa_node = -1, len;
  char buf[256];
  snprintf(buf, 256, "/sys/class/net/%s/device/numa_node", iface);
  fd = open(buf, O_RDONLY);
  if (fd == -1)
    return -1;
  len = read(fd, buf, sizeof(buf));
  if (len < 0)
    goto cleanup;
  numa_node = strtol(buf, NULL, 0);
cleanup:
  close(fd);
  return numa_node;
}


x86 assembly (clang, -O0):
<intf_numa_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe83(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b0 <intf_numa_node+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <intf_numa_node+0xa9>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d6 <intf_numa_node+0x86>
jmp    11eb <intf_numa_node+0x9b>
lea    -0x120(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intf_numa_node>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rcx
lea    0xe9d(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11ae <intf_numa_node+0x5e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11b5 <intf_numa_node+0x65>
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
jmp    11ba <intf_numa_node+0x6a>
mov    $0xffffffff,%ebp
jmp    11c1 <intf_numa_node+0x71>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/sys/class/net/%s/device/numa_node\00"
@O_RDONLY = global i32 0
define i32 @intf_numa_node(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 -1, i32* %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %31
17: ; preds = %1
%18 = load i32, i32* %4
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 256)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %27
24: ; preds = %17
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @strtol(i8* %25, i32* null, i32 0)
store i32 %26, i32* %5
br label %27
27: ; preds = %24, %23
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %5
store i32 %30, i32* %2
br label %31
31: ; preds = %27, %16
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [35 x i8] c"/sys/class/net/%s/device/numa_node\00"
@O_RDONLY = global i32 0
define i32 @intf_numa_node(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* %3, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = call i32 @read(i32 %6, i8* %3, i32 256)
%10 = icmp slt i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @strtol(i8* nocapture %3, i32* null, i32 0)
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ -1, %8 ], [ %12, %11 ]
%15 = call i32 @close(i32 %6)
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ %14, %13 ], [ -1, %1 ]
ret i32 %17
}