#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 EOF;
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int findLineLength(FILE *fh) {
  int ch;
  int length = 0;
  if (feof(fh)) {
    return -1;
  }
  do {
    ch = fgetc(fh);
    length++;
  } while ((ch != '\n') && (ch != EOF));
  return length;
}


x86 assembly (clang, -O0):
<findLineLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1152 <findLineLength+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    119e <findLineLength+0x7e>
jmp    1157 <findLineLength+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     118d <findLineLength+0x6d>
mov    -0x14(%rbp),%eax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1157 <findLineLength+0x37>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findLineLength>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <feof@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1155 <findLineLength+0x35>
xor    %ebp,%ebp
mov    0x2ea9(%rip),%r14
nop
mov    %rbx,%rdi
call   1030 <fgetc@plt>
add    $0x1,%ebp
cmp    $0xa,%eax
je     1155 <findLineLength+0x35>
cmp    (%r14),%eax
jne    1140 <findLineLength+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @findLineLength(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
%6 = load i32*, i32** %3
%7 = call i64 @feof(i32* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %27
10: ; preds = %1
br label %11
11: ; preds = %23, %10
%12 = load i32*, i32** %3
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %16
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %4
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %11, label %25
25: ; preds = %23
%26 = load i32, i32* %5
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %9
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @findLineLength(i32* nocapture %0) {
%2 = tail call i64 @feof(i32* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1, %4
%5 = phi i32 [ %7, %4 ], [ 0, %1 ]
%6 = tail call i32 @fgetc(i32* %0)
%7 = add nuw nsw i32 %5, 1
%8 = icmp ne i32 %6, 10
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %6, %9
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %4, label %12
12: ; preds = %4, %1
%13 = phi i32 [ -1, %1 ], [ %7, %4 ]
ret i32 %13
}