#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 */

/* Variables and functions */
int /*<<< orphan*/ O_APPEND;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, char *);
long long lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
long long last_chunk_file(char *filename) {
  int file = open(filename, O_APPEND);
  long long pos = lseek(file, 0, SEEK_END);
  if (pos == -1) {
    fprintf(stderr, "error %d seeking file %s :%s\n", errno, filename,
            strerror(errno));
    return -1;
  }
  close(file);
  return pos;
}


x86 assembly (clang, -O0):
<last_chunk_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    11e7 <last_chunk_file+0x97>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11f7 <last_chunk_file+0xa7>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_chunk_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    0x2e77(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
je     118e <last_chunk_file+0x3e>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    11bf <last_chunk_file+0x6f>
mov    0x2e43(%rip),%rax
mov    (%rax),%r15d
mov    0x2e31(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xe51(%rip),%rsi
mov    %r15d,%edi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %rax,%r8
call   1050 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_APPEND = global i32 0
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"error %d seeking file %s :%s\0A\00"
@errno = global i32 0
define i64 @last_chunk_file(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_APPEND
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = load i32, i32* @SEEK_END
%11 = call i64 @lseek(i32 %9, i32 0, i32 %10)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = load i8*, i8** %3
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17, i8* %19)
store i64 -1, i64* %2
br label %25
21: ; preds = %1
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
%24 = load i64, i64* %5
store i64 %24, i64* %2
br label %25
25: ; preds = %21, %14
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
@O_APPEND = global i32 0
@SEEK_END = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"error %d seeking file %s :%s\0A\00"
@errno = global i32 0
define i64 @last_chunk_file(i8* %0) {
%2 = load i32, i32* @O_APPEND
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = load i32, i32* @SEEK_END
%5 = tail call i64 @lseek(i32 %3, i32 0, i32 %4)
%6 = icmp eq i64 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %0, i8* %10)
br label %14
12: ; preds = %1
%13 = tail call i32 @close(i32 %3)
br label %14
14: ; preds = %12, %7
ret i64 %5
}