#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
void skip_lines(FILE *stream, int lines) {
  char *line = NULL;
  size_t n = 0;
  ssize_t bytes_read = 0;
  for (int i = 0; (i < lines) && (bytes_read >= 0); i++) {
    bytes_read = getline(&line, &n, stream);
    if (bytes_read == -1) {
      break;
    }
  }
  if (line != NULL) {
    free(line);
  }
  if (bytes_read == -1) {
    perror("tail");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<skip_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    118a <skip_lines+0x4a>
cmpq   $0x0,-0x28(%rbp)
setge  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    119a <skip_lines+0x5a>
jmp    11d2 <skip_lines+0x92>
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <getline@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    11bf <skip_lines+0x7f>
jmp    11d2 <skip_lines+0x92>
jmp    11c4 <skip_lines+0x84>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116e <skip_lines+0x2e>
cmpq   $0x0,-0x18(%rbp)
je     11e6 <skip_lines+0xa6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    1207 <skip_lines+0xc7>
lea    0xe08(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<skip_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
test   %esi,%esi
jle    11b9 <skip_lines+0x79>
mov    %esi,%r13d
mov    %rdi,%r14
mov    $0x1,%ebp
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <getline@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
je     11a4 <skip_lines+0x64>
cmp    %r13d,%ebp
jge    11a4 <skip_lines+0x64>
add    $0x1,%ebp
test   %rbx,%rbx
jns    1180 <skip_lines+0x40>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11b3 <skip_lines+0x73>
call   1030 <free@plt>
cmp    $0xffffffffffffffff,%rbx
je     11c8 <skip_lines+0x88>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe31(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"tail\00"
define void @skip_lines(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i8* null, i8** %5
store i64 0, i64* %6
store i64 0, i64* %7
store i32 0, i32* %8
br label %9
9: ; preds = %25, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i64, i64* %7
%15 = icmp sge i64 %14, 0
br label %16
16: ; preds = %13, %9
%17 = phi i1 [ false, %9 ], [ %15, %13 ]
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = load i32*, i32** %3
%20 = call i64 @getline(i8** %5, i64* %6, i32* %19)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
br label %28
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %9
28: ; preds = %23, %16
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %28
%35 = load i64, i64* %7
%36 = icmp eq i64 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"tail\00"
define void @skip_lines(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = icmp sgt i32 %1, 0
br i1 %7, label %12, label %27
8: ; preds = %12
%9 = icmp slt i32 %16, %1
%10 = icmp sgt i64 %14, -1
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %17
12: ; preds = %2, %8
%13 = phi i32 [ %16, %8 ], [ 0, %2 ]
%14 = call i64 @getline(i8** %3, i64* %4, i32* %0)
%15 = icmp eq i64 %14, -1
%16 = add nuw nsw i32 %13, 1
br i1 %15, label %17, label %8
17: ; preds = %8, %12
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @free(i8* %18)
br label %22
22: ; preds = %20, %17
%23 = icmp eq i64 %14, -1
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2, %22
ret void
}