#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__ const st_size;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int check_size(const char *filename, const off_t size) {
  struct stat statbuf;
  if (stat(filename, &statbuf) < 0) {
    fprintf(stderr, "stat failed on %s: %s\n", filename, strerror(errno));
    return (-1);
  }
  if (statbuf.st_size != size) {
    return (-2);
  }
  return (0);
}


x86 assembly (clang, -O0):
<check_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    119b <check_size+0x6b>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <check_size+0x8c>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11b5 <check_size+0x85>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11bc <check_size+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     115e <check_size+0x2e>
xor    %eax,%eax
cmp    %r14,0x8(%rsp)
sete   %al
add    %eax,%eax
add    $0xfffffffe,%eax
jmp    118e <check_size+0x5e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ebp
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe84(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i64 }
@stderr = global i32 0
@.str = [23 x i8] c"stat failed on %s: %s\0A\00"
@errno = global i32 0
define i32 @check_size(i8* %0, i64 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @stat(i8* %0, %struct.stat* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
br label %17
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %1
%16 = select i1 %15, i32 0, i32 -2
br label %17
17: ; preds = %12, %7
%18 = phi i32 [ -1, %7 ], [ %16, %12 ]
ret i32 %18
}