#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 */
long EOF;
int /*<<< orphan*/ SEEK_CUR;
long fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void HDR_GetLineByFile(FILE *fp, unsigned char *pucLine,
                       unsigned long *pulLineLen) {
  long ch;
  char cNextCh;
  unsigned char *pucBuf = pucLine;
  while ((ch = fgetc(fp)) != EOF) {
    if (('\r' == (char)ch) || ('\n' == (char)ch)) {
      if ('\r' == (char)ch) {
        cNextCh = (char)fgetc(fp);
        if ('\n' != cNextCh) {
          fseek(fp, -1, SEEK_CUR);
        }
      }
      break;
    }
    *pucBuf = (unsigned char)ch;
    pucBuf++;
    (*pulLineLen)++;
  }
  pucBuf[0] = 0;
  return;
}


x86 assembly (clang, -O0):
<HDR_GetLineByFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
je     11fe <HDR_GetLineByFile+0xde>
mov    -0x20(%rbp),%rax
movsbl %al,%ecx
mov    $0xd,%eax
cmp    %ecx,%eax
je     1181 <HDR_GetLineByFile+0x61>
mov    -0x20(%rbp),%rax
movsbl %al,%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    11d3 <HDR_GetLineByFile+0xb3>
mov    -0x20(%rbp),%rax
movsbl %al,%ecx
mov    $0xd,%eax
cmp    %ecx,%eax
jne    11ce <HDR_GetLineByFile+0xae>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
je     11c9 <HDR_GetLineByFile+0xa9>
mov    -0x8(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
jmp    11ce <HDR_GetLineByFile+0xae>
jmp    11fe <HDR_GetLineByFile+0xde>
mov    -0x20(%rbp),%rax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    113c <HDR_GetLineByFile+0x1c>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HDR_GetLineByFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    0x2ea3(%rip),%r12
cmp    (%r12),%rax
je     1170 <HDR_GetLineByFile+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%al
je     1170 <HDR_GetLineByFile+0x50>
cmp    $0xd,%al
je     117f <HDR_GetLineByFile+0x5f>
mov    %al,(%rbx)
add    $0x1,%rbx
addq   $0x1,(%r15)
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%rax
jne    1150 <HDR_GetLineByFile+0x30>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     1170 <HDR_GetLineByFile+0x50>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
jmp    1170 <HDR_GetLineByFile+0x50>

LLVM IR (-O0):
@EOF = global i64 0
@SEEK_CUR = global i32 0
define void @HDR_GetLineByFile(i32* %0, i8* %1, i64* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64* %2, i64** %6
%10 = load i8*, i8** %5
store i8* %10, i8** %9
br label %11
11: ; preds = %44, %3
%12 = load i32*, i32** %4
%13 = call i64 @fgetc(i32* %12)
store i64 %13, i64* %7
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %11
%17 = load i64, i64* %7
%18 = trunc i64 %17 to i8
%19 = sext i8 %18 to i32
%20 = icmp eq i32 13, %19
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i64, i64* %7
%23 = trunc i64 %22 to i8
%24 = sext i8 %23 to i32
%25 = icmp eq i32 10, %24
br i1 %25, label %26, label %44
26: ; preds = %21, %16
%27 = load i64, i64* %7
%28 = trunc i64 %27 to i8
%29 = sext i8 %28 to i32
%30 = icmp eq i32 13, %29
br i1 %30, label %31, label %43
31: ; preds = %26
%32 = load i32*, i32** %4
%33 = call i64 @fgetc(i32* %32)
%34 = trunc i64 %33 to i8
store i8 %34, i8* %8
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp ne i32 10, %36
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32*, i32** %4
%40 = load i32, i32* @SEEK_CUR
%41 = call i32 @fseek(i32* %39, i32 -1, i32 %40)
br label %42
42: ; preds = %38, %31
br label %43
43: ; preds = %42, %26
br label %53
44: ; preds = %21
%45 = load i64, i64* %7
%46 = trunc i64 %45 to i8
%47 = load i8*, i8** %9
store i8 %46, i8* %47
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %9
%50 = load i64*, i64** %6
%51 = load i64, i64* %50
%52 = add i64 %51, 1
store i64 %52, i64* %50
br label %11
53: ; preds = %43, %11
%54 = load i8*, i8** %9
%55 = getelementptr inbounds i8, i8* %54, i64 0
store i8 0, i8* %55
ret void
}

LLVM IR (-O2):
@EOF = global i64 0
@SEEK_CUR = global i32 0
define void @HDR_GetLineByFile(i32* nocapture %0, i8* nocapture writeonly %1, i64* nocapture %2) {
%4 = tail call i64 @fgetc(i32* %0)
%5 = load i64, i64* @EOF
%6 = icmp eq i64 %4, %5
br i1 %6, label %25, label %7
7: ; preds = %3, %18
%8 = phi i64 [ %22, %18 ], [ %4, %3 ]
%9 = phi i8* [ %19, %18 ], [ %1, %3 ]
%10 = trunc i64 %8 to i8
switch i8 %10, label %18 [
i8 13, label %11
i8 10, label %25
]
11: ; preds = %7
%12 = tail call i64 @fgetc(i32* %0)
%13 = and i64 %12, 255
%14 = icmp eq i64 %13, 10
br i1 %14, label %25, label %15
15: ; preds = %11
%16 = load i32, i32* @SEEK_CUR
%17 = tail call i32 @fseek(i32* %0, i32 -1, i32 %16)
br label %25
18: ; preds = %7
store i8 %10, i8* %9
%19 = getelementptr inbounds i8, i8* %9, i64 1
%20 = load i64, i64* %2
%21 = add i64 %20, 1
store i64 %21, i64* %2
%22 = tail call i64 @fgetc(i32* %0)
%23 = load i64, i64* @EOF
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %7
25: ; preds = %18, %7, %3, %15, %11
%26 = phi i8* [ %9, %15 ], [ %9, %11 ], [ %1, %3 ], [ %19, %18 ], [ %9, %7 ]
store i8 0, i8* %26
ret void
}