#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 buffer {
  int dummy;
};

/* Variables and functions */
size_t buffer_size(struct buffer const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, size_t,
                           size_t, size_t);
int /*<<< orphan*/ stderr;
int check_size(const struct buffer *b, size_t offset, size_t size,
               const char *desc) {
  if (size == 0)
    return 0;
  if (offset >= buffer_size(b) || (offset + size) > buffer_size(b)) {
    {
      fprintf(stderr,
              "E: "
              "The file is not large enough for the '%s'. "
              "%ld bytes @ offset %zu, input %zu bytes.\n",
              desc, size, offset, buffer_size(b));
    };
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114f <check_size+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <check_size+0xd3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <buffer_size@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jae    1195 <check_size+0x75>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <buffer_size@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jbe    11ec <check_size+0xcc>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <buffer_size@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    %rax,%r9
lea    0xe25(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <check_size+0xd3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdx,%rdx
je     1189 <check_size+0x69>
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <buffer_size@plt>
cmp    %r14,%rax
jbe    1159 <check_size+0x39>
lea    (%r12,%r14,1),%r13
mov    %rbx,%rdi
call   1040 <buffer_size@plt>
cmp    %rax,%r13
jbe    1189 <check_size+0x69>
mov    0x2e80(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <buffer_size@plt>
lea    0xe8f(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %rax,%r9
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
@stderr = global i32 0
@.str = [88 x i8] c"E: The file is not large enough for the '%s'. %ld bytes @ offset %zu, input %zu bytes.\0A\00"
define i32 @check_size(%struct.buffer* %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.buffer*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store %struct.buffer* %0, %struct.buffer** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
%10 = load i64, i64* %8
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %4
store i32 0, i32* %5
br label %34
13: ; preds = %4
%14 = load i64, i64* %7
%15 = load %struct.buffer*, %struct.buffer** %6
%16 = call i64 @buffer_size(%struct.buffer* %15)
%17 = icmp uge i64 %14, %16
br i1 %17, label %25, label %18
18: ; preds = %13
%19 = load i64, i64* %7
%20 = load i64, i64* %8
%21 = add i64 %19, %20
%22 = load %struct.buffer*, %struct.buffer** %6
%23 = call i64 @buffer_size(%struct.buffer* %22)
%24 = icmp ugt i64 %21, %23
br i1 %24, label %25, label %33
25: ; preds = %18, %13
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %9
%28 = load i64, i64* %8
%29 = load i64, i64* %7
%30 = load %struct.buffer*, %struct.buffer** %6
%31 = call i64 @buffer_size(%struct.buffer* %30)
%32 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0), i8* %27, i64 %28, i64 %29, i64 %31)
store i32 -1, i32* %5
br label %34
33: ; preds = %18
store i32 0, i32* %5
br label %34
34: ; preds = %33, %25, %12
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@stderr = global i32 0
@.str = [88 x i8] c"E: The file is not large enough for the '%s'. %ld bytes @ offset %zu, input %zu bytes.\0A\00"
define i32 @check_size(%struct.buffer* %0, i64 %1, i64 %2, i8* %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = tail call i64 @buffer_size(%struct.buffer* %0)
%8 = icmp ugt i64 %7, %1
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = add i64 %2, %1
%11 = tail call i64 @buffer_size(%struct.buffer* %0)
%12 = icmp ugt i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9, %6
%14 = load i32, i32* @stderr
%15 = tail call i64 @buffer_size(%struct.buffer* %0)
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %2, i64 %1, i64 %15)
br label %17
17: ; preds = %9, %4, %13
%18 = phi i32 [ -1, %13 ], [ 0, %4 ], [ 0, %9 ]
ret i32 %18
}