#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 find_next_in_filestream(int /*<<< orphan*/ *, char);
char *fs_first_line(int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int);
char *restrict fs_read_nth_line(FILE *file_stream, const int nth) {
  char *string;
  int current_line = 0;
  int char_offset = 0;
  while (current_line++ < nth &&
         (char_offset = find_next_in_filestream(file_stream, '\n') + 1) &&
         (fseek(file_stream, char_offset, 1) != -1))
    ;
  string = fs_first_line(file_stream);
  return string;
}


x86 assembly (clang, -O0):
<fs_read_nth_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    11a4 <fs_read_nth_line+0x74>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1050 <find_next_in_filestream@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11a4 <fs_read_nth_line+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b4 <fs_read_nth_line+0x84>
jmp    11b9 <fs_read_nth_line+0x89>
jmp    114d <fs_read_nth_line+0x1d>
mov    -0x8(%rbp),%rdi
call   1030 <fs_first_line@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_read_nth_line>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
test   %esi,%esi
cmovg  %esi,%ebp
add    $0x1,%ebp
add    $0xffffffff,%ebp
je     116a <fs_read_nth_line+0x3a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <find_next_in_filestream@plt>
inc    %eax
je     116a <fs_read_nth_line+0x3a>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1040 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1140 <fs_read_nth_line+0x10>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fs_first_line@plt>

LLVM IR (-O0):
define i8* @fs_read_nth_line(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %6
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32*, i32** %3
%15 = call i32 @find_next_in_filestream(i32* %14, i8 signext 10)
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i32*, i32** %3
%20 = load i32, i32* %7
%21 = call i32 @fseek(i32* %19, i32 %20, i32 1)
%22 = icmp ne i32 %21, -1
br label %23
23: ; preds = %18, %13, %8
%24 = phi i1 [ false, %13 ], [ false, %8 ], [ %22, %18 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %8
26: ; preds = %23
%27 = load i32*, i32** %3
%28 = call i8* @fs_first_line(i32* %27)
store i8* %28, i8** %5
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
define i8* @fs_read_nth_line(i32* %0, i32 %1) {
%3 = call i32 @llvm.smax.i32(i32 %1, i32 0)
br label %4
4: ; preds = %12, %2
%5 = phi i32 [ 0, %2 ], [ %6, %12 ]
%6 = add nuw i32 %5, 1
%7 = icmp eq i32 %5, %3
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = tail call i32 @find_next_in_filestream(i32* %0, i8 signext 10)
%10 = add nsw i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @fseek(i32* %0, i32 %10, i32 1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %4
15: ; preds = %4, %8, %12
%16 = tail call i8* @fs_first_line(i32* %0)
ret i8* %16
}