#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
scalar_t__ lseek(int, int, int /*<<< orphan*/);
int write(int, int *, int);
int write_header_back(int fd, uint8_t *header_buffer) {
  int seek_back = header_buffer[8] + 2;
  if (lseek(fd, -seek_back, SEEK_CUR) < 0)
    return 0;
  int r = write(fd, header_buffer + 7, seek_back);
  return r - 2;
}


x86 assembly (clang, -O0):
<write_header_back>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
sub    -0x14(%rbp),%esi
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    1168 <write_header_back+0x48>
movl   $0x0,-0x4(%rbp)
jmp    1187 <write_header_back+0x67>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x1c,%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_header_back>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x20(%rsi),%ebp
mov    $0xfffffffe,%esi
sub    %ebp,%esi
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
test   %rax,%rax
js     1160 <write_header_back+0x40>
add    $0x2,%ebp
add    $0x1c,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
add    $0xfffffffe,%eax
jmp    1162 <write_header_back+0x42>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @write_header_back(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = getelementptr inbounds i32, i32* %8, i64 8
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 2
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = load i32, i32* %6
%14 = sub nsw i32 0, %13
%15 = load i32, i32* @SEEK_CUR
%16 = call i64 @lseek(i32 %12, i32 %14, i32 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 0, i32* %3
br label %27
19: ; preds = %2
%20 = load i32, i32* %4
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 7
%23 = load i32, i32* %6
%24 = call i32 @write(i32 %20, i32* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 2
store i32 %26, i32* %3
br label %27
27: ; preds = %19, %18
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @write_header_back(i32 %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 8
%4 = load i32, i32* %3
%5 = sub i32 -2, %4
%6 = load i32, i32* @SEEK_CUR
%7 = tail call i64 @lseek(i32 %0, i32 %5, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = add nsw i32 %4, 2
%11 = getelementptr inbounds i32, i32* %1, i64 7
%12 = tail call i32 @write(i32 %0, i32* %11, i32 %10)
%13 = add nsw i32 %12, -2
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ %13, %9 ], [ 0, %2 ]
ret i32 %15
}