#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int leer_reversa(FILE *fp, int *seek) {
  fseek(fp, *seek, SEEK_SET);
  int c = fgetc(fp);
  if (*seek == 0) {
    *seek = -1;
  } else {
    fseek(fp, -2, SEEK_CUR);
    *seek = ftell(fp);
  }
  return c;
}


x86 assembly (clang, -O0):
<leer_reversa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1180 <leer_reversa+0x50>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    11a8 <leer_reversa+0x78>
mov    -0x8(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leer_reversa>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%esi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
cmpl   $0x0,(%r14)
je     117a <leer_reversa+0x4a>
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffe,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
jmp    117f <leer_reversa+0x4f>
mov    $0xffffffff,%eax
mov    %eax,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @leer_reversa(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @fseek(i32* %6, i32 %8, i32 %9)
%11 = load i32*, i32** %3
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %5
%13 = load i32*, i32** %4
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32*, i32** %4
store i32 -1, i32* %17
br label %25
18: ; preds = %2
%19 = load i32*, i32** %3
%20 = load i32, i32* @SEEK_CUR
%21 = call i32 @fseek(i32* %19, i32 -2, i32 %20)
%22 = load i32*, i32** %3
%23 = call i32 @ftell(i32* %22)
%24 = load i32*, i32** %4
store i32 %23, i32* %24
br label %25
25: ; preds = %18, %16
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define i32 @leer_reversa(i32* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %0, i32 %3, i32 %4)
%6 = tail call i32 @fgetc(i32* %0)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @SEEK_CUR
%11 = tail call i32 @fseek(i32* %0, i32 -2, i32 %10)
%12 = tail call i32 @ftell(i32* %0)
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ %12, %9 ], [ -1, %2 ]
store i32 %14, i32* %1
ret i32 %6
}