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

/* Variables and functions */
int /*<<< orphan*/ smm_errno_update(int);
scalar_t__ stat(char *, struct stat *);
long long smm_filesize(char *fname) {
  struct stat fs;
  if (fname == NULL) {
    return -1;
  }
  if (stat(fname, &fs) < 0) {
    smm_errno_update((0xC0000000 | (8)));
    return -1;
  }
  smm_errno_update(0);
  return (long long)fs.st_size;
}


x86 assembly (clang, -O0):
<smm_filesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <smm_filesize+0x24>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1181 <smm_filesize+0x61>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jge    1172 <smm_filesize+0x52>
mov    $0xc0000008,%edi
call   1040 <smm_errno_update@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1181 <smm_filesize+0x61>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smm_filesize>:
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffffffffffff,%rbx
test   %rdi,%rdi
je     1158 <smm_filesize+0x38>
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
js     114e <smm_filesize+0x2e>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
mov    0x8(%rsp),%rbx
jmp    1158 <smm_filesize+0x38>
mov    $0xc0000008,%edi
call   1040 <smm_errno_update@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
define i64 @smm_filesize(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i64 -1, i64* %2
br label %18
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @stat(i8* %9, %struct.stat* %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @smm_errno_update(i32 -1073741816)
store i64 -1, i64* %2
br label %18
14: ; preds = %8
%15 = call i32 @smm_errno_update(i32 0)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%17 = load i64, i64* %16
store i64 %17, i64* %2
br label %18
18: ; preds = %14, %12, %7
%19 = load i64, i64* %2
ret i64 %19
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i64 @smm_filesize(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = call i64 @stat(i8* %0, %struct.stat* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @smm_errno_update(i32 -1073741816)
br label %14
10: ; preds = %5
%11 = call i32 @smm_errno_update(i32 0)
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i64, i64* %12
br label %14
14: ; preds = %1, %10, %8
%15 = phi i64 [ -1, %8 ], [ %13, %10 ], [ -1, %1 ]
ret i64 %15
}