#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int nRows(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int scanf(char *, int *, char *);
void printRow() {
  FILE *f;
  f = fopen("car.txt", "r");
  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;
    }
  }
  fclose(f);
  f = fopen("car.txt", "r");
  while (!feof(f) && currentRowCount < rowSelected - 1) {
    if (c == '\n') {
      ++currentRowCount;
    }
    c = fgetc(f);
  }
  while (!feof(f) && c != '\n') {
    putchar(c);
    c = fgetc(f);
  }
  fclose(f);
  printf("\n\n");
}


x86 assembly (clang, -O0):
<printRow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
lea    0xe62(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-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    125f <printRow+0xcf>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
lea    0xe41(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x19(%rbp),%rdx
call   10a0 <scanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    120d <printRow+0x7d>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     122c <printRow+0x9c>
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <clean_stdin@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    125a <printRow+0xca>
cmpl   $0x1,-0xc(%rbp)
jl     1242 <printRow+0xb2>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1255 <printRow+0xc5>
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    125a <printRow+0xca>
jmp    11c9 <printRow+0x39>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd91(%rip),%rdi
lea    0xd92(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b(%rbp)
jne    12a9 <printRow+0x119>
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    12b9 <printRow+0x129>
jmp    12e0 <printRow+0x150>
movsbl -0x1a(%rbp),%eax
cmp    $0xa,%eax
jne    12cf <printRow+0x13f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1a(%rbp)
jmp    127f <printRow+0xef>
jmp    12e5 <printRow+0x155>
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1c(%rbp)
jne    130b <printRow+0x17b>
movsbl -0x1a(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1c(%rbp)
mov    -0x1c(%rbp),%al
test   $0x1,%al
jne    131b <printRow+0x18b>
jmp    1335 <printRow+0x1a5>
movsbl -0x1a(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1a(%rbp)
jmp    12e5 <printRow+0x155>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd32(%rip),%rdi
call   1050 <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
lea    0xe4b(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   10c0 <fopen@plt>
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
call   10a0 <nRows@plt>
mov    %eax,0xc(%rsp)
lea    0xe29(%rip),%r12
lea    0xe3f(%rip),%r13
lea    0x8(%rsp),%rbx
lea    0x7(%rsp),%rbp
lea    0xe5b(%rip),%r14
lea    0xe2e(%rip),%r15
jmp    1227 <printRow+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <clean_stdin@plt>
movl   $0xffffffff,0x8(%rsp)
ff
mov    %r12,%rdi
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10b0 <scanf@plt>
cmp    $0x2,%eax
jne    1210 <printRow+0x70>
cmpb   $0xa,0x7(%rsp)
jne    1210 <printRow+0x70>
mov    0x8(%rsp),%eax
test   %eax,%eax
jle    1257 <printRow+0xb7>
cmp    0xc(%rsp),%eax
jle    1269 <printRow+0xc9>
mov    %r15,%rdi
call   1040 <puts@plt>
movl   $0xffffffff,0x8(%rsp)
ff
jmp    1227 <printRow+0x87>
mov    0x10(%rsp),%rdi
call   1050 <fclose@plt>
lea    0xd86(%rip),%rdi
lea    0xd87(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12fa <printRow+0x15a>
cmpl   $0x2,0x8(%rsp)
jl     12fa <printRow+0x15a>
xor    %ebp,%ebp
xchg   %ax,%ax
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    12fa <printRow+0x15a>
mov    %r12b,%bl
add    %ebx,%ebp
mov    0x8(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebp
jl     12a0 <printRow+0x100>
jmp    12fa <printRow+0x15a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xa,%r15b
je     1306 <printRow+0x166>
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     12e0 <printRow+0x140>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xd17(%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 = [8 x i8] c"car.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Insert row number to print: \00"
@.str.3 = [5 x i8] c"%d%c\00"
@.str.4 = [36 x i8] c"Incorrect value, please try again.\0A\00"
@.str.5 = [39 x i8] c"Value out of range, please try again.\0A\00"
@.str.6 = [3 x i8] c"\0A\0A\00"
define void @printRow() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %1
store i32 -1, i32* %2
%9 = load i32*, i32** %1
%10 = call i32 @nRows(i32* %9)
store i32 %10, i32* %3
store i32 0, i32* %5
br label %11
11: ; preds = %36, %0
%12 = load i32, i32* %2
%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.2, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %2, i8* %6)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i8, i8* %6
%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.4, i64 0, i64 0))
%25 = call i32 (...) @clean_stdin()
store i32 -1, i32* %2
br label %36
26: ; preds = %19
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%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.5, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
35: ; preds = %33, %29
br label %36
36: ; preds = %35, %23
br label %11
37: ; preds = %11
%38 = load i32*, i32** %1
%39 = call i32 @fclose(i32* %38)
%40 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %1
br label %41
41: ; preds = %59, %37
%42 = load i32*, i32** %1
%43 = call i32 @feof(i32* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %41
%46 = load i32, i32* %5
%47 = load i32, i32* %2
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br label %50
50: ; preds = %45, %41
%51 = phi i1 [ false, %41 ], [ %49, %45 ]
br i1 %51, label %52, label %62
52: ; preds = %50
%53 = load i8, i8* %7
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %59
59: ; preds = %56, %52
%60 = load i32*, i32** %1
%61 = call signext i8 @fgetc(i32* %60)
store i8 %61, i8* %7
br label %41
62: ; preds = %50
br label %63
63: ; preds = %73, %62
%64 = load i32*, i32** %1
%65 = call i32 @feof(i32* %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %63
%68 = load i8, i8* %7
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 10
br label %71
71: ; preds = %67, %63
%72 = phi i1 [ false, %63 ], [ %70, %67 ]
br i1 %72, label %73, label %78
73: ; preds = %71
%74 = load i8, i8* %7
%75 = call i32 @putchar(i8 signext %74)
%76 = load i32*, i32** %1
%77 = call signext i8 @fgetc(i32* %76)
store i8 %77, i8* %7
br label %63
78: ; preds = %71
%79 = load i32*, i32** %1
%80 = call i32 @fclose(i32* %79)
%81 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
ret void
}

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