#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
off_t get_file_size(int o) {
  off_t offset;
  int ret = 1;
  offset = lseek(o, 0, SEEK_END);
  if (offset < 0) {
    printf("ERROR: Failed to seek to end of file.");
    ret = 0;
  } else if (offset == 0) {
    printf("ERROR: File is empty.");
    ret = 0;
  }
  if (lseek(o, 0, SEEK_SET) != 0) {
    printf("ERROR: Failed to start of file.");
    ret = 0;
  }
  return ret ? offset : 0;
}


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    116c <get_file_size+0x4c>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    118f <get_file_size+0x6f>
cmpq   $0x0,-0x10(%rbp)
jne    118a <get_file_size+0x6a>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    118f <get_file_size+0x6f>
mov    -0x4(%rbp),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0x0,%rax
je     11bf <get_file_size+0x9f>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <get_file_size+0xb6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11e1 <get_file_size+0xc1>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    11e1 <get_file_size+0xc1>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ebc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
js     114a <get_file_size+0x2a>
je     1153 <get_file_size+0x33>
mov    %rax,%rbx
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
jmp    116a <get_file_size+0x4a>
lea    0xeaf(%rip),%rdi
jmp    115a <get_file_size+0x3a>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
test   %rax,%rax
je     1186 <get_file_size+0x66>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [38 x i8] c"ERROR: Failed to seek to end of file.\00"
@.str.1 = [22 x i8] c"ERROR: File is empty.\00"
@SEEK_SET = global i32 0
@.str.2 = [32 x i8] c"ERROR: Failed to start of file.\00"
define i64 @get_file_size(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
%5 = load i32, i32* %2
%6 = load i32, i32* @SEEK_END
%7 = call i64 @lseek(i32 %5, i32 0, i32 %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %18
12: ; preds = %1
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %17
17: ; preds = %15, %12
br label %18
18: ; preds = %17, %10
%19 = load i32, i32* %2
%20 = load i32, i32* @SEEK_SET
%21 = call i64 @lseek(i32 %19, i32 0, i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %25
25: ; preds = %23, %18
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i64, i64* %3
br label %31
30: ; preds = %25
br label %31
31: ; preds = %30, %28
%32 = phi i64 [ %29, %28 ], [ 0, %30 ]
ret i64 %32
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [38 x i8] c"ERROR: Failed to seek to end of file.\00"
@.str.1 = [22 x i8] c"ERROR: File is empty.\00"
@SEEK_SET = global i32 0
@.str.2 = [32 x i8] c"ERROR: Failed to start of file.\00"
define i64 @get_file_size(i32 %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i64 @lseek(i32 %0, i32 0, i32 %2)
%4 = icmp slt i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = icmp eq i64 %3, 0
br i1 %6, label %7, label %13
7: ; preds = %5, %1
%8 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %5 ]
%9 = tail call i32 @printf(i8* dereferenceable(1) %8)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i64 @lseek(i32 %0, i32 0, i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %17
13: ; preds = %5
%14 = load i32, i32* @SEEK_SET
%15 = tail call i64 @lseek(i32 %0, i32 0, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13, %7
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %13, %17, %7
%20 = phi i64 [ 0, %7 ], [ 0, %17 ], [ %3, %13 ]
ret i64 %20
}