#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 */
struct stat {
  unsigned long st_size;
};

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char const *, struct stat *);
unsigned long get_file_size(const char *pFile) {
  if (0 != access(pFile, R_OK)) {
    printf("file [%s] not exists\n", pFile);
    return 0;
  }
  struct stat s;
  if (stat(pFile, &s) < 0) {
    printf("stat file faild\n");
    return 0;
  }
  return s.st_size;
}


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     117b <get_file_size+0x4b>
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <get_file_size+0x85>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11ad <get_file_size+0x7d>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <get_file_size+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
je     1170 <get_file_size+0x30>
lea    0xe9f(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1195 <get_file_size+0x55>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     1186 <get_file_size+0x46>
mov    (%rsp),%r14
jmp    1195 <get_file_size+0x55>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@R_OK = global i32 0
@.str = [22 x i8] c"file [%s] not exists\0A\00"
@.str.1 = [17 x i8] c"stat file faild\0A\00"
define i64 @get_file_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @R_OK
%7 = call i64 @access(i8* %5, i32 %6)
%8 = icmp ne i64 0, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
store i64 0, i64* %2
br label %21
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @stat(i8* %13, %struct.stat* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %2
br label %21
18: ; preds = %12
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i64, i64* %19
store i64 %20, i64* %2
br label %21
21: ; preds = %18, %16, %9
%22 = load i64, i64* %2
ret i64 %22
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@R_OK = global i32 0
@.str = [22 x i8] c"file [%s] not exists\0A\00"
@str = [16 x i8] c"stat file faild\00"
define i64 @get_file_size(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @R_OK
%4 = tail call i64 @access(i8* %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
8: ; preds = %1
%9 = bitcast %struct.stat* %2 to i8*
%10 = call i64 @stat(i8* %0, %struct.stat* %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %17
14: ; preds = %8
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i64, i64* %15
br label %17
17: ; preds = %14, %12
%18 = phi i64 [ 0, %12 ], [ %16, %14 ]
br label %19
19: ; preds = %17, %6
%20 = phi i64 [ 0, %6 ], [ %18, %17 ]
ret i64 %20
}