#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*/ assert(int);
char *endofline(char *);
char *getbufend();
char *getbufstart();
scalar_t__ screenlines(char *);
char *skipscreenlines(char *start, int lines) {
  assert((start >= getbufstart() && start <= getbufend()));
  while (lines > 0 && start < getbufend()) {
    lines -= screenlines(start);
    start = endofline(start) + 1;
  }
  if (start > getbufend())
    start = getbufend();
  return start;
}


x86 assembly (clang, -O0):
<skipscreenlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getbufstart@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0xd(%rbp)
jb     11a2 <skipscreenlines+0x52>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getbufend@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setbe  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jle    11dd <skipscreenlines+0x8d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getbufend@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ed <skipscreenlines+0x9d>
jmp    1219 <skipscreenlines+0xc9>
mov    -0x8(%rbp),%rdi
call   1060 <screenlines@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <endofline@plt>
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11af <skipscreenlines+0x5f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getbufend@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jbe    1243 <skipscreenlines+0xf3>
mov    $0x0,%al
call   1030 <getbufend@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skipscreenlines>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getbufstart@plt>
cmp    %rbx,%rax
ja     1179 <skipscreenlines+0x29>
xor    %eax,%eax
call   1030 <getbufend@plt>
xor    %r14d,%r14d
cmp    %rbx,%rax
setae  %r14b
mov    %r14d,%edi
call   1050 <assert@plt>
test   %ebp,%ebp
jle    11b9 <skipscreenlines+0x69>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <getbufend@plt>
cmp    %rax,%rbx
jae    11b9 <skipscreenlines+0x69>
mov    %rbx,%rdi
call   1060 <screenlines@plt>
sub    %eax,%ebp
mov    %rbx,%rdi
call   1070 <endofline@plt>
mov    %rax,%rbx
add    $0x1,%rbx
test   %ebp,%ebp
jg     1190 <skipscreenlines+0x40>
xor    %eax,%eax
call   1030 <getbufend@plt>
cmp    %rax,%rbx
jbe    11d0 <skipscreenlines+0x80>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <getbufend@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @skipscreenlines(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = call i8* (...) @getbufstart()
%7 = icmp uge i8* %5, %6
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i8* (...) @getbufend()
%11 = icmp ule i8* %9, %10
br label %12
12: ; preds = %8, %2
%13 = phi i1 [ false, %2 ], [ %11, %8 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
br label %16
16: ; preds = %25, %12
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i8* (...) @getbufend()
%22 = icmp ult i8* %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %25, label %35
25: ; preds = %23
%26 = load i8*, i8** %3
%27 = call i64 @screenlines(i8* %26)
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = sub nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %4
%32 = load i8*, i8** %3
%33 = call i8* @endofline(i8* %32)
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %3
br label %16
35: ; preds = %23
%36 = load i8*, i8** %3
%37 = call i8* (...) @getbufend()
%38 = icmp ugt i8* %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i8* (...) @getbufend()
store i8* %40, i8** %3
br label %41
41: ; preds = %39, %35
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
define i8* @skipscreenlines(i8* %0, i32 %1) {
%3 = tail call i8* (...) @getbufstart()
%4 = icmp ugt i8* %3, %0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i8* (...) @getbufend()
%7 = icmp uge i8* %6, %0
%8 = zext i1 %7 to i32
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ 0, %2 ], [ %8, %5 ]
%11 = tail call i32 @assert(i32 %10)
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %25
13: ; preds = %9, %18
%14 = phi i32 [ %21, %18 ], [ %1, %9 ]
%15 = phi i8* [ %23, %18 ], [ %0, %9 ]
%16 = tail call i8* (...) @getbufend()
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = tail call i64 @screenlines(i8* %15)
%20 = trunc i64 %19 to i32
%21 = sub i32 %14, %20
%22 = tail call i8* @endofline(i8* %15)
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = icmp sgt i32 %21, 0
br i1 %24, label %13, label %25
25: ; preds = %13, %18, %9
%26 = phi i8* [ %0, %9 ], [ %23, %18 ], [ %15, %13 ]
%27 = tail call i8* (...) @getbufend()
%28 = icmp ugt i8* %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i8* (...) @getbufend()
br label %31
31: ; preds = %29, %25
%32 = phi i8* [ %30, %29 ], [ %26, %25 ]
ret i8* %32
}