unsigned long *find_kernel_symbol_tab(void) {
  unsigned long *p;
  unsigned long *addr;
  unsigned num = 0;
  unsigned i = 0;
  unsigned val1, val2;
  p = 0xc0008000UL;
  while (p < 0xc0000000UL + 1024 * 1024 * 16) {
    addr = p;
    i = 0;
    if (k_read(addr, 4) >= 0xc0008000UL) {
      while (i < 10000UL) {
        if ((val1 = k_read(addr + 1, 4)) >= 0xc0008000UL &&
            val1 >= k_read(addr, 4)) {
          addr++;
          i++;
          continue;
        }
        break;
      }
      if (i == 10000UL)
        return p;
    }
    p += i + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<find_kernel_symbol_tab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0xc0008000,%eax
mov    %rax,-0x10(%rbp)
mov    $0xc1000000,%eax
cmp    %rax,-0x10(%rbp)
jae    1227 <find_kernel_symbol_tab+0x117>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1030 <k_read@plt>
cltq
mov    $0xc0008000,%ecx
cmp    %rcx,%rax
jb     120b <find_kernel_symbol_tab+0xfb>
jmp    1172 <find_kernel_symbol_tab+0x62>
mov    -0x20(%rbp),%eax
cmp    $0x2710,%rax
jae    11ea <find_kernel_symbol_tab+0xda>
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1030 <k_read@plt>
mov    %eax,-0x24(%rbp)
mov    %eax,%eax
mov    $0xc0008000,%ecx
cmp    %rcx,%rax
jb     11e5 <find_kernel_symbol_tab+0xd5>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1030 <k_read@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jb     11e5 <find_kernel_symbol_tab+0xd5>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1172 <find_kernel_symbol_tab+0x62>
jmp    11ea <find_kernel_symbol_tab+0xda>
mov    -0x20(%rbp),%eax
cmp    $0x2710,%rax
jne    1206 <find_kernel_symbol_tab+0xf6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122f <find_kernel_symbol_tab+0x11f>
jmp    120b <find_kernel_symbol_tab+0xfb>
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    112f <find_kernel_symbol_tab+0x1f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_kernel_symbol_tab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xc0008000,%r14d
lea    0xff8000(%r14),%r12
jmp    1140 <find_kernel_symbol_tab+0x30>
nopw   0x0(%rax,%rax,1)
mov    %r13d,%eax
lea    (%r14,%rax,8),%r14
add    $0x8,%r14
cmp    %r12,%r14
jae    11b1 <find_kernel_symbol_tab+0xa1>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <k_read@plt>
mov    $0x0,%r13d
test   %eax,%eax
jns    1130 <find_kernel_symbol_tab+0x20>
xor    %r13d,%r13d
mov    %r14,%rbx
nop
lea    0x8(%rbx),%r15
mov    %r15,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <k_read@plt>
cmp    $0xc0008000,%eax
jb     1130 <find_kernel_symbol_tab+0x20>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <k_read@plt>
cmp    %eax,%ebp
jb     1130 <find_kernel_symbol_tab+0x20>
add    $0x1,%r13d
mov    %r15,%rbx
cmp    $0x2710,%r13d
jne    1160 <find_kernel_symbol_tab+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
jmp    119f <find_kernel_symbol_tab+0x8f>

LLVM IR (-O0):
define i64* @find_kernel_symbol_tab() {
%1 = alloca i64*
%2 = alloca i64*
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
store i64* inttoptr (i64 3221258240 to i64*), i64** %2
br label %8
8: ; preds = %46, %0
%9 = load i64*, i64** %2
%10 = icmp ult i64* %9, inttoptr (i64 3238002688 to i64*)
br i1 %10, label %11, label %52
11: ; preds = %8
%12 = load i64*, i64** %2
store i64* %12, i64** %3
store i32 0, i32* %5
%13 = load i64*, i64** %3
%14 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %13, i32 4)
%15 = sext i32 %14 to i64
%16 = icmp uge i64 %15, 3221258240
br i1 %16, label %17, label %46
17: ; preds = %11
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %5
%20 = zext i32 %19 to i64
%21 = icmp ult i64 %20, 10000
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load i64*, i64** %3
%24 = getelementptr inbounds i64, i64* %23, i64 1
%25 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %24, i32 4)
store i32 %25, i32* %6
%26 = zext i32 %25 to i64
%27 = icmp uge i64 %26, 3221258240
br i1 %27, label %28, label %38
28: ; preds = %22
%29 = load i32, i32* %6
%30 = load i64*, i64** %3
%31 = call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %30, i32 4)
%32 = icmp uge i32 %29, %31
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i64*, i64** %3
%35 = getelementptr inbounds i64, i64* %34, i32 1
store i64* %35, i64** %3
%36 = load i32, i32* %5
%37 = add i32 %36, 1
store i32 %37, i32* %5
br label %18
38: ; preds = %28, %22
br label %39
39: ; preds = %38, %18
%40 = load i32, i32* %5
%41 = zext i32 %40 to i64
%42 = icmp eq i64 %41, 10000
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i64*, i64** %2
store i64* %44, i64** %1
br label %53
45: ; preds = %39
br label %46
46: ; preds = %45, %11
%47 = load i32, i32* %5
%48 = add i32 %47, 1
%49 = load i64*, i64** %2
%50 = zext i32 %48 to i64
%51 = getelementptr inbounds i64, i64* %49, i64 %50
store i64* %51, i64** %2
br label %8
52: ; preds = %8
store i64* null, i64** %1
br label %53
53: ; preds = %52, %43
%54 = load i64*, i64** %1
ret i64* %54
}

LLVM IR (-O2):
define i64* @find_kernel_symbol_tab() {
br label %1
1: ; preds = %0, %17
%2 = phi i64* [ inttoptr (i64 3221258240 to i64*), %0 ], [ %21, %17 ]
%3 = tail call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %2, i32 4)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %1, %14
%6 = phi i32 [ %15, %14 ], [ 0, %1 ]
%7 = phi i64* [ %8, %14 ], [ %2, %1 ]
%8 = getelementptr inbounds i64, i64* %7, i64 1
%9 = tail call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %8, i32 4)
%10 = icmp ugt i32 %9, -1073709057
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = tail call i32 (i64*, i32, ...) bitcast (i32 (...)* @k_read to i32 (i64*, i32, ...)*)(i64* %7, i32 4)
%13 = icmp ult i32 %9, %12
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, 10000
br i1 %16, label %23, label %5
17: ; preds = %11, %5, %1
%18 = phi i32 [ 0, %1 ], [ %6, %5 ], [ %6, %11 ]
%19 = add nuw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %2, i64 %20
%22 = icmp ult i64* %21, inttoptr (i64 3238002688 to i64*)
br i1 %22, label %1, label %23
23: ; preds = %17, %14
%24 = phi i64* [ %2, %14 ], [ null, %17 ]
ret i64* %24
}