#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*/ DISPLAY(char *, char *);
int EOF;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long long ftello64(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int ungetc(int c, FILE *stream) {
  long long pos = ftello64(stream);
  if (pos == 0)
    return EOF;
  fseek(stream, -1, SEEK_CUR);
  if (c != getc(stream)) {
    DISPLAY("UNSUPPORTED", "ungetc does not return same char");
    return EOF;
  }
  fseek(stream, -1, SEEK_CUR);
  return c;
}


x86 assembly (clang, -O0):
<ungetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ftello64@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1178 <ungetc+0x38>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <ungetc+0xac>
mov    -0x10(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
je     11cf <ungetc+0x8f>
lea    0xe4e(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1050 <DISPLAY@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <ungetc+0xac>
mov    -0x10(%rbp),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ungetc>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <ftello64@plt>
test   %rax,%rax
je     119e <ungetc+0x5e>
mov    0x2e8b(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    %ebp,%eax
jne    118b <ungetc+0x4b>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
jmp    11a7 <ungetc+0x67>
lea    0xe6e(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1050 <DISPLAY@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@SEEK_CUR = global i32 0
@.str = [12 x i8] c"UNSUPPORTED\00"
@.str.1 = [33 x i8] c"ungetc does not return same char\00"
define i32 @ungetc(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
%8 = call i64 @ftello64(i32* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* @EOF
store i32 %12, i32* %3
br label %29
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = load i32, i32* @SEEK_CUR
%16 = call i32 @fseek(i32* %14, i32 -1, i32 %15)
%17 = load i32, i32* %4
%18 = load i32*, i32** %5
%19 = call i32 @getc(i32* %18)
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = call i32 @DISPLAY(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EOF
store i32 %23, i32* %3
br label %29
24: ; preds = %13
%25 = load i32*, i32** %5
%26 = load i32, i32* @SEEK_CUR
%27 = call i32 @fseek(i32* %25, i32 -1, i32 %26)
%28 = load i32, i32* %4
store i32 %28, i32* %3
br label %29
29: ; preds = %24, %21, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@EOF = global i32 0
@SEEK_CUR = global i32 0
@.str = [12 x i8] c"UNSUPPORTED\00"
@.str.1 = [33 x i8] c"ungetc does not return same char\00"
define i32 @ungetc(i32 %0, i32* nocapture %1) {
%3 = tail call i64 @ftello64(i32* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32, i32* @EOF
br label %18
7: ; preds = %2
%8 = load i32, i32* @SEEK_CUR
%9 = tail call i32 @fseek(i32* %1, i32 -1, i32 %8)
%10 = tail call i32 @getc(i32* %1)
%11 = icmp eq i32 %10, %0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @DISPLAY(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EOF
br label %18
15: ; preds = %7
%16 = load i32, i32* @SEEK_CUR
%17 = tail call i32 @fseek(i32* %1, i32 -1, i32 %16)
br label %18
18: ; preds = %15, %12, %5
%19 = phi i32 [ %6, %5 ], [ %14, %12 ], [ %0, %15 ]
ret i32 %19
}