#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int _get_length_file(void *arg) {
  FILE *f = (FILE *)arg;
  int res, pos, len = -1;
  pos = ftell(f);
  if (pos < 0)
    return -1;
  res = fseek(f, 0, SEEK_END);
  if (res >= 0) {
    len = ftell(f);
    fseek(f, pos, SEEK_SET);
  }
  return len;
}


x86 assembly (clang, -O0):
<_get_length_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    115d <_get_length_file+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <_get_length_file+0x85>
mov    -0x18(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     119f <_get_length_file+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_length_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <ftell@plt>
test   %eax,%eax
js     116c <_get_length_file+0x4c>
mov    %eax,%ebp
mov    0x2eaf(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
test   %eax,%eax
js     116c <_get_length_file+0x4c>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %eax,%r14d
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <fseek@plt>
mov    %r14d,%eax
jmp    1171 <_get_length_file+0x51>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @_get_length_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %4
store i32 -1, i32* %7
%10 = load i32*, i32** %4
%11 = call i32 @ftell(i32* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 -1, i32* %2
br label %30
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32*, i32** %4
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %7
%24 = load i32*, i32** %4
%25 = load i32, i32* %6
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %24, i32 %25, i32 %26)
br label %28
28: ; preds = %21, %15
%29 = load i32, i32* %7
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %14
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @_get_length_file(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call i32 @ftell(i32* %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %2, i32 0, i32 %6)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = tail call i32 @ftell(i32* %2)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %2, i32 %3, i32 %11)
br label %13
13: ; preds = %5, %9, %1
%14 = phi i32 [ -1, %1 ], [ %10, %9 ], [ -1, %5 ]
ret i32 %14
}