#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
unsigned int get_file_size(const char *FilePath) {
  FILE *file;
  unsigned int ret = 0;
  if (FilePath == NULL)
    return 0;
  file = fopen(FilePath, "r");
  if (file) {
    fseek(file, 0, SEEK_END);
    ret = ftell(file);
    rewind(file);
  }
  if (file)
    fclose(file);
  return ret;
}


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117a <get_file_size+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11dc <get_file_size+0x8c>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c2 <get_file_size+0x72>
mov    -0x18(%rbp),%rdi
mov    0x2e44(%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   1040 <rewind@plt>
cmpq   $0x0,-0x18(%rbp)
je     11d6 <get_file_size+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     119d <get_file_size+0x4d>
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119d <get_file_size+0x4d>
mov    %rax,%rbx
mov    0x2e75(%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   1040 <rewind@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    119f <get_file_size+0x4f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@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
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %30
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i32*, i32** %4
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %4
%19 = call i32 @ftell(i32* %18)
store i32 %19, i32* %5
%20 = load i32*, i32** %4
%21 = call i32 @rewind(i32* %20)
br label %22
22: ; preds = %14, %9
%23 = load i32*, i32** %4
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %8
%31 = load i32, i32* %2
ret i32 %31
}

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