#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;
int ESPIPE;
int errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fprintf(int /*<<< orphan*/, char *, int const, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int pline(const int line, const char *path) {
  int c;
  int n;
  size_t len;
  char *s;
  FILE *fd;
  n = 1;
  s = NULL;
  fd = fopen(path, "r");
  if (!fd)
    return errno;
  while (line > n && (c = fgetc(fd)) != EOF)
    if (c == '\n')
      n++;
  if (line != n) {
    if (!errno) {
      return (errno = ESPIPE);
    } else {
      return errno;
    }
  }
  if (getline(&s, &len, fd) == -1)
    return errno;
  if (fprintf(stderr, "%d. %s", line, s) < 0)
    return errno;
  if (fclose(fd) != 0)
    return errno;
  return 0;
}


x86 assembly (clang, -O0):
<pline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119e <pline+0x4e>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
jmp    11a3 <pline+0x53>
mov    -0x8(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x31(%rbp)
jle    11cf <pline+0x7f>
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11df <pline+0x8f>
jmp    11f7 <pline+0xa7>
cmpl   $0xa,-0x14(%rbp)
jne    11f2 <pline+0xa2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <pline+0x53>
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     123e <pline+0xee>
mov    0x2dbe(%rip),%rax
cmpl   $0x0,(%rax)
jne    122d <pline+0xdd>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
mov    -0x30(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
jne    1269 <pline+0x119>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    0xd82(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jge    12a0 <pline+0x150>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     12c4 <pline+0x174>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12cb <pline+0x17b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rax
mov    %edi,%r14d
movq   $0x0,0x8(%rsp)
lea    0xe90(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     120c <pline+0xbc>
mov    %rax,%rbx
mov    $0x1,%ebp
cmp    $0x2,%r14d
jl     11bc <pline+0x6c>
mov    $0x1,%ebp
mov    0x2e4d(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
je     11bc <pline+0x6c>
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %ecx,%ebp
cmp    %r14d,%ebp
jl     11a0 <pline+0x50>
cmp    %r14d,%ebp
jne    1217 <pline+0xc7>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     120c <pline+0xbc>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rcx
lea    0xe15(%rip),%rsi
mov    %r14d,%edx
call   1050 <fprintf@plt>
test   %rax,%rax
js     120c <pline+0xbc>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     122f <pline+0xdf>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
jmp    122f <pline+0xdf>
mov    0x2daa(%rip),%rcx
mov    (%rcx),%eax
test   %eax,%eax
jne    122f <pline+0xdf>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@EOF = global i32 0
@ESPIPE = global i32 0
@stderr = global i32 0
@.str.1 = [7 x i8] c"%d. %s\00"
define i32 @pline(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 1, i32* %7
store i8* null, i8** %9
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = load i32, i32* @errno
store i32 %16, i32* %3
br label %68
17: ; preds = %2
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %7
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32*, i32** %10
%24 = call i32 @fgetc(i32* %23)
store i32 %24, i32* %6
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br label %27
27: ; preds = %22, %18
%28 = phi i1 [ false, %18 ], [ %26, %22 ]
br i1 %28, label %29, label %36
29: ; preds = %27
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %35
35: ; preds = %32, %29
br label %18
36: ; preds = %27
%37 = load i32, i32* %4
%38 = load i32, i32* %7
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i32, i32* @errno
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = load i32, i32* @ESPIPE
store i32 %44, i32* @errno
store i32 %44, i32* %3
br label %68
45: ; preds = %40
%46 = load i32, i32* @errno
store i32 %46, i32* %3
br label %68
47: ; preds = %36
%48 = load i32*, i32** %10
%49 = call i32 @getline(i8** %9, i64* %8, i32* %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i32, i32* @errno
store i32 %52, i32* %3
br label %68
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load i32, i32* %4
%56 = load i8*, i8** %9
%57 = call i64 @fprintf(i32 %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %55, i8* %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = load i32, i32* @errno
store i32 %60, i32* %3
br label %68
61: ; preds = %53
%62 = load i32*, i32** %10
%63 = call i64 @fclose(i32* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = load i32, i32* @errno
store i32 %66, i32* %3
br label %68
67: ; preds = %61
store i32 0, i32* %3
br label %68
68: ; preds = %67, %65, %59, %51, %45, %43, %15
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@EOF = global i32 0
@ESPIPE = global i32 0
@stderr = global i32 0
@.str.1 = [7 x i8] c"%d. %s\00"
define i32 @pline(i32 %0, i8* nocapture %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast i64* %3 to i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = icmp sgt i32 %0, 1
br i1 %10, label %13, label %23
11: ; preds = %2
%12 = load i32, i32* @errno
br label %48
13: ; preds = %9, %18
%14 = phi i32 [ %21, %18 ], [ 1, %9 ]
%15 = tail call i32 @fgetc(i32* %7)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = icmp eq i32 %15, 10
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %14, %20
%22 = icmp slt i32 %21, %0
br i1 %22, label %13, label %23
23: ; preds = %13, %18, %9
%24 = phi i32 [ 1, %9 ], [ %21, %18 ], [ %14, %13 ]
%25 = icmp eq i32 %24, %0
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i32, i32* @ESPIPE
store i32 %30, i32* @errno
br label %48
31: ; preds = %23
%32 = call i32 @getline(i8** %4, i64* %3, i32* %7)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32, i32* @errno
br label %48
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %4
%39 = call i64 @fprintf(i32 %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i32, i32* @errno
br label %48
43: ; preds = %36
%44 = call i64 @fclose(i32* %7)
%45 = icmp eq i64 %44, 0
%46 = load i32, i32* @errno
%47 = select i1 %45, i32 0, i32 %46
br label %48
48: ; preds = %43, %26, %41, %34, %29, %11
%49 = phi i32 [ %30, %29 ], [ %35, %34 ], [ %42, %41 ], [ %12, %11 ], [ %27, %26 ], [ %47, %43 ]
ret i32 %49
}