#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int get_file_size(char *fname) {
  FILE *fp;
  int size;
  fp = fopen(fname, "rb");
  if (fp == NULL) {
    fprintf(stdout, "File %s Open Error : %s\n", fname, strerror(errno));
    return -1;
  }
  fseek(fp, 0, SEEK_END);
  size = ftell(fp);
  fclose(fp);
  return size;
}


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cf <get_file_size+0x6f>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <get_file_size+0x9e>
mov    -0x18(%rbp),%rdi
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a4 <get_file_size+0x44>
mov    %rax,%rbx
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    11d4 <get_file_size+0x74>
mov    0x2e25(%rip),%rax
mov    (%rax),%ebx
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe41(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.1 = [25 x i8] c"File %s Open Error : %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
define i32 @get_file_size(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* @stdout
%12 = load i8*, i8** %3
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %14)
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %4
%21 = call i32 @ftell(i32* %20)
store i32 %21, i32* %5
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %16, %10
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.1 = [25 x i8] c"File %s Open Error : %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
define i32 @get_file_size(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @stdout
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %7)
br label %14
9: ; preds = %1
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %2, i32 0, i32 %10)
%12 = tail call i32 @ftell(i32* %2)
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %9, %4
%15 = phi i32 [ -1, %4 ], [ %12, %9 ]
ret i32 %15
}