#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 */
struct test {
  int dummy;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ errno;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_abort(struct test *, char *, int /*<<< orphan*/);
int fd_has_data(struct test *test, int fd) {
  off_t pos = lseek(fd, 0, SEEK_END);
  if (pos < 0) {
    test_abort(test, "fd_has_data lseek error: %s", strerror(errno));
  }
  return pos;
}


x86 assembly (clang, -O0):
<fd_has_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1189 <fd_has_data+0x59>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe7c(%rip),%rsi
call   1040 <test_abort@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_has_data>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
mov    %esi,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1170 <fd_has_data+0x40>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9a(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1040 <test_abort@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.test = type { i32 }
@SEEK_END = global i32 0
@.str = [28 x i8] c"fd_has_data lseek error: %s\00"
@errno = global i32 0
define i32 @fd_has_data(%struct.test* %0, i32 %1) {
%3 = alloca %struct.test*
%4 = alloca i32
%5 = alloca i64
store %struct.test* %0, %struct.test** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* @SEEK_END
%8 = call i64 @lseek(i32 %6, i32 0, i32 %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load %struct.test*, %struct.test** %3
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 @test_abort(%struct.test* %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %11, %2
%17 = load i64, i64* %5
%18 = trunc i64 %17 to i32
ret i32 %18
}

LLVM IR (-O2):
%struct.test = type { i32 }
@SEEK_END = global i32 0
@.str = [28 x i8] c"fd_has_data lseek error: %s\00"
@errno = global i32 0
define i32 @fd_has_data(%struct.test* %0, i32 %1) {
%3 = load i32, i32* @SEEK_END
%4 = tail call i64 @lseek(i32 %1, i32 0, i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @test_abort(%struct.test* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6, %2
%11 = trunc i64 %4 to i32
ret i32 %11
}