#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int lseek(int, long, int /*<<< orphan*/);
int getFileStartAndLength(int fd, int *start_, size_t *length_) {
  int start, end;
  size_t length;
  start = lseek(fd, 0L, SEEK_CUR);
  end = lseek(fd, 0L, SEEK_END);
  if (start == -1 || end == -1)
    return -1;
  length = end - start;
  if (length == 0)
    return -1;
  *start_ = start;
  *length_ = length;
  return 0;
}


x86 assembly (clang, -O0):
<getFileStartAndLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb3(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <lseek@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <lseek@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
je     1167 <getFileStartAndLength+0x57>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1173 <getFileStartAndLength+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <getFileStartAndLength+0xa1>
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
cltq
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1196 <getFileStartAndLength+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <getFileStartAndLength+0xa1>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileStartAndLength>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %eax,%ebp
mov    0x2eb0(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ebp
je     1163 <getFileStartAndLength+0x53>
cmp    $0xffffffff,%ecx
je     1163 <getFileStartAndLength+0x53>
sub    %ebp,%ecx
je     1163 <getFileStartAndLength+0x53>
movslq %ecx,%rax
mov    %ebp,(%r15)
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
define i32 @getFileStartAndLength(i32 %0, i32* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = load i32, i32* @SEEK_CUR
%5 = tail call i32 @lseek(i32 %0, i64 0, i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @lseek(i32 %0, i64 0, i32 %6)
%8 = icmp eq i32 %5, -1
%9 = icmp eq i32 %7, -1
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = sub nsw i32 %7, %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = sext i32 %12 to i64
store i32 %5, i32* %1
store i64 %15, i64* %2
br label %16
16: ; preds = %11, %3, %14
%17 = phi i32 [ 0, %14 ], [ -1, %3 ], [ -1, %11 ]
ret i32 %17
}