#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*/ SEEK_SET;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ read(int, char *, int);
void print_line(int line, int size, int *table, int fd) {
  if (line > size - 1) {
    printf("Sorry text has no %dth line. \n", line);
  } else {
    int len = table[line] - table[line - 1] + 1;
    char *str = (char *)malloc(sizeof(char) * len);
    lseek(fd, table[line - 1], SEEK_SET);
    read(fd, str, len);
    str[len - 1] = '\0';
    printf("%d: %s", line, str);
    free(str);
  }
}


x86 assembly (clang, -O0):
<print_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    118c <print_line+0x3c>
mov    -0x4(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121f <print_line+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
sub    (%rcx,%rdx,4),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <read@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
cmp    %edi,%esi
jle    11da <print_line+0x8a>
mov    %ecx,%r14d
mov    %rdx,%rbp
movslq %r13d,%rbx
movslq (%rdx,%rbx,4),%r15
movslq -0x4(%rdx,%rbx,4),%rax
sub    %rax,%r15
lea    0x1(%r15),%edi
mov    %edi,0x4(%rsp)
call   1070 <malloc@plt>
mov    %rax,%r12
mov    -0x4(%rbp,%rbx,4),%esi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
call   1050 <lseek@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    0x4(%rsp),%edx
call   1060 <read@plt>
movb   $0x0,(%r12,%r15,1)
lea    0xe68(%rip),%rdi
mov    %r13d,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xe1f(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Sorry text has no %dth line. \0A\00"
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"%d: %s\00"
define void @print_line(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = icmp sgt i32 %11, %13
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i32, i32* %5
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %61
18: ; preds = %4
%19 = load i32*, i32** %7
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %7
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %24, i64 %27
%29 = load i32, i32* %28
%30 = sub nsw i32 %23, %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %10
%38 = load i32, i32* %8
%39 = load i32*, i32** %7
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* @SEEK_SET
%46 = call i32 @lseek(i32 %38, i32 %44, i32 %45)
%47 = load i32, i32* %8
%48 = load i8*, i8** %10
%49 = load i32, i32* %9
%50 = call i32 @read(i32 %47, i8* %48, i32 %49)
%51 = load i8*, i8** %10
%52 = load i32, i32* %9
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 0, i8* %55
%56 = load i32, i32* %5
%57 = load i8*, i8** %10
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %56, i8* %57)
%59 = load i8*, i8** %10
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %18, %15
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Sorry text has no %dth line. \0A\00"
@SEEK_SET = global i32 0
@.str.1 = [7 x i8] c"%d: %s\00"
define void @print_line(i32 %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %1, %0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %28
8: ; preds = %4
%9 = sext i32 %0 to i64
%10 = getelementptr inbounds i32, i32* %2, i64 %9
%11 = load i32, i32* %10
%12 = add nsw i32 %0, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %2, i64 %13
%15 = load i32, i32* %14
%16 = sub nsw i32 %11, %15
%17 = add nsw i32 %16, 1
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = load i32, i32* %14
%21 = load i32, i32* @SEEK_SET
%22 = tail call i32 @lseek(i32 %3, i32 %20, i32 %21)
%23 = tail call i32 @read(i32 %3, i8* %19, i32 %17)
%24 = sext i32 %16 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
store i8 0, i8* %25
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %19)
%27 = tail call i32 @free(i8* %19)
br label %28
28: ; preds = %8, %6
ret void
}