#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
void getSavedLogAt(FILE *fp, char *line, int position) {
  int cnt = 0;
  if (fp) {
    while ((cnt <= position) && fgets(line, 8192, fp)) {
      cnt++;
    }
    if (cnt <= position)
      *line = '\0';
  }
}


x86 assembly (clang, -O0):
<getSavedLogAt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119d <getSavedLogAt+0x8d>
jmp    113a <getSavedLogAt+0x2a>
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x19(%rbp)
jg     1167 <getSavedLogAt+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x2000,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1177 <getSavedLogAt+0x67>
jmp    1185 <getSavedLogAt+0x75>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <getSavedLogAt+0x2a>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1198 <getSavedLogAt+0x88>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    119d <getSavedLogAt+0x8d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSavedLogAt>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1150 <getSavedLogAt+0x40>
mov    %edx,%ebp
test   %edx,%edx
js     1150 <getSavedLogAt+0x40>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x2000,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     114c <getSavedLogAt+0x3c>
add    $0xffffffff,%ebp
jne    1130 <getSavedLogAt+0x20>
jmp    1150 <getSavedLogAt+0x40>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @getSavedLogAt(i32* %0, i8* %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp slt i32 %2, 0
%6 = or i1 %4, %5
br i1 %6, label %15, label %10
7: ; preds = %10
%8 = add nuw i32 %11, 1
%9 = icmp eq i32 %11, %2
br i1 %9, label %15, label %10
10: ; preds = %3, %7
%11 = phi i32 [ %8, %7 ], [ 0, %3 ]
%12 = tail call i64 @fgets(i8* %1, i32 8192, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %10
store i8 0, i8* %1
br label %15
15: ; preds = %7, %14, %3
ret void
}