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

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int snprintf(char *, int, char *, char const *);
int isbatman(const char *ifname, int ifindex) {
  char buf[256];
  int rc;
  rc = snprintf(buf, 256, "/sys/devices/virtual/net/%s/mesh", ifname);
  if (rc < 0 || rc >= 256)
    return -1;
  if (access(buf, F_OK) >= 0)
    return 1;
  if (errno != ENOENT)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<isbatman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xeb7(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jl     1171 <isbatman+0x51>
cmpl   $0x100,-0x124(%rbp)
jl     117d <isbatman+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <isbatman+0xb5>
lea    -0x120(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jl     11a8 <isbatman+0x88>
movl   $0x1,-0x4(%rbp)
jmp    11d5 <isbatman+0xb5>
mov    0x2e31(%rip),%rax
mov    (%rax),%rax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <isbatman+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <isbatman+0xb5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isbatman>:
sub    $0x108,%rsp
mov    %rdi,%rcx
lea    0xecf(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xff,%ecx
ja     116b <isbatman+0x4b>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <access@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
js     1173 <isbatman+0x53>
add    $0x108,%rsp
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%rcx
mov    0x2e4c(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
setne  %al
neg    %eax
add    $0x108,%rsp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"/sys/devices/virtual/net/%s/mesh\00"
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @isbatman(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 256
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 -1, i32* %3
br label %29
17: ; preds = %13
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @F_OK
%20 = call i64 @access(i8* %18, i32 %19)
%21 = icmp sge i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %3
br label %29
23: ; preds = %17
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %3
br label %29
28: ; preds = %23
store i32 0, i32* %3
br label %29
29: ; preds = %28, %27, %22, %16
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [33 x i8] c"/sys/devices/virtual/net/%s/mesh\00"
@F_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
define i32 @isbatman(i8* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp ugt i32 %5, 255
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = load i32, i32* @F_OK
%9 = call i64 @access(i8* %4, i32 %8)
%10 = icmp sgt i64 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOENT
%14 = icmp ne i64 %12, %13
%15 = sext i1 %14 to i32
br label %16
16: ; preds = %11, %7, %2
%17 = phi i32 [ -1, %2 ], [ 1, %7 ], [ %15, %11 ]
ret i32 %17
}