#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*/ full_path;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ debugfs_make_path(char *, char *, char *, int);
char *debugfs_mount(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int batadv_interface_check(char *mesh_iface) {
  char *debugfs_mnt;
  char full_path[256 + 1];
  FILE *f;
  debugfs_mnt = debugfs_mount(NULL);
  if (!debugfs_mnt) {
    fprintf(stderr, "Could not find debugfs path\n");
    return -1;
  }
  debugfs_make_path("%s/batman_adv/%s"
                    "/"
                    "transtable_global",
                    mesh_iface, full_path, sizeof(full_path));
  f = fopen(full_path, "r");
  if (!f) {
    fprintf(stderr,
            "Could not find %s for interface %s. Make sure it is a valid "
            "batman-adv soft-interface\n",
            "transtable_global", mesh_iface);
    return -1;
  }
  fclose(f);
  debugfs_make_path("%s/batman_adv/%s"
                    "/"
                    "originators",
                    mesh_iface, full_path, sizeof(full_path));
  f = fopen(full_path, "r");
  if (!f) {
    fprintf(stderr,
            "Could not find %s for interface %s. Make sure it is a valid "
            "batman-adv soft-interface\n",
            "originators", mesh_iface);
    return -1;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<batadv_interface_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <debugfs_mount@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <batadv_interface_check+0x4a>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129d <batadv_interface_check+0x14d>
mov    -0x10(%rbp),%rsi
lea    -0x120(%rbp),%rdx
lea    0xe71(%rip),%rdi
mov    $0x101,%ecx
call   1040 <debugfs_make_path@plt>
lea    -0x120(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    120c <batadv_interface_check+0xbc>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe50(%rip),%rsi
lea    0xe35(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129d <batadv_interface_check+0x14d>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    -0x120(%rbp),%rdx
lea    0xe6f(%rip),%rdi
mov    $0x101,%ecx
call   1040 <debugfs_make_path@plt>
lea    -0x120(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    128a <batadv_interface_check+0x13a>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xdd2(%rip),%rsi
lea    0xe33(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129d <batadv_interface_check+0x14d>
mov    -0x128(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<batadv_interface_check>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
xor    %edi,%edi
call   1070 <debugfs_mount@plt>
test   %rax,%rax
je     11d9 <batadv_interface_check+0x89>
lea    0xead(%rip),%rdi
mov    %rsp,%rbx
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x101,%ecx
call   1040 <debugfs_make_path@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f2 <batadv_interface_check+0xa2>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xef3(%rip),%rdi
mov    %rsp,%rbx
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x101,%ecx
call   1040 <debugfs_make_path@plt>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     120b <batadv_interface_check+0xbb>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1231 <batadv_interface_check+0xe1>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    122c <batadv_interface_check+0xdc>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
lea    0xe25(%rip),%rdx
jmp    1222 <batadv_interface_check+0xd2>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
lea    0xe88(%rip),%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Could not find debugfs path\0A\00"
@.str.1 = [35 x i8] c"%s/batman_adv/%s/transtable_global\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [87 x i8] c"Could not find %s for interface %s. Make sure it is a valid batman-adv soft-interface\0A\00"
@.str.4 = [18 x i8] c"transtable_global\00"
@.str.5 = [29 x i8] c"%s/batman_adv/%s/originators\00"
@.str.6 = [12 x i8] c"originators\00"
define i32 @batadv_interface_check(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [257 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
%7 = call i8* @debugfs_mount(i32* null)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %42
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%16 = call i32 @debugfs_make_path(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15, i32 257)
%17 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %23)
store i32 -1, i32* %2
br label %42
25: ; preds = %13
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %3
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%30 = call i32 @debugfs_make_path(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %28, i8* %29, i32 257)
%31 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = icmp ne i32* %33, null
br i1 %34, label %39, label %35
35: ; preds = %25
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %3
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %37)
store i32 -1, i32* %2
br label %42
39: ; preds = %25
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %2
br label %42
42: ; preds = %39, %35, %21, %10
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Could not find debugfs path\0A\00"
@.str.1 = [35 x i8] c"%s/batman_adv/%s/transtable_global\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [87 x i8] c"Could not find %s for interface %s. Make sure it is a valid batman-adv soft-interface\0A\00"
@.str.4 = [18 x i8] c"transtable_global\00"
@.str.5 = [29 x i8] c"%s/batman_adv/%s/originators\00"
@.str.6 = [12 x i8] c"originators\00"
define i32 @batadv_interface_check(i8* %0) {
%2 = alloca [257 x i8]
%3 = getelementptr inbounds [257 x i8], [257 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @debugfs_mount(i32* null)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %26
9: ; preds = %1
%10 = call i32 @debugfs_make_path(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %3, i32 257)
%11 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %26
16: ; preds = %9
%17 = call i32 @fclose(i32* %11)
%18 = call i32 @debugfs_make_path(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %3, i32 257)
%19 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %26
24: ; preds = %16
%25 = call i32 @fclose(i32* %19)
br label %26
26: ; preds = %24, %21, %13, %6
%27 = phi i32 [ 0, %24 ], [ -1, %21 ], [ -1, %13 ], [ -1, %6 ]
ret i32 %27
}