#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 /*<<< orphan*/ clean_stdin();
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int nRows(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int scanf(char *, int *, char *);
void printRow(FILE *f) {
  int rowSelected = -1, rowNum = nRows(f), read, currentRowCount = 0;
  char enter, c;
  while (rowSelected < 1) {
    printf("Insert row number to print: ");
    read = scanf("%d%c", &rowSelected, &enter);
    if (read != 2 || enter != '\n') {
      printf("Incorrect value, please try again.\n");
      clean_stdin();
      rowSelected = -1;
    } else if (rowSelected < 1 || rowSelected > rowNum) {
      printf("Value out of range, please try again.\n");
      rowSelected = -1;
    }
  }
  rewind(f);
  while (!feof(f) && currentRowCount < rowSelected - 1) {
    if (c == '\n') {
      ++currentRowCount;
    }
    c = fgetc(f);
  }
  while (!feof(f) && c != '\n') {
    putchar(c);
    c = fgetc(f);
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<printRow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <nRows@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    123c <printRow+0xbc>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x19(%rbp),%rdx
call   10a0 <scanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11ea <printRow+0x6a>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     1209 <printRow+0x89>
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <clean_stdin@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    1237 <printRow+0xb7>
cmpl   $0x1,-0xc(%rbp)
jl     121f <printRow+0x9f>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1232 <printRow+0xb2>
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    1237 <printRow+0xb7>
jmp    11a6 <printRow+0x26>
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b(%rbp)
jne    126f <printRow+0xef>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    127f <printRow+0xff>
jmp    12a6 <printRow+0x126>
movsbl -0x1a(%rbp),%eax
cmp    $0xa,%eax
jne    1295 <printRow+0x115>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1a(%rbp)
jmp    1245 <printRow+0xc5>
jmp    12ab <printRow+0x12b>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1c(%rbp)
jne    12d1 <printRow+0x151>
movsbl -0x1a(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1c(%rbp)
mov    -0x1c(%rbp),%al
test   $0x1,%al
jne    12e1 <printRow+0x161>
jmp    12fb <printRow+0x17b>
movsbl -0x1a(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1a(%rbp)
jmp    12ab <printRow+0x12b>
lea    0xd6b(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printRow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
movl   $0xffffffff,0x10(%rsp)
ff
call   10a0 <nRows@plt>
mov    %eax,0x14(%rsp)
lea    0xe47(%rip),%r12
lea    0xe5d(%rip),%r13
lea    0x10(%rsp),%rbx
lea    0xf(%rsp),%rbp
lea    0xe79(%rip),%r15
jmp    11f7 <printRow+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <clean_stdin@plt>
movl   $0xffffffff,0x10(%rsp)
ff
mov    %r12,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10b0 <scanf@plt>
cmp    $0x2,%eax
jne    11e0 <printRow+0x50>
cmpb   $0xa,0xf(%rsp)
jne    11e0 <printRow+0x50>
mov    0x10(%rsp),%eax
test   %eax,%eax
jle    1227 <printRow+0x97>
cmp    0x14(%rsp),%eax
jle    123d <printRow+0xad>
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,0x10(%rsp)
ff
jmp    11f7 <printRow+0x67>
mov    %r14,%rdi
call   1060 <rewind@plt>
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12ba <printRow+0x12a>
cmpl   $0x2,0x10(%rsp)
jl     12ba <printRow+0x12a>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cmp    $0xa,%r15b
sete   %r12b
mov    %r14,%rdi
call   1080 <fgetc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12ba <printRow+0x12a>
mov    %r12b,%bl
add    %ebx,%ebp
mov    0x10(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebp
jl     1260 <printRow+0xd0>
jmp    12ba <printRow+0x12a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%r15b
je     12c6 <printRow+0x136>
movsbl %r15b,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1080 <fgetc@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     12a0 <printRow+0x110>
lea    0xd55(%rip),%rdi
call   1040 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Insert row number to print: \00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [36 x i8] c"Incorrect value, please try again.\0A\00"
@.str.3 = [39 x i8] c"Value out of range, please try again.\0A\00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define void @printRow(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
store i32* %0, i32** %2
store i32 -1, i32* %3
%9 = load i32*, i32** %2
%10 = call i32 @nRows(i32* %9)
store i32 %10, i32* %4
store i32 0, i32* %6
br label %11
11: ; preds = %36, %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i8* %7)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 2
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i8, i8* %7
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %19, %14
%24 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 (...) @clean_stdin()
store i32 -1, i32* %3
br label %36
26: ; preds = %19
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29, %26
%34 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35, %23
br label %11
37: ; preds = %11
%38 = load i32*, i32** %2
%39 = call i32 @rewind(i32* %38)
br label %40
40: ; preds = %58, %37
%41 = load i32*, i32** %2
%42 = call i32 @feof(i32* %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %49, label %44
44: ; preds = %40
%45 = load i32, i32* %6
%46 = load i32, i32* %3
%47 = sub nsw i32 %46, 1
%48 = icmp slt i32 %45, %47
br label %49
49: ; preds = %44, %40
%50 = phi i1 [ false, %40 ], [ %48, %44 ]
br i1 %50, label %51, label %61
51: ; preds = %49
%52 = load i8, i8* %8
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %58
58: ; preds = %55, %51
%59 = load i32*, i32** %2
%60 = call signext i8 @fgetc(i32* %59)
store i8 %60, i8* %8
br label %40
61: ; preds = %49
br label %62
62: ; preds = %72, %61
%63 = load i32*, i32** %2
%64 = call i32 @feof(i32* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i8, i8* %8
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 10
br label %70
70: ; preds = %66, %62
%71 = phi i1 [ false, %62 ], [ %69, %66 ]
br i1 %71, label %72, label %77
72: ; preds = %70
%73 = load i8, i8* %8
%74 = call i32 @putchar(i8 signext %73)
%75 = load i32*, i32** %2
%76 = call signext i8 @fgetc(i32* %75)
store i8 %76, i8* %8
br label %62
77: ; preds = %70
%78 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Insert row number to print: \00"
@.str.1 = [5 x i8] c"%d%c\00"
@str = [2 x i8] c"\0A\00"
@str.5 = [38 x i8] c"Value out of range, please try again.\00"
@str.6 = [35 x i8] c"Incorrect value, please try again.\00"
define void @printRow(i32* %0) {
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = tail call i32 @nRows(i32* %0)
br label %6
6: ; preds = %23, %1
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i8* %3)
%9 = icmp ne i32 %8, 2
%10 = load i8, i8* %3
%11 = icmp ne i8 %10, 10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
%15 = call i32 (...) @clean_stdin()
br label %23
16: ; preds = %6
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 1
%19 = icmp sgt i32 %17, %5
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %13
store i32 -1, i32* %2
br label %6
24: ; preds = %16
%25 = call i32 @rewind(i32* %0)
%26 = call i32 @feof(i32* %0)
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 1
%30 = select i1 %27, i1 %29, i1 false
br i1 %30, label %37, label %31
31: ; preds = %37, %24
%32 = phi i8 [ undef, %24 ], [ %43, %37 ]
%33 = call i32 @feof(i32* %0)
%34 = icmp eq i32 %33, 0
%35 = icmp ne i8 %32, 10
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %50, label %58
37: ; preds = %24, %37
%38 = phi i8 [ %43, %37 ], [ undef, %24 ]
%39 = phi i32 [ %42, %37 ], [ 0, %24 ]
%40 = icmp eq i8 %38, 10
%41 = zext i1 %40 to i32
%42 = add nuw nsw i32 %39, %41
%43 = call signext i8 @fgetc(i32* %0)
%44 = call i32 @feof(i32* %0)
%45 = icmp eq i32 %44, 0
%46 = load i32, i32* %2
%47 = add nsw i32 %46, -1
%48 = icmp slt i32 %42, %47
%49 = select i1 %45, i1 %48, i1 false
br i1 %49, label %37, label %31
50: ; preds = %31, %50
%51 = phi i8 [ %53, %50 ], [ %32, %31 ]
%52 = call i32 @putchar(i8 signext %51)
%53 = call signext i8 @fgetc(i32* %0)
%54 = call i32 @feof(i32* %0)
%55 = icmp eq i32 %54, 0
%56 = icmp ne i8 %53, 10
%57 = and i1 %55, %56
br i1 %57, label %50, label %58
58: ; preds = %50, %31
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}