#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*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, unsigned int, int /*<<< orphan*/ *);
unsigned int strlen(char *);
bool FileGetLine(FILE *fp, char *buffer, unsigned length) {
  char *ret = NULL;
  while (ret == NULL && !feof(fp)) {
    ret = fgets(buffer, length, fp);
    unsigned len = strlen(buffer);
    if (len && buffer[len - 1] == '\n') {
      buffer[len - 1] = '\0';
    }
    if (len == 0 || buffer[0] == '#') {
      ret = NULL;
    }
  }
  return ret == buffer;
}


x86 assembly (clang, -O0):
<FileGetLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
jne    116f <FileGetLine+0x3f>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    117f <FileGetLine+0x4f>
jmp    11f9 <FileGetLine+0xc9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11d2 <FileGetLine+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11d2 <FileGetLine+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x24(%rbp)
je     11ec <FileGetLine+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11f4 <FileGetLine+0xc4>
movq   $0x0,-0x20(%rbp)
jmp    114b <FileGetLine+0x1b>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileGetLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
jmp    1157 <FileGetLine+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
test   %rbp,%rbp
jne    119d <FileGetLine+0x6d>
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    119b <FileGetLine+0x6b>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1150 <FileGetLine+0x20>
add    $0xffffffff,%eax
cmpb   $0xa,(%rbx,%rax,1)
je     1190 <FileGetLine+0x60>
cmpb   $0x23,(%rbx)
je     1150 <FileGetLine+0x20>
jmp    1152 <FileGetLine+0x22>
movb   $0x0,(%rbx,%rax,1)
cmpb   $0x23,(%rbx)
je     1150 <FileGetLine+0x20>
jmp    1152 <FileGetLine+0x22>
xor    %ebp,%ebp
xor    %eax,%eax
cmp    %rbx,%rbp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FileGetLine(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
br label %9
9: ; preds = %53, %3
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %54
19: ; preds = %17
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = load i32*, i32** %4
%23 = call i8* @fgets(i8* %20, i32 %21, i32* %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %5
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %19
%29 = load i8*, i8** %5
%30 = load i32, i32* %8
%31 = sub i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %43
37: ; preds = %28
%38 = load i8*, i8** %5
%39 = load i32, i32* %8
%40 = sub i32 %39, 1
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %37, %28, %19
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 0
br i1 %45, label %52, label %46
46: ; preds = %43
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 35
br i1 %51, label %52, label %53
52: ; preds = %46, %43
store i8* null, i8** %7
br label %53
53: ; preds = %52, %46
br label %9
54: ; preds = %17
%55 = load i8*, i8** %7
%56 = load i8*, i8** %5
%57 = icmp eq i8* %55, %56
%58 = zext i1 %57 to i32
ret i32 %58
}

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