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

/* Variables and functions */
int /*<<< orphan*/ abort();
int fstat(int, struct stat *);
int /*<<< orphan*/ printf(char *, long long, ...);
void mfd_assert_size(int fd, size_t size) {
  struct stat st;
  int r;
  r = fstat(fd, &st);
  if (r < 0) {
    printf("fstat(%d) failed: %m\n", fd);
    abort();
  } else if (st.st_size != size) {
    printf("wrong file size %lld, but expected %lld\n", (long long)st.st_size,
           (long long)size);
    abort();
  }
}


x86 assembly (clang, -O0):
<mfd_assert_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1171 <mfd_assert_size+0x41>
movslq -0x4(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     119c <mfd_assert_size+0x6c>
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11a1 <mfd_assert_size+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_assert_size>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rsi
call   1050 <fstat@plt>
test   %eax,%eax
js     1154 <mfd_assert_size+0x24>
mov    (%rsp),%rsi
cmp    %rbx,%rsi
jne    116c <mfd_assert_size+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
movslq %ebp,%rsi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xea3(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [22 x i8] c"fstat(%d) failed: %m\0A\00"
@.str.1 = [41 x i8] c"wrong file size %lld, but expected %lld\0A\00"
define void @mfd_assert_size(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca %struct.stat
%6 = alloca i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i32, i32* %3
%8 = call i32 @fstat(i32 %7, %struct.stat* %5)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* %4
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load i64, i64* %4
%25 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %24)
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %16
br label %28
28: ; preds = %27
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [22 x i8] c"fstat(%d) failed: %m\0A\00"
@.str.1 = [41 x i8] c"wrong file size %lld, but expected %lld\0A\00"
define void @mfd_assert_size(i32 %0, i64 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @fstat(i32 %0, %struct.stat* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = sext i32 %0 to i64
%9 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, %1
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i64 %13, i64 %1)
%17 = tail call i32 (...) @abort()
unreachable
18: ; preds = %11
ret void
}