#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
void print_begin(FILE *fd, int line_pos) {
  int c, counter = 1;
  while ((c = fgetc(fd)) != EOF && counter < line_pos) {
    if (c == '\n')
      counter++;
  }
  do {
    printf("%c", c);
  } while ((c = fgetc(fd)) != EOF);
}


x86 assembly (clang, -O0):
<print_begin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e9b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x15(%rbp)
je     1164 <print_begin+0x44>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1174 <print_begin+0x54>
jmp    118c <print_begin+0x6c>
cmpl   $0xa,-0x10(%rbp)
jne    1187 <print_begin+0x67>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <print_begin+0x16>
jmp    1191 <print_begin+0x71>
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%eax
jne    1191 <print_begin+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_begin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r12
call   1040 <fgetc@plt>
mov    0x2eab(%rip),%r14
cmp    (%r14),%eax
je     1170 <print_begin+0x50>
cmp    $0x2,%r15d
jl     1170 <print_begin+0x50>
mov    $0x1,%ebp
nopl   (%rax)
xor    %ebx,%ebx
cmp    $0xa,%eax
sete   %r13b
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%eax
je     1170 <print_begin+0x50>
mov    %r13b,%bl
add    %ebx,%ebp
cmp    %r15d,%ebp
jl     1150 <print_begin+0x30>
lea    0xe89(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    (%r14),%eax
jne    1180 <print_begin+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"%c\00"
define void @print_begin(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %6
br label %7
7: ; preds = %24, %2
%8 = load i32*, i32** %3
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %21, %18
br label %7
25: ; preds = %16
br label %26
26: ; preds = %29, %25
%27 = load i32, i32* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26
%30 = load i32*, i32** %3
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %5
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %26, label %34
34: ; preds = %29
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"%c\00"
define void @print_begin(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp sgt i32 %1, 1
%7 = and i1 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ %3, %2 ]
%10 = phi i32 [ %13, %8 ], [ 1, %2 ]
%11 = icmp eq i32 %9, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %10, %12
%14 = tail call i32 @fgetc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
%17 = icmp slt i32 %13, %1
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %8, label %19
19: ; preds = %8, %2
%20 = phi i32 [ %3, %2 ], [ %14, %8 ]
br label %21
21: ; preds = %19, %21
%22 = phi i32 [ %24, %21 ], [ %20, %19 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = tail call i32 @fgetc(i32* %0)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %21
27: ; preds = %21
ret void
}