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


x86 assembly (clang, -O0):
<escribir_reversa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1189 <escribir_reversa+0x59>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    11b1 <escribir_reversa+0x81>
mov    -0x8(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escribir_reversa>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdx),%esi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
cmpl   $0x0,(%r14)
je     117c <escribir_reversa+0x4c>
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xfffffffe,%esi
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
jmp    1181 <escribir_reversa+0x51>
mov    $0xffffffff,%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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