#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char find_intf(char *filePath, char *net_intf) {
  strcpy(filePath, "/sys/class/net/");
  strcat(filePath, net_intf);
  struct stat link_attributes;
  if ((lstat(filePath, &link_attributes)) != 0) {
    if (errno == ENOENT) {
      fprintf(stderr, "Error_lstat:No such network interface\n");
      return (-1);
    } else {
      perror("Error_lstat: ");
      return (-1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_intf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     11e1 <find_intf+0x91>
mov    0x2e3d(%rip),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11cc <find_intf+0x7c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
movb   $0xff,-0x1(%rbp)
jmp    11e5 <find_intf+0x95>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
movb   $0xff,-0x1(%rbp)
jmp    11e5 <find_intf+0x95>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_intf>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <lstat@plt>
test   %rax,%rax
je     11b0 <find_intf+0x60>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <find_intf+0x6a>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xff,%al
jmp    11b2 <find_intf+0x62>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
jmp    11ac <find_intf+0x5c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/sys/class/net/\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"Error_lstat:No such network interface\0A\00"
@.str.2 = [14 x i8] c"Error_lstat: \00"
define signext i8 @find_intf(i8* %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @strcat(i8* %9, i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @lstat(i8* %12, %struct.stat* %6)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i8 -1, i8* %3
br label %25
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i8 -1, i8* %3
br label %25
24: ; preds = %2
store i8 0, i8* %3
br label %25
25: ; preds = %24, %22, %19
%26 = load i8, i8* %3
ret i8 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"/sys/class/net/\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [39 x i8] c"Error_lstat:No such network interface\0A\00"
@.str.2 = [14 x i8] c"Error_lstat: \00"
define signext i8 @find_intf(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strcat(i8* %0, i8* %1)
%6 = bitcast %struct.stat* %3 to i8*
%7 = call i64 @lstat(i8* %0, %struct.stat* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = load i64, i64* @errno
%11 = load i64, i64* @ENOENT
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %9
%17 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %2, %16, %13
%19 = phi i8 [ -1, %13 ], [ -1, %16 ], [ 0, %2 ]
ret i8 %19
}