#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;
char fgetc(int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char ar_peek(FILE *f) {
  char c = fgetc(f);
  int retval = fseek(f, -1, SEEK_CUR);
  if (retval == 0) {
    printf("Peeked: %d\n", c);
    return c;
  } else {
    printf("Peek error.\n");
    return -1;
  }
}


x86 assembly (clang, -O0):
<ar_peek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <fseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1189 <ar_peek+0x59>
movsbl -0x11(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x11(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    119b <ar_peek+0x6b>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ar_peek>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
test   %eax,%eax
je     1178 <ar_peek+0x38>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xff,%bpl
jmp    118a <ar_peek+0x4a>
movsbl %bpl,%esi
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@.str = [12 x i8] c"Peeked: %d\0A\00"
@.str.1 = [13 x i8] c"Peek error.\0A\00"
define signext i8 @ar_peek(i32* %0) {
%2 = alloca i8
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call signext i8 @fgetc(i32* %6)
store i8 %7, i8* %4
%8 = load i32*, i32** %3
%9 = load i32, i32* @SEEK_CUR
%10 = call i32 @fseek(i32* %8, i32 -1, i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8, i8* %4
store i8 %17, i8* %2
br label %20
18: ; preds = %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8 -1, i8* %2
br label %20
20: ; preds = %18, %13
%21 = load i8, i8* %2
ret i8 %21
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@.str = [12 x i8] c"Peeked: %d\0A\00"
@str = [12 x i8] c"Peek error.\00"
define signext i8 @ar_peek(i32* nocapture %0) {
%2 = tail call signext i8 @fgetc(i32* %0)
%3 = load i32, i32* @SEEK_CUR
%4 = tail call i32 @fseek(i32* %0, i32 -1, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = sext i8 %2 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %11
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = phi i8 [ %2, %6 ], [ -1, %9 ]
ret i8 %12
}