#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 */

/* Variables and functions */
int /*<<< orphan*/ skip_space(char **);
char *strchr(char *, char);
int read_eol_n(char **str, int n) {
  int ok = 0;
  char *tmp;
  skip_space(str);
  tmp = strchr(*str, '\n');
  if (tmp != NULL) {
    if (tmp - (*str) < n) {
      ok = 1;
      (*str) = tmp + 1;
      skip_space(str);
    }
  }
  return ok;
}


x86 assembly (clang, -O0):
<read_eol_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <skip_space@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <read_eol_n+0x7e>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jge    1199 <read_eol_n+0x79>
movl   $0x1,-0x10(%rbp)
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <skip_space@plt>
jmp    119e <read_eol_n+0x7e>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_eol_n>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <skip_space@plt>
mov    (%rbx),%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     116b <read_eol_n+0x4b>
mov    %rcx,%rdx
sub    %rbp,%rdx
movslq %r14d,%rsi
cmp    %rsi,%rdx
jge    116b <read_eol_n+0x4b>
add    $0x1,%rcx
mov    %rcx,(%rbx)
mov    %rbx,%rdi
call   1030 <skip_space@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_eol_n(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i8**, i8*** %3
%8 = call i32 @skip_space(i8** %7)
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = call i8* @strchr(i8* %10, i8 signext 10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %31
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = ptrtoint i8* %15 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %24, label %30
24: ; preds = %14
store i32 1, i32* %5
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8**, i8*** %3
store i8* %26, i8** %27
%28 = load i8**, i8*** %3
%29 = call i32 @skip_space(i8** %28)
br label %30
30: ; preds = %24, %14
br label %31
31: ; preds = %30, %2
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @read_eol_n(i8** %0, i32 %1) {
%3 = tail call i32 @skip_space(i8** %0)
%4 = load i8*, i8** %0
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 10)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %4 to i64
%10 = sub i64 %8, %9
%11 = sext i32 %1 to i64
%12 = icmp slt i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %14, i8** %0
%15 = tail call i32 @skip_space(i8** %0)
br label %16
16: ; preds = %7, %13, %2
%17 = phi i32 [ 1, %13 ], [ 0, %7 ], [ 0, %2 ]
ret i32 %17
}