#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 symfile {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct symfile *add_new_file(char *);
int /*<<< orphan*/ add_new_symbol(struct symfile *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *filename_exist(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isalnum(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
void find_export_symbols(char *filename) {
  FILE *fp;
  struct symfile *sym;
  char line[2048];
  if (filename_exist(filename) == NULL) {
    sym = add_new_file(filename);
    fp = fopen(filename, "r");
    if (fp == NULL) {
      fprintf(stderr, "docproc: ");
      perror(filename);
    }
    while (fgets(line, 2048, fp)) {
      char *p;
      char *e;
      if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != 0) ||
          ((p = strstr(line, "EXPORT_SYMBOL")) != 0)) {
        while (isalnum(*p) || *p == '_')
          p++;
        while (isspace(*p))
          p++;
        if (*p != '(')
          continue;
        else
          p++;
        while (isspace(*p))
          p++;
        e = p;
        while (isalnum(*e) || *e == '_')
          e++;
        *e = '\0';
        add_new_symbol(sym, p);
      }
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<find_export_symbols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <filename_exist@plt>
cmp    $0x0,%rax
jne    141f <find_export_symbols+0x26f>
mov    -0x8(%rbp),%rdi
call   1060 <add_new_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121c <find_export_symbols+0x6c>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
jmp    1221 <find_export_symbols+0x71>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1416 <find_export_symbols+0x266>
lea    -0x820(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
jne    1288 <find_export_symbols+0xd8>
lea    -0x820(%rbp),%rdi
lea    0xdac(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
je     1411 <find_export_symbols+0x261>
jmp    128d <find_export_symbols+0xdd>
mov    -0x828(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x831(%rbp)
jne    12c7 <find_export_symbols+0x117>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x831(%rbp)
mov    -0x831(%rbp),%al
test   $0x1,%al
jne    12da <find_export_symbols+0x12a>
jmp    12f1 <find_export_symbols+0x141>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
jmp    128d <find_export_symbols+0xdd>
jmp    12f6 <find_export_symbols+0x146>
mov    -0x828(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1326 <find_export_symbols+0x176>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
jmp    12f6 <find_export_symbols+0x146>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x28,%eax
je     133e <find_export_symbols+0x18e>
jmp    1221 <find_export_symbols+0x71>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
jmp    1355 <find_export_symbols+0x1a5>
mov    -0x828(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1385 <find_export_symbols+0x1d5>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
jmp    1355 <find_export_symbols+0x1a5>
mov    -0x828(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x832(%rbp)
jne    13cd <find_export_symbols+0x21d>
mov    -0x830(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x832(%rbp)
mov    -0x832(%rbp),%al
test   $0x1,%al
jne    13e0 <find_export_symbols+0x230>
jmp    13f7 <find_export_symbols+0x247>
mov    -0x830(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x830(%rbp)
jmp    1393 <find_export_symbols+0x1e3>
mov    -0x830(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x828(%rbp),%rsi
call   10c0 <add_new_symbol@plt>
jmp    1221 <find_export_symbols+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_export_symbols>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%rbx
call   1090 <filename_exist@plt>
test   %rax,%rax
jne    1317 <find_export_symbols+0x167>
mov    %rbx,%rdi
call   1060 <add_new_file@plt>
mov    %rax,%r14
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     1329 <find_export_symbols+0x179>
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     130f <find_export_symbols+0x15f>
lea    0xdf4(%rip),%r15
mov    %rsp,%rbx
jmp    1239 <find_export_symbols+0x89>
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     130f <find_export_symbols+0x15f>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1274 <find_export_symbols+0xc4>
mov    %rbx,%rdi
lea    0xdc8(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1274 <find_export_symbols+0xc4>
jmp    1220 <find_export_symbols+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
movsbl 0x0(%rbp),%edi
call   1040 <isalnum@plt>
test   %rax,%rax
jne    1270 <find_export_symbols+0xc0>
movzbl 0x0(%rbp),%eax
cmp    $0x5f,%al
je     1270 <find_export_symbols+0xc0>
movsbl %al,%edi
nopl   (%rax)
call   1050 <isspace@plt>
test   %rax,%rax
je     12b0 <find_export_symbols+0x100>
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
jmp    1290 <find_export_symbols+0xe0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x28,0x0(%rbp)
jne    1220 <find_export_symbols+0x70>
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1050 <isspace@plt>
test   %rax,%rax
jne    12c0 <find_export_symbols+0x110>
mov    %rbp,%r13
jmp    12e4 <find_export_symbols+0x134>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r13
movsbl 0x0(%r13),%edi
call   1040 <isalnum@plt>
test   %rax,%rax
jne    12e0 <find_export_symbols+0x130>
cmpb   $0x5f,0x0(%r13)
je     12e0 <find_export_symbols+0x130>
movb   $0x0,0x0(%r13)
mov    %r14,%rdi
mov    %rbp,%rsi
call   10c0 <add_new_symbol@plt>
jmp    1220 <find_export_symbols+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
lea    0xcc9(%rip),%rsi
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <perror@plt>
jmp    11f8 <find_export_symbols+0x48>

LLVM IR (-O0):
%struct.symfile = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"docproc: \00"
@.str.2 = [18 x i8] c"EXPORT_SYMBOL_GPL\00"
@.str.3 = [14 x i8] c"EXPORT_SYMBOL\00"
define void @find_export_symbols(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.symfile*
%5 = alloca [2048 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @filename_exist(i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %106
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call %struct.symfile* @add_new_file(i8* %12)
store %struct.symfile* %13, %struct.symfile** %4
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %2
%22 = call i32 @perror(i8* %21)
br label %23
23: ; preds = %18, %11
br label %24
24: ; preds = %102, %67, %23
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%26 = load i32*, i32** %3
%27 = call i64 @fgets(i8* %25, i32 2048, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %103
29: ; preds = %24
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%31 = call i8* @strstr(i8* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i8* %31, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%35 = call i8* @strstr(i8* %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i8* %35, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %102
37: ; preds = %33, %29
br label %38
38: ; preds = %50, %37
%39 = load i8*, i8** %6
%40 = load i8, i8* %39
%41 = call i64 @isalnum(i8 signext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 95
br label %48
48: ; preds = %43, %38
%49 = phi i1 [ true, %38 ], [ %47, %43 ]
br i1 %49, label %50, label %53
50: ; preds = %48
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
br label %38
53: ; preds = %48
br label %54
54: ; preds = %59, %53
%55 = load i8*, i8** %6
%56 = load i8, i8* %55
%57 = call i64 @isspace(i8 signext %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %6
br label %54
62: ; preds = %54
%63 = load i8*, i8** %6
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 40
br i1 %66, label %67, label %68
67: ; preds = %62
br label %24
68: ; preds = %62
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %6
br label %71
71: ; preds = %68
br label %72
72: ; preds = %77, %71
%73 = load i8*, i8** %6
%74 = load i8, i8* %73
%75 = call i64 @isspace(i8 signext %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i8*, i8** %6
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %6
br label %72
80: ; preds = %72
%81 = load i8*, i8** %6
store i8* %81, i8** %7
br label %82
82: ; preds = %94, %80
%83 = load i8*, i8** %7
%84 = load i8, i8* %83
%85 = call i64 @isalnum(i8 signext %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %92, label %87
87: ; preds = %82
%88 = load i8*, i8** %7
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 95
br label %92
92: ; preds = %87, %82
%93 = phi i1 [ true, %82 ], [ %91, %87 ]
br i1 %93, label %94, label %97
94: ; preds = %92
%95 = load i8*, i8** %7
%96 = getelementptr inbounds i8, i8* %95, i32 1
store i8* %96, i8** %7
br label %82
97: ; preds = %92
%98 = load i8*, i8** %7
store i8 0, i8* %98
%99 = load %struct.symfile*, %struct.symfile** %4
%100 = load i8*, i8** %6
%101 = call i32 @add_new_symbol(%struct.symfile* %99, i8* %100)
br label %102
102: ; preds = %97, %33
br label %24
103: ; preds = %24
%104 = load i32*, i32** %3
%105 = call i32 @fclose(i32* %104)
br label %106
106: ; preds = %103, %1
ret void
}

LLVM IR (-O2):
%struct.symfile = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"docproc: \00"
@.str.2 = [18 x i8] c"EXPORT_SYMBOL_GPL\00"
@.str.3 = [14 x i8] c"EXPORT_SYMBOL\00"
define void @find_export_symbols(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @filename_exist(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %71
6: ; preds = %1
%7 = tail call %struct.symfile* @add_new_file(i8* %0)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @perror(i8* %0)
br label %14
14: ; preds = %10, %6
%15 = call i64 @fgets(i8* %3, i32 2048, i32* %8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %69, label %17
17: ; preds = %14, %66
%18 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %66, label %23
23: ; preds = %20, %17
%24 = phi i8* [ %21, %20 ], [ %18, %17 ]
br label %25
25: ; preds = %23, %36
%26 = phi i8* [ %37, %36 ], [ %24, %23 ]
%27 = load i8, i8* %26
%28 = call i64 @isalnum(i8 signext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i8, i8* %26
%32 = icmp eq i8 %31, 95
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i64 @isspace(i8 signext %31)
%35 = icmp eq i64 %34, 0
br i1 %35, label %44, label %38
36: ; preds = %25, %30
%37 = getelementptr inbounds i8, i8* %26, i64 1
br label %25
38: ; preds = %33, %38
%39 = phi i8* [ %40, %38 ], [ %26, %33 ]
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = call i64 @isspace(i8 signext %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %38
44: ; preds = %38, %33
%45 = phi i8* [ %26, %33 ], [ %40, %38 ]
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 40
br i1 %47, label %48, label %66
48: ; preds = %44, %48
%49 = phi i8* [ %50, %48 ], [ %45, %44 ]
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = call i64 @isspace(i8 signext %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %48
54: ; preds = %48, %62
%55 = phi i8* [ %63, %62 ], [ %50, %48 ]
%56 = load i8, i8* %55
%57 = call i64 @isalnum(i8 signext %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8, i8* %55
%61 = icmp eq i8 %60, 95
br i1 %61, label %62, label %64
62: ; preds = %54, %59
%63 = getelementptr inbounds i8, i8* %55, i64 1
br label %54
64: ; preds = %59
store i8 0, i8* %55
%65 = call i32 @add_new_symbol(%struct.symfile* %7, i8* %50)
br label %66
66: ; preds = %20, %64, %44
%67 = call i64 @fgets(i8* %3, i32 2048, i32* %8)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %17
69: ; preds = %66, %14
%70 = call i32 @fclose(i32* %8)
br label %71
71: ; preds = %69, %1
ret void
}