#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__ asprintf(char **, char *, char const *, ...);
char *fdreadlink(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ ksft_exit_fail_msg(char *, char *, int, char *);
int /*<<< orphan*/ strcmp(char *, char *);
bool fdequal(int fd, int dfd, const char *path) {
  char *fdpath, *dfdpath, *other;
  bool cmp;
  fdpath = fdreadlink(fd);
  dfdpath = fdreadlink(dfd);
  if (!path)
    do {
      if (asprintf(&other, "%s", dfdpath) < 0)
        ksft_exit_fail_msg(
            "%s:%d %s failed\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Broadcom/linux-rdma-nxt/refs/heads/"
            "hwpoison/.backup_do_not_remove/tools/testing/selftests/openat2/"
            "helpers.c",
            80, "asprintf");
    } while (0);
  else if (*path == '/')
    do {
      if (asprintf(&other, "%s", path) < 0)
        ksft_exit_fail_msg(
            "%s:%d %s failed\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Broadcom/linux-rdma-nxt/refs/heads/"
            "hwpoison/.backup_do_not_remove/tools/testing/selftests/openat2/"
            "helpers.c",
            82, "asprintf");
    } while (0);
  else
    do {
      if (asprintf(&other, "%s/%s", dfdpath, path) < 0)
        ksft_exit_fail_msg(
            "%s:%d %s failed\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Broadcom/linux-rdma-nxt/refs/heads/"
            "hwpoison/.backup_do_not_remove/tools/testing/selftests/openat2/"
            "helpers.c",
            84, "asprintf");
    } while (0);
  cmp = !strcmp(fdpath, other);
  free(fdpath);
  free(dfdpath);
  free(other);
  return cmp;
}


x86 assembly (clang, -O0):
<fdequal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <fdreadlink@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <fdreadlink@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d3 <fdequal+0x83>
jmp    118a <fdequal+0x3a>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    0xf4a(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    11c9 <fdequal+0x79>
lea    0xe4f(%rip),%rdi
lea    0xe59(%rip),%rsi
mov    $0x50,%edx
lea    0xf13(%rip),%rcx
call   1040 <ksft_exit_fail_msg@plt>
jmp    11ce <fdequal+0x7e>
jmp    1288 <fdequal+0x138>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1231 <fdequal+0xe1>
jmp    11e8 <fdequal+0x98>
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    0xeec(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    1227 <fdequal+0xd7>
lea    0xdf1(%rip),%rdi
lea    0xdfb(%rip),%rsi
mov    $0x52,%edx
lea    0xeb5(%rip),%rcx
call   1040 <ksft_exit_fail_msg@plt>
jmp    122c <fdequal+0xdc>
jmp    1283 <fdequal+0x133>
jmp    1236 <fdequal+0xe6>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    1279 <fdequal+0x129>
lea    0xd9f(%rip),%rdi
lea    0xda9(%rip),%rsi
mov    $0x54,%edx
lea    0xe63(%rip),%rcx
call   1040 <ksft_exit_fail_msg@plt>
jmp    127e <fdequal+0x12e>
jmp    1283 <fdequal+0x133>
jmp    1288 <fdequal+0x138>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdequal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
call   1060 <fdreadlink@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1060 <fdreadlink@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1198 <fdequal+0x48>
cmpb   $0x2f,(%rbx)
jne    11b8 <fdequal+0x68>
lea    0xf64(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <asprintf@plt>
test   %rax,%rax
jns    11f3 <fdequal+0xa3>
mov    $0x52,%edx
jmp    11d9 <fdequal+0x89>
lea    0xf44(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <asprintf@plt>
test   %rax,%rax
jns    11f3 <fdequal+0xa3>
mov    $0x50,%edx
jmp    11d9 <fdequal+0x89>
lea    0xf21(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <asprintf@plt>
test   %rax,%rax
jns    11f3 <fdequal+0xa3>
mov    $0x54,%edx
lea    0xe20(%rip),%rdi
lea    0xe2a(%rip),%rsi
lea    0xee9(%rip),%rcx
call   1040 <ksft_exit_fail_msg@plt>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"%s:%d %s failed\0A\00"
@.str.2 = [198 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Broadcom/linux-rdma-nxt/refs/heads/hwpoison/.backup_do_not_remove/tools/testing/selftests/openat2/helpers.c\00"
@.str.3 = [9 x i8] c"asprintf\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @fdequal(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i32, i32* %4
%12 = call i8* @fdreadlink(i32 %11)
store i8* %12, i8** %7
%13 = load i32, i32* %5
%14 = call i8* @fdreadlink(i32 %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %26, label %17
17: ; preds = %3
br label %18
18: ; preds = %17
%19 = load i8*, i8** %8
%20 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([198 x i8], [198 x i8]* @.str.2, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24
br label %51
26: ; preds = %3
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 47
br i1 %30, label %31, label %40
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = load i8*, i8** %6
%34 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([198 x i8], [198 x i8]* @.str.2, i64 0, i64 0), i32 82, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
br label %39
39: ; preds = %38
br label %50
40: ; preds = %26
br label %41
41: ; preds = %40
%42 = load i8*, i8** %8
%43 = load i8*, i8** %6
%44 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([198 x i8], [198 x i8]* @.str.2, i64 0, i64 0), i32 84, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49, %39
br label %51
51: ; preds = %50, %25
%52 = load i8*, i8** %7
%53 = load i8*, i8** %9
%54 = call i32 @strcmp(i8* %52, i8* %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
%57 = zext i1 %56 to i32
store i32 %57, i32* %10
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
%60 = load i8*, i8** %8
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %9
%63 = call i32 @free(i8* %62)
%64 = load i32, i32* %10
ret i32 %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [17 x i8] c"%s:%d %s failed\0A\00"
@.str.2 = [198 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Broadcom/linux-rdma-nxt/refs/heads/hwpoison/.backup_do_not_remove/tools/testing/selftests/openat2/helpers.c\00"
@.str.3 = [9 x i8] c"asprintf\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @fdequal(i32 %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @fdreadlink(i32 %0)
%7 = tail call i8* @fdreadlink(i32 %1)
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%11 = icmp slt i64 %10, 0
br i1 %11, label %21, label %24
12: ; preds = %3
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 47
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%17 = icmp slt i64 %16, 0
br i1 %17, label %21, label %24
18: ; preds = %12
%19 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %7, i8* %2)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18, %15, %9
%22 = phi i32 [ 80, %9 ], [ 82, %15 ], [ 84, %18 ]
%23 = call i32 @ksft_exit_fail_msg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([198 x i8], [198 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %21, %15, %18, %9
%25 = load i8*, i8** %4
%26 = call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(1) %25)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @free(i8* %6)
%30 = call i32 @free(i8* %7)
%31 = load i8*, i8** %4
%32 = call i32 @free(i8* %31)
ret i32 %28
}