#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 {
  int st_mode;
  scalar_t__ st_size;
};

/* Variables and functions */
int S_IFDIR;
int S_IFMT;
int stat(char *, struct stat *);
int GetSizeFile(char *filename) {
  struct stat buf;
  if (stat(filename, &buf) == -1) {
    return (-1);
  }
  if ((buf.st_mode & S_IFMT) == S_IFDIR)
    return -1;
  return (int)buf.st_size;
}


x86 assembly (clang, -O0):
<GetSizeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    113e <GetSizeFile+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    116c <GetSizeFile+0x5c>
mov    -0x20(%rbp),%eax
mov    0x2e98(%rip),%rcx
and    (%rcx),%eax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
jne    1165 <GetSizeFile+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    116c <GetSizeFile+0x5c>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetSizeFile>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ecx
je     1146 <GetSizeFile+0x36>
mov    0x2eaf(%rip),%rcx
mov    (%rcx),%ecx
and    0x8(%rsp),%ecx
mov    0x2e92(%rip),%rdx
cmp    (%rdx),%ecx
je     1146 <GetSizeFile+0x36>
mov    0x10(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
define i32 @GetSizeFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @stat(i8* %5, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %21
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IFMT
%13 = and i32 %11, %12
%14 = load i32, i32* @S_IFDIR
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 -1, i32* %2
br label %21
17: ; preds = %9
%18 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %16, %8
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
define i32 @GetSizeFile(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @S_IFMT
%10 = and i32 %9, %8
%11 = load i32, i32* @S_IFDIR
%12 = icmp eq i32 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %6
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %6, %1, %13
%18 = phi i32 [ %16, %13 ], [ -1, %1 ], [ -1, %6 ]
ret i32 %18
}