#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
off_t tail_seek_prev(int fd, off_t *off_p, size_t *buf_size_p) {
  off_t new_off = *off_p - *buf_size_p;
  new_off = lseek(fd, new_off >= 0 ? new_off : 0, SEEK_SET);
  if (new_off != (off_t)-1) {
    *buf_size_p = *off_p - new_off;
    *off_p = new_off;
  }
  return new_off;
}


x86 assembly (clang, -O0):
<tail_seek_prev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1153 <tail_seek_prev+0x43>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    115e <tail_seek_prev+0x4e>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    115e <tail_seek_prev+0x4e>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     119f <tail_seek_prev+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
sub    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tail_seek_prev>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rsi),%rax
xor    %esi,%esi
sub    (%rdx),%rax
cmovns %rax,%rsi
mov    0x2eb3(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     1146 <tail_seek_prev+0x36>
mov    (%rbx),%rcx
sub    %rax,%rcx
mov    %rcx,(%r14)
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @tail_seek_prev(i32 %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64
store i32 %0, i32* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%8 = load i64*, i64** %5
%9 = load i64, i64* %8
%10 = load i64*, i64** %6
%11 = load i64, i64* %10
%12 = sub i64 %9, %11
store i64 %12, i64* %7
%13 = load i32, i32* %4
%14 = load i64, i64* %7
%15 = icmp sge i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i64, i64* %7
br label %19
18: ; preds = %3
br label %19
19: ; preds = %18, %16
%20 = phi i64 [ %17, %16 ], [ 0, %18 ]
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @lseek(i32 %13, i64 %20, i32 %21)
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = icmp ne i64 %23, -1
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = load i64*, i64** %5
%27 = load i64, i64* %26
%28 = load i64, i64* %7
%29 = sub nsw i64 %27, %28
%30 = load i64*, i64** %6
store i64 %29, i64* %30
%31 = load i64, i64* %7
%32 = load i64*, i64** %5
store i64 %31, i64* %32
br label %33
33: ; preds = %25, %19
%34 = load i64, i64* %7
ret i64 %34
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @tail_seek_prev(i32 %0, i64* nocapture %1, i64* nocapture %2) {
%4 = load i64, i64* %1
%5 = load i64, i64* %2
%6 = sub i64 %4, %5
%7 = icmp sgt i64 %6, 0
%8 = select i1 %7, i64 %6, i64 0
%9 = load i32, i32* @SEEK_SET
%10 = tail call i64 @lseek(i32 %0, i64 %8, i32 %9)
%11 = icmp eq i64 %10, -1
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i64, i64* %1
%14 = sub nsw i64 %13, %10
store i64 %14, i64* %2
store i64 %10, i64* %1
br label %15
15: ; preds = %12, %3
ret i64 %10
}