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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ is_xref_needed(char *, char **, int);
int /*<<< orphan*/ my_fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ my_isblank(char);
char *sskip(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
char *strrchr(char *, char);
int ida_xrefs_show_need(FILE *fasm, char *p, char **rlist, int rlist_len) {
  int found_need = 0;
  char line[256];
  long pos;
  p = strrchr(p, ';');
  if (p != NULL && *p == ';') {
    if (!strncmp(p + 2, "sctref", strlen("sctref")))
      return 1;
    if (!strncmp(p + 2, "DATA XREF: ", strlen("DATA XREF: "))) {
      p += 13;
      if (is_xref_needed(p, rlist, rlist_len))
        return 1;
    }
  }
  pos = ftell(fasm);
  while (1) {
    if (!my_fgets(line, sizeof(line), fasm))
      break;
    if (!my_isblank(line[0]))
      break;
    p = sskip(line);
    if (*p != ';')
      break;
    p = strrchr(p, ';');
    p += 2;
    if (!strncmp(p, "sctref", strlen("sctref"))) {
      found_need = 1;
      break;
    }
    if (!strncmp(p, "DATA XREF: ", strlen("DATA XREF: ")))
      p += 11;
    if (is_xref_needed(p, rlist, rlist_len)) {
      found_need = 1;
      break;
    }
  }
  fseek(fasm, pos, SEEK_SET);
  return found_need;
}


x86 assembly (clang, -O0):
<ida_xrefs_show_need>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1298 <ida_xrefs_show_need+0x108>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    1298 <ida_xrefs_show_need+0x108>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x140(%rbp)
lea    0xe0c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    %eax,%edx
lea    0xdf7(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1223 <ida_xrefs_show_need+0x93>
movl   $0x1,-0x4(%rbp)
jmp    13f4 <ida_xrefs_show_need+0x264>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x148(%rbp)
lea    0xdce(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    %eax,%edx
lea    0xdb9(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1293 <ida_xrefs_show_need+0x103>
mov    -0x18(%rbp),%rax
add    $0xd,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <is_xref_needed@plt>
cmp    $0x0,%rax
je     128e <ida_xrefs_show_need+0xfe>
movl   $0x1,-0x4(%rbp)
jmp    13f4 <ida_xrefs_show_need+0x264>
jmp    1293 <ida_xrefs_show_need+0x103>
jmp    1298 <ida_xrefs_show_need+0x108>
mov    -0x10(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1070 <my_fgets@plt>
cmp    $0x0,%eax
jne    12cb <ida_xrefs_show_need+0x13b>
jmp    13d5 <ida_xrefs_show_need+0x245>
movsbl -0x130(%rbp),%edi
call   1060 <my_isblank@plt>
cmp    $0x0,%eax
jne    12e5 <ida_xrefs_show_need+0x155>
jmp    13d5 <ida_xrefs_show_need+0x245>
lea    -0x130(%rbp),%rdi
call   10a0 <sskip@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
je     130a <ida_xrefs_show_need+0x17a>
jmp    13d5 <ida_xrefs_show_need+0x245>
mov    -0x18(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    0xcc6(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    %eax,%edx
lea    0xcb1(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1369 <ida_xrefs_show_need+0x1d9>
movl   $0x1,-0x28(%rbp)
jmp    13d5 <ida_xrefs_show_need+0x245>
mov    -0x18(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    0xc8c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x158(%rbp),%rdi
mov    %eax,%edx
lea    0xc77(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13aa <ida_xrefs_show_need+0x21a>
mov    -0x18(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <is_xref_needed@plt>
cmp    $0x0,%rax
je     13d0 <ida_xrefs_show_need+0x240>
movl   $0x1,-0x28(%rbp)
jmp    13d5 <ida_xrefs_show_need+0x245>
jmp    12a8 <ida_xrefs_show_need+0x118>
mov    -0x10(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    0x2bf9(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ida_xrefs_show_need>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %ecx,0x4(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rdi,0x8(%rsp)
mov    %rsi,%rdi
mov    $0x3b,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1234 <ida_xrefs_show_need+0xa4>
mov    %rax,%rbx
cmpb   $0x3b,(%rax)
jne    1234 <ida_xrefs_show_need+0xa4>
lea    0x2(%rbx),%r14
lea    0xe2c(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     131a <ida_xrefs_show_need+0x18a>
lea    0xe0a(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1234 <ida_xrefs_show_need+0xa4>
add    $0xd,%rbx
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
call   1080 <is_xref_needed@plt>
test   %rax,%rax
jne    131a <ida_xrefs_show_need+0x18a>
mov    0x8(%rsp),%rdi
call   1090 <ftell@plt>
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rbx
lea    0xdb1(%rip),%r12
lea    0xdb1(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    0x8(%rsp),%rdx
call   1070 <my_fgets@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1302 <ida_xrefs_show_need+0x172>
movsbl 0x20(%rsp),%edi
call   1060 <my_isblank@plt>
test   %eax,%eax
je     1302 <ida_xrefs_show_need+0x172>
mov    %rbx,%rdi
call   10a0 <sskip@plt>
cmpb   $0x3b,(%rax)
jne    1302 <ida_xrefs_show_need+0x172>
mov    %rax,%rdi
mov    $0x3b,%esi
call   1050 <strrchr@plt>
mov    %rax,%r15
lea    0x2(%rax),%r13
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     1302 <ida_xrefs_show_need+0x172>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
add    $0xd,%r15
test   %eax,%eax
cmovne %r13,%r15
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
mov    0x4(%rsp),%edx
call   1080 <is_xref_needed@plt>
test   %rax,%rax
je     1260 <ida_xrefs_show_need+0xd0>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edx
mov    0x8(%rsp),%rdi
mov    0x18(%rsp),%rsi
call   10b0 <fseek@plt>
mov    %ebp,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"sctref\00"
@.str.1 = [12 x i8] c"DATA XREF: \00"
@SEEK_SET = global i32 0
define i32 @ida_xrefs_show_need(i32* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
store i32 0, i32* %10
%13 = load i8*, i8** %7
%14 = call i8* @strrchr(i8* %13, i8 signext 59)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %46
17: ; preds = %4
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 59
br i1 %21, label %22, label %46
22: ; preds = %17
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @strncmp(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 1, i32* %5
br label %101
29: ; preds = %22
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @strncmp(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %29
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 13
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = load i8**, i8*** %8
%40 = load i32, i32* %9
%41 = call i64 @is_xref_needed(i8* %38, i8** %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %35
store i32 1, i32* %5
br label %101
44: ; preds = %35
br label %45
45: ; preds = %44, %29
br label %46
46: ; preds = %45, %17, %4
%47 = load i32*, i32** %6
%48 = call i64 @ftell(i32* %47)
store i64 %48, i64* %12
br label %49
49: ; preds = %46, %94
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%51 = load i32*, i32** %6
%52 = call i32 @my_fgets(i8* %50, i32 256, i32* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %49
br label %95
55: ; preds = %49
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%57 = load i8, i8* %56
%58 = call i32 @my_isblank(i8 signext %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %55
br label %95
61: ; preds = %55
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%63 = call i8* @sskip(i8* %62)
store i8* %63, i8** %7
%64 = load i8*, i8** %7
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 59
br i1 %67, label %68, label %69
68: ; preds = %61
br label %95
69: ; preds = %61
%70 = load i8*, i8** %7
%71 = call i8* @strrchr(i8* %70, i8 signext 59)
store i8* %71, i8** %7
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i64 2
store i8* %73, i8** %7
%74 = load i8*, i8** %7
%75 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%76 = call i32 @strncmp(i8* %74, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %79, label %78
78: ; preds = %69
store i32 1, i32* %10
br label %95
79: ; preds = %69
%80 = load i8*, i8** %7
%81 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%82 = call i32 @strncmp(i8* %80, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %81)
%83 = icmp ne i32 %82, 0
br i1 %83, label %87, label %84
84: ; preds = %79
%85 = load i8*, i8** %7
%86 = getelementptr inbounds i8, i8* %85, i64 11
store i8* %86, i8** %7
br label %87
87: ; preds = %84, %79
%88 = load i8*, i8** %7
%89 = load i8**, i8*** %8
%90 = load i32, i32* %9
%91 = call i64 @is_xref_needed(i8* %88, i8** %89, i32 %90)
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %87
store i32 1, i32* %10
br label %95
94: ; preds = %87
br label %49
95: ; preds = %93, %78, %68, %60, %54
%96 = load i32*, i32** %6
%97 = load i64, i64* %12
%98 = load i32, i32* @SEEK_SET
%99 = call i32 @fseek(i32* %96, i64 %97, i32 %98)
%100 = load i32, i32* %10
store i32 %100, i32* %5
br label %101
101: ; preds = %95, %43, %28
%102 = load i32, i32* %5
ret i32 %102
}

LLVM IR (-O2):
@.str = [7 x i8] c"sctref\00"
@.str.1 = [12 x i8] c"DATA XREF: \00"
@SEEK_SET = global i32 0
define i32 @ida_xrefs_show_need(i32* %0, i8* %1, i8** %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 59)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %4
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 59
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %7, i64 2
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %56, label %17
17: ; preds = %12
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = getelementptr inbounds i8, i8* %7, i64 13
%23 = tail call i64 @is_xref_needed(i8* %22, i8** %2, i32 %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %56
25: ; preds = %17, %21, %9, %4
%26 = tail call i64 @ftell(i32* %0)
br label %27
27: ; preds = %44, %25
%28 = call i32 @my_fgets(i8* %6, i32 256, i32* %0)
%29 = icmp eq i32 %28, 0
br i1 %29, label %52, label %30
30: ; preds = %27
%31 = load i8, i8* %6
%32 = call i32 @my_isblank(i8 signext %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %52, label %34
34: ; preds = %30
%35 = call i8* @sskip(i8* %6)
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 59
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = call i8* @strrchr(i8* %35, i8 signext 59)
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @strncmp(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %52, label %44
44: ; preds = %38
%45 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @strncmp(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = icmp eq i32 %46, 0
%48 = getelementptr inbounds i8, i8* %39, i64 13
%49 = select i1 %47, i8* %48, i8* %40
%50 = call i64 @is_xref_needed(i8* %49, i8** %2, i32 %3)
%51 = icmp eq i64 %50, 0
br i1 %51, label %27, label %52
52: ; preds = %44, %38, %34, %30, %27
%53 = phi i32 [ 0, %34 ], [ 0, %30 ], [ 0, %27 ], [ 1, %38 ], [ 1, %44 ]
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @fseek(i32* %0, i64 %26, i32 %54)
br label %56
56: ; preds = %21, %12, %52
%57 = phi i32 [ %53, %52 ], [ 1, %12 ], [ 1, %21 ]
ret i32 %57
}