#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int scan_line(FILE *fid, char *line) {
  int i;
  if (fid == NULL) {
    return 0;
  }
  if (feof(fid)) {
    return 0;
  }
  do {
    fgets(line, 256, fid);
    for (i = 0; line[i] != '\0'; i++) {
      if (line[i] == '#' || line[i] == '\n' || line[i] == '\r') {
        line[i] = '\0';
        break;
      }
    }
  } while (line[0] == '\0' && feof(fid) == 0);
  if (feof(fid))
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<scan_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <scan_line+0x27>
movl   $0x0,-0x4(%rbp)
jmp    125a <scan_line+0x13a>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1166 <scan_line+0x46>
movl   $0x0,-0x4(%rbp)
jmp    125a <scan_line+0x13a>
jmp    116b <scan_line+0x4b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1030 <fgets@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11fc <scan_line+0xdc>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
je     11d8 <scan_line+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11d8 <scan_line+0xb8>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    11e9 <scan_line+0xc9>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fc <scan_line+0xdc>
jmp    11ee <scan_line+0xce>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <scan_line+0x64>
jmp    1201 <scan_line+0xe1>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1229 <scan_line+0x109>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    116b <scan_line+0x4b>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1253 <scan_line+0x133>
movl   $0x0,-0x4(%rbp)
jmp    125a <scan_line+0x13a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_line>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
test   %rdi,%rdi
je     11ae <scan_line+0x8e>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <feof@plt>
test   %rax,%rax
jne    11ae <scan_line+0x8e>
lea    0xeba(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
xor    %eax,%eax
jmp    1174 <scan_line+0x54>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rax
movzbl (%rbx,%rax,1),%ecx
cmp    $0x23,%rcx
ja     1170 <scan_line+0x50>
movslq 0x0(%rbp,%rcx,4),%rcx
add    %rbp,%rcx
jmp    *%rcx
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
cmpb   $0x0,(%rbx)
jne    11a0 <scan_line+0x80>
mov    %r14,%rdi
call   1040 <feof@plt>
test   %rax,%rax
je     1150 <scan_line+0x30>
mov    %r14,%rdi
call   1040 <feof@plt>
cmp    $0x1,%rax
sbb    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scan_line(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %80
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = call i64 @feof(i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 0, i32* %3
br label %80
15: ; preds = %10
br label %16
16: ; preds = %72, %15
%17 = load i8*, i8** %5
%18 = load i32*, i32** %4
%19 = call i32 @fgets(i8* %17, i32 256, i32* %18)
store i32 0, i32* %6
br label %20
20: ; preds = %58, %16
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %61
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 35
br i1 %35, label %52, label %36
36: ; preds = %28
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %52, label %44
44: ; preds = %36
%45 = load i8*, i8** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 13
br i1 %51, label %52, label %57
52: ; preds = %44, %36, %28
%53 = load i8*, i8** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 0, i8* %56
br label %61
57: ; preds = %44
br label %58
58: ; preds = %57
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
store i32 %60, i32* %6
br label %20
61: ; preds = %52, %20
br label %62
62: ; preds = %61
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 0
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %62
%69 = load i32*, i32** %4
%70 = call i64 @feof(i32* %69)
%71 = icmp eq i64 %70, 0
br label %72
72: ; preds = %68, %62
%73 = phi i1 [ false, %62 ], [ %71, %68 ]
br i1 %73, label %16, label %74
74: ; preds = %72
%75 = load i32*, i32** %4
%76 = call i64 @feof(i32* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %74
store i32 0, i32* %3
br label %80
79: ; preds = %74
store i32 -1, i32* %3
br label %80
80: ; preds = %79, %78, %14, %9
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
define i32 @scan_line(i32* %0, i8* %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = tail call i64 @feof(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %28
7: ; preds = %4, %21
%8 = tail call i32 @fgets(i8* %1, i32 256, i32* %0)
br label %9
9: ; preds = %16, %7
%10 = phi i64 [ %17, %16 ], [ 0, %7 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %16 [
i8 0, label %18
i8 35, label %13
i8 10, label %13
i8 13, label %13
]
13: ; preds = %9, %9, %9
%14 = and i64 %10, 4294967295
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
br label %18
16: ; preds = %9
%17 = add nuw i64 %10, 1
br label %9
18: ; preds = %9, %13
%19 = load i8, i8* %1
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i64 @feof(i32* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %7, label %24
24: ; preds = %18, %21
%25 = tail call i64 @feof(i32* %0)
%26 = icmp eq i64 %25, 0
%27 = sext i1 %26 to i32
br label %28
28: ; preds = %24, %4, %2
%29 = phi i32 [ 0, %2 ], [ 0, %4 ], [ %27, %24 ]
ret i32 %29
}