#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ interpret_table_entry(char *);
scalar_t__ isspace(char);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memmove(char *, char *, int);
size_t strspn(char *, char *);
void parse_device_table(FILE *file) {
  char *line;
  size_t length = 256;
  int len = 0;
  if ((line = (char *)malloc(length)) == NULL) {
    fclose(file);
    return;
  }
  while ((len = getline(&line, &length, file)) != -1) {
    while (len > 0 && isspace(line[len - 1]))
      line[--len] = '\0';
    memmove(line, &line[strspn(line, " \n\r\t\v")], len + 1);
    if (*line != '#')
      interpret_table_entry(line);
  }
  if (line)
    free(line);
  fclose(file);
}


x86 assembly (clang, -O0):
<parse_device_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x100,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c0 <parse_device_table+0x40>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12b0 <parse_device_table+0x130>
jmp    11c5 <parse_device_table+0x45>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1293 <parse_device_table+0x113>
jmp    11e7 <parse_device_table+0x67>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jle    1216 <parse_device_table+0x96>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1226 <parse_device_table+0xa6>
jmp    123f <parse_device_table+0xbf>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e7 <parse_device_table+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1060 <strspn@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1090 <memmove@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     128e <parse_device_table+0x10e>
mov    -0x10(%rbp),%rdi
call   1050 <interpret_table_entry@plt>
jmp    11c5 <parse_device_table+0x45>
cmpq   $0x0,-0x10(%rbp)
je     12a7 <parse_device_table+0x127>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_device_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r13
movq   $0x100,0x10(%rsp)
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1297 <parse_device_table+0x117>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     1271 <parse_device_table+0xf1>
mov    %eax,%ebx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11f5 <parse_device_table+0x75>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10a0 <getline@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1271 <parse_device_table+0xf1>
test   %ebx,%ebx
jle    1234 <parse_device_table+0xb4>
mov    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
lea    -0x1(%rbx),%rbp
mov    %ebp,%r14d
movsbl (%rax,%r14,1),%edi
call   1070 <isspace@plt>
test   %rax,%rax
je     1234 <parse_device_table+0xb4>
mov    0x8(%rsp),%rax
movb   $0x0,(%rax,%r14,1)
lea    0x1(%rbp),%rax
mov    %rbp,%rbx
cmp    $0x1,%rax
ja     1200 <parse_device_table+0x80>
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
lea    0xdbd(%rip),%rsi
call   1060 <strspn@plt>
lea    (%rax,%rbp,1),%rsi
add    $0x1,%ebx
mov    %rbp,%rdi
mov    %ebx,%edx
call   1090 <memmove@plt>
mov    0x8(%rsp),%rdi
cmpb   $0x23,(%rdi)
je     11e0 <parse_device_table+0x60>
call   1050 <interpret_table_entry@plt>
jmp    11e0 <parse_device_table+0x60>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1280 <parse_device_table+0x100>
call   1030 <free@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [6 x i8] c" \0A\0D\09\0B\00"
define void @parse_device_table(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %2
store i64 256, i64* %4
store i32 0, i32* %5
%6 = load i64, i64* %4
%7 = call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
br label %65
13: ; preds = %1
br label %14
14: ; preds = %55, %13
%15 = load i32*, i32** %2
%16 = call i32 @getline(i8** %3, i64* %4, i32* %15)
store i32 %16, i32* %5
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %56
18: ; preds = %14
br label %19
19: ; preds = %33, %18
%20 = load i32, i32* %5
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @isspace(i8 signext %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %22, %19
%32 = phi i1 [ false, %19 ], [ %30, %22 ]
br i1 %32, label %33, label %39
33: ; preds = %31
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, -1
store i32 %36, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 0, i8* %38
br label %19
39: ; preds = %31
%40 = load i8*, i8** %3
%41 = load i8*, i8** %3
%42 = load i8*, i8** %3
%43 = call i64 @strspn(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = call i32 @memmove(i8* %40, i8* %44, i32 %46)
%48 = load i8*, i8** %3
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 35
br i1 %51, label %52, label %55
52: ; preds = %39
%53 = load i8*, i8** %3
%54 = call i32 @interpret_table_entry(i8* %53)
br label %55
55: ; preds = %52, %39
br label %14
56: ; preds = %14
%57 = load i8*, i8** %3
%58 = icmp ne i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %3
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %59, %56
%63 = load i32*, i32** %2
%64 = call i32 @fclose(i32* %63)
br label %65
65: ; preds = %62, %10
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c" \0A\0D\09\0B\00"
define void @parse_device_table(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
store i64 256, i64* %3
%6 = tail call i64 @malloc(i64 256)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = icmp eq i64 %6, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %49, label %14
12: ; preds = %1
%13 = tail call i32 @fclose(i32* %0)
br label %56
14: ; preds = %9, %46
%15 = phi i32 [ %47, %46 ], [ %10, %9 ]
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = zext i32 %15 to i64
br label %19
19: ; preds = %17, %28
%20 = phi i64 [ %18, %17 ], [ %22, %28 ]
%21 = load i8*, i8** %2
%22 = add nsw i64 %20, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i64 @isspace(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %19
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 %23
store i8 0, i8* %30
%31 = icmp ugt i64 %20, 1
br i1 %31, label %19, label %34
32: ; preds = %19
%33 = trunc i64 %20 to i32
br label %34
34: ; preds = %28, %32, %14
%35 = phi i32 [ %15, %14 ], [ %33, %32 ], [ 0, %28 ]
%36 = load i8*, i8** %2
%37 = call i64 @strspn(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = add nsw i32 %35, 1
%40 = call i32 @memmove(i8* %36, i8* %38, i32 %39)
%41 = load i8*, i8** %2
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 35
br i1 %43, label %46, label %44
44: ; preds = %34
%45 = call i32 @interpret_table_entry(i8* %41)
br label %46
46: ; preds = %44, %34
%47 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %14
49: ; preds = %46, %9
%50 = load i8*, i8** %2
%51 = icmp eq i8* %50, null
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @free(i8* %50)
br label %54
54: ; preds = %52, %49
%55 = call i32 @fclose(i32* %0)
br label %56
56: ; preds = %54, %12
ret void
}