#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 ssize_t;
typedef int /*<<< orphan*/ link;

/* Variables and functions */
int asprintf(char **, char *, char *, char const *);
int /*<<< orphan*/ free(char *);
int readlink(char *, char *, int);
char *strstr(char *, char const *);
bool rport_is_child(const char *rport, const char *ifname) {
  char link[1024];
  ssize_t ret;
  char *path;
  char *offs;
  int err;
  err = asprintf(&path, "%s/%s", "/sys/class/fc_remote_ports", rport);
  if (err == -1)
    return false;
  ret = readlink(path, link, sizeof(link));
  free(path);
  if (ret == -1)
    return false;
  offs = strstr(link, ifname);
  return offs ? true : false;
}


x86 assembly (clang, -O0):
<rport_is_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x430(%rbp),%rdi
lea    0xe9b(%rip),%rsi
lea    0xe9a(%rip),%rdx
call   1050 <asprintf@plt>
mov    %eax,-0x43c(%rbp)
cmpl   $0xffffffff,-0x43c(%rbp)
jne    1190 <rport_is_child+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1202 <rport_is_child+0xc2>
mov    -0x430(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <readlink@plt>
mov    %eax,-0x424(%rbp)
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xffffffff,-0x424(%rbp)
jne    11d3 <rport_is_child+0x93>
movl   $0x0,-0x4(%rbp)
jmp    1202 <rport_is_child+0xc2>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rport_is_child>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
lea    0xea8(%rip),%rsi
lea    0xea7(%rip),%rdx
lea    0x8(%rsp),%rdi
call   1050 <asprintf@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     11ab <rport_is_child+0x6b>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
call   1040 <readlink@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
cmp    $0xffffffff,%ebx
je     11ab <rport_is_child+0x6b>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [27 x i8] c"/sys/class/fc_remote_ports\00"
define i32 @rport_is_child(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @asprintf(i8** %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %33
16: ; preds = %2
%17 = load i8*, i8** %8
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 @readlink(i8* %17, i8* %18, i32 1024)
store i32 %19, i32* %7
%20 = load i8*, i8** %8
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 0, i32* %3
br label %33
25: ; preds = %16
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i8* @strstr(i8* %26, i8* %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = icmp ne i8* %29, null
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 0
store i32 %32, i32* %3
br label %33
33: ; preds = %25, %24, %15
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [27 x i8] c"/sys/class/fc_remote_ports\00"
define i32 @rport_is_child(i8* %0, i8* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @readlink(i8* %10, i8* %5, i32 1024)
%12 = load i8*, i8** %4
%13 = call i32 @free(i8* %12)
%14 = icmp eq i32 %11, -1
br i1 %14, label %19, label %15
15: ; preds = %9
%16 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %1)
%17 = icmp ne i8* %16, null
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %9, %2, %15
%20 = phi i32 [ %18, %15 ], [ 0, %2 ], [ 0, %9 ]
ret i32 %20
}