#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 */
char EOF;
char getc(int /*<<< orphan*/ *);
int read_block(char *buf, FILE *fin) {
  int ret = 0;
  int hit = 0;
  char *curr = buf;
  for (;;) {
    *curr = getc(fin);
    if (*curr == EOF)
      return -1;
    ret++;
    if (*curr == '\n' && hit == 1)
      return ret - 1;
    else if (*curr == '\n')
      hit = 1;
    else
      hit = 0;
    curr++;
  }
}


x86 assembly (clang, -O0):
<read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <getc@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    0x2e93(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    116c <read_block+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d6 <read_block+0xc6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    119d <read_block+0x8d>
cmpl   $0x1,-0x20(%rbp)
jne    119d <read_block+0x8d>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <read_block+0xc6>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b9 <read_block+0xa9>
movl   $0x1,-0x20(%rbp)
jmp    11c0 <read_block+0xb0>
movl   $0x0,-0x20(%rbp)
jmp    11c5 <read_block+0xb5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1136 <read_block+0x26>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rsi,%rdi
call   1030 <getc@plt>
mov    %al,0x0(%r13)
mov    0x2eb4(%rip),%r15
mov    $0xffffffff,%r14d
cmp    (%r15),%al
je     117a <read_block+0x6a>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    116e <read_block+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ebp,%ebp
cmp    $0xa,%al
sete   %bpl
mov    %r12,%rdi
call   1030 <getc@plt>
mov    %al,0x1(%r13,%rbx,1)
add    $0x1,%rbx
cmp    (%r15),%al
je     117a <read_block+0x6a>
cmp    $0x1,%ebp
jne    1150 <read_block+0x40>
cmp    $0xa,%al
jne    1150 <read_block+0x40>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @read_block(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
store i8* %9, i8** %8
br label %10
10: ; preds = %42, %2
%11 = load i32*, i32** %5
%12 = call signext i8 @getc(i32* %11)
%13 = load i8*, i8** %8
store i8 %12, i8* %13
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %10
store i32 -1, i32* %3
br label %45
21: ; preds = %10
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %3
br label %45
34: ; preds = %28, %21
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 1, i32* %7
br label %41
40: ; preds = %34
store i32 0, i32* %7
br label %41
41: ; preds = %40, %39
br label %42
42: ; preds = %41
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %8
br label %10
45: ; preds = %31, %20
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @read_block(i8* nocapture writeonly %0, i32* nocapture %1) {
%3 = tail call signext i8 @getc(i32* %1)
store i8 %3, i8* %0
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %21, label %6
6: ; preds = %2, %14
%7 = phi i8 [ %18, %14 ], [ %3, %2 ]
%8 = phi i8* [ %17, %14 ], [ %0, %2 ]
%9 = phi i32 [ %16, %14 ], [ 0, %2 ]
%10 = phi i32 [ %15, %14 ], [ 0, %2 ]
%11 = icmp eq i8 %7, 10
%12 = icmp eq i32 %9, 1
%13 = and i1 %12, %11
br i1 %13, label %21, label %14
14: ; preds = %6
%15 = add nuw nsw i32 %10, 1
%16 = zext i1 %11 to i32
%17 = getelementptr inbounds i8, i8* %8, i64 1
%18 = tail call signext i8 @getc(i32* %1)
store i8 %18, i8* %17
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %6
21: ; preds = %14, %6, %2
%22 = phi i32 [ -1, %2 ], [ %10, %6 ], [ -1, %14 ]
ret i32 %22
}