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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int sscanf(char *, char *, int *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
void rtnl_tab_initialize(char *file, char **tab, int size) {
  char buf[512];
  FILE *fp;
  fp = fopen(file, "r");
  if (!fp) {
    return;
  }
  while (fgets(buf, sizeof(buf), fp)) {
    char *p = buf;
    int id;
    char namebuf[512];
    while (*p == ' ' || *p == '\t') {
      p++;
    }
    if (*p == '#' || *p == '\n' || *p == 0) {
      continue;
    }
    if (sscanf(p, "0x%x %s\n", &id, namebuf) != 2 &&
        sscanf(p, "0x%x %s #", &id, namebuf) != 2 &&
        sscanf(p, "%d %s\n", &id, namebuf) != 2 &&
        sscanf(p, "%d %s #", &id, namebuf) != 2) {
      fprintf(stderr, "Database %s is corrupted at %s\n", file, p);
      fclose(fp);
      return;
    }
    if (id < 0 || id > size) {
      continue;
    }
    tab[id] = strdup(namebuf);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<rtnl_tab_initialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    11a0 <rtnl_tab_initialize+0x40>
jmp    1397 <rtnl_tab_initialize+0x237>
jmp    11a5 <rtnl_tab_initialize+0x45>
lea    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     138b <rtnl_tab_initialize+0x22b>
lea    -0x220(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x441(%rbp)
je     1206 <rtnl_tab_initialize+0xa6>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    1219 <rtnl_tab_initialize+0xb9>
jmp    1230 <rtnl_tab_initialize+0xd0>
mov    -0x230(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x230(%rbp)
jmp    11d5 <rtnl_tab_initialize+0x75>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1269 <rtnl_tab_initialize+0x109>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1269 <rtnl_tab_initialize+0x109>
mov    -0x230(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    126e <rtnl_tab_initialize+0x10e>
jmp    11a5 <rtnl_tab_initialize+0x45>
mov    -0x230(%rbp),%rdi
lea    -0x440(%rbp),%rcx
lea    0xd7f(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     1347 <rtnl_tab_initialize+0x1e7>
mov    -0x230(%rbp),%rdi
lea    -0x440(%rbp),%rcx
lea    0xd5e(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     1347 <rtnl_tab_initialize+0x1e7>
mov    -0x230(%rbp),%rdi
lea    -0x440(%rbp),%rcx
lea    0xd3e(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     1347 <rtnl_tab_initialize+0x1e7>
mov    -0x230(%rbp),%rdi
lea    -0x440(%rbp),%rcx
lea    0xd1b(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     1347 <rtnl_tab_initialize+0x1e7>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x230(%rbp),%rcx
lea    0xcf3(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x228(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1397 <rtnl_tab_initialize+0x237>
cmpl   $0x0,-0x234(%rbp)
jl     1363 <rtnl_tab_initialize+0x203>
mov    -0x234(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1368 <rtnl_tab_initialize+0x208>
jmp    11a5 <rtnl_tab_initialize+0x45>
lea    -0x440(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x234(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11a5 <rtnl_tab_initialize+0x45>
mov    -0x228(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnl_tab_initialize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbp
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1301 <rtnl_tab_initialize+0x1a1>
mov    %rax,%rbx
mov    %rbp,0x10(%rsp)
lea    0x220(%rsp),%r15
mov    %r15,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     12f9 <rtnl_tab_initialize+0x199>
lea    0x8(%rsp),%r13
lea    0x20(%rsp),%r14
movabs $0x100000200,%r12
jmp    1213 <rtnl_tab_initialize+0xb3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movabs $0x800000401,%rcx
bt     %rax,%rcx
jae    1240 <rtnl_tab_initialize+0xe0>
mov    %r15,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
lea    0x20(%rsp),%r14
lea    0x8(%rsp),%r13
test   %rax,%rax
je     12f9 <rtnl_tab_initialize+0x199>
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
cmp    $0x23,%rax
ja     1240 <rtnl_tab_initialize+0xe0>
bt     %rax,%r12
jae    11e0 <rtnl_tab_initialize+0x80>
add    $0x1,%rbp
jmp    1220 <rtnl_tab_initialize+0xc0>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xdb8(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     12b0 <rtnl_tab_initialize+0x150>
mov    %rbp,%rdi
lea    0xda7(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     12b0 <rtnl_tab_initialize+0x150>
mov    %rbp,%rdi
lea    0xd97(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     12b0 <rtnl_tab_initialize+0x150>
mov    %rbp,%rdi
lea    0xd84(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    12dc <rtnl_tab_initialize+0x17c>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%ebp
test   %ebp,%ebp
js     11f0 <rtnl_tab_initialize+0x90>
cmp    0xc(%rsp),%ebp
jg     11f0 <rtnl_tab_initialize+0x90>
mov    %r14,%rdi
call   1080 <strdup@plt>
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx,%rbp,8)
jmp    11f0 <rtnl_tab_initialize+0x90>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd38(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %rbp,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [9 x i8] c"0x%x %s\0A\00"
@.str.2 = [10 x i8] c"0x%x %s #\00"
@.str.3 = [7 x i8] c"%d %s\0A\00"
@.str.4 = [8 x i8] c"%d %s #\00"
@stderr = global i32 0
@.str.5 = [32 x i8] c"Database %s is corrupted at %s\0A\00"
define void @rtnl_tab_initialize(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 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 %52, label %10
10: ; preds = %3
%11 = call i64 @fgets(i8* %7, i32 512, i32* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %50, label %13
13: ; preds = %10
%14 = bitcast i32* %5 to i8*
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
br label %16
16: ; preds = %13, %47
br label %17
17: ; preds = %20, %16
%18 = phi i8* [ %7, %16 ], [ %21, %20 ]
%19 = load i8, i8* %18
switch i8 %19, label %22 [
i8 32, label %20
i8 9, label %20
i8 35, label %47
i8 10, label %47
i8 0, label %47
]
20: ; preds = %17, %17
%21 = getelementptr inbounds i8, i8* %18, i64 1
br label %17
22: ; preds = %17
%23 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %5, i8* %15)
%24 = icmp eq i32 %23, 2
br i1 %24, label %38, label %25
25: ; preds = %22
%26 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %5, i8* %15)
%27 = icmp eq i32 %26, 2
br i1 %27, label %38, label %28
28: ; preds = %25
%29 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %5, i8* %15)
%30 = icmp eq i32 %29, 2
br i1 %30, label %38, label %31
31: ; preds = %28
%32 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* %5, i8* %15)
%33 = icmp eq i32 %32, 2
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %18)
%37 = call i32 @fclose(i32* %8)
br label %52
38: ; preds = %31, %28, %25, %22
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 0
%41 = icmp sgt i32 %39, %2
%42 = or i1 %40, %41
br i1 %42, label %47, label %43
43: ; preds = %38
%44 = call i8* @strdup(i8* %15)
%45 = zext i32 %39 to i64
%46 = getelementptr inbounds i8*, i8** %1, i64 %45
store i8* %44, i8** %46
br label %47
47: ; preds = %17, %17, %17, %38, %43
%48 = call i64 @fgets(i8* %7, i32 512, i32* %8)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %16
50: ; preds = %47, %10
%51 = call i32 @fclose(i32* %8)
br label %52
52: ; preds = %34, %3, %50
ret void
}