#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 viewer {
  int dummy;
};
struct object {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bail(struct viewer *);
int data_left(struct object *, unsigned char const *);
int /*<<< orphan*/ diag(struct viewer *, int, char *, int, char *, int, char *);
void expect_data(struct viewer *viewer, struct object *object,
                 const unsigned char *start, int size) {
  int left = data_left(object, start);
  if (left < size) {
    diag(viewer, 0x1,
         "expecting to read %d byte%s, "
         "but object file has %d byte%s of data left to read",
         size, (size == 1) ? "" : "s", (left < 0) ? 0 : left,
         (left == 1) ? "" : "s");
    bail(viewer);
  }
}


x86 assembly (clang, -O0):
<expect_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <data_left@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ec <expect_data+0xbc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edx
lea    0xed5(%rip),%rax
lea    0xecd(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11a1 <expect_data+0x71>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a7 <expect_data+0x77>
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%r9d
mov    -0x20(%rbp),%esi
lea    0xe90(%rip),%rax
lea    0xe88(%rip),%rdx
cmp    $0x1,%esi
cmove  %rdx,%rax
mov    $0x1,%esi
lea    0xe26(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <diag@plt>
mov    -0x8(%rbp),%rdi
call   1050 <bail@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_data>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <data_left@plt>
cmp    %ebp,%eax
jge    1197 <expect_data+0x67>
cmp    $0x1,%ebp
lea    0xefe(%rip),%rcx
lea    0xef8(%rip),%rdx
mov    %rdx,%r8
cmove  %rcx,%r8
xor    %r9d,%r9d
test   %eax,%eax
cmovns %eax,%r9d
cmp    $0x1,%eax
cmove  %rcx,%rdx
mov    %rdx,(%rsp)
lea    0xe86(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%ecx
call   1030 <diag@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <bail@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.viewer = type { i32 }
%struct.object = type { i32 }
@.str = [80 x i8] c"expecting to read %d byte%s, but object file has %d byte%s of data left to read\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define void @expect_data(%struct.viewer* %0, %struct.object* %1, i8* %2, i32 %3) {
%5 = alloca %struct.viewer*
%6 = alloca %struct.object*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store %struct.viewer* %0, %struct.viewer** %5
store %struct.object* %1, %struct.object** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load %struct.object*, %struct.object** %6
%11 = load i8*, i8** %7
%12 = call i32 @data_left(%struct.object* %10, i8* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %37
16: ; preds = %4
%17 = load %struct.viewer*, %struct.viewer** %5
%18 = load i32, i32* %8
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %16
br label %28
26: ; preds = %16
%27 = load i32, i32* %9
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 0, %25 ], [ %27, %26 ]
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 1
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%34 = call i32 @diag(%struct.viewer* %17, i32 1, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %22, i32 %29, i8* %33)
%35 = load %struct.viewer*, %struct.viewer** %5
%36 = call i32 @bail(%struct.viewer* %35)
br label %37
37: ; preds = %28, %4
ret void
}

LLVM IR (-O2):
%struct.viewer = type { i32 }
%struct.object = type { i32 }
@.str = [80 x i8] c"expecting to read %d byte%s, but object file has %d byte%s of data left to read\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"s\00"
define void @expect_data(%struct.viewer* %0, %struct.object* %1, i8* %2, i32 %3) {
%5 = tail call i32 @data_left(%struct.object* %1, i8* %2)
%6 = icmp slt i32 %5, %3
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = icmp eq i32 %3, 1
%9 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%10 = icmp sgt i32 %5, 0
%11 = select i1 %10, i32 %5, i32 0
%12 = icmp eq i32 %5, 1
%13 = select i1 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%14 = tail call i32 @diag(%struct.viewer* %0, i32 1, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %9, i32 %11, i8* %13)
%15 = tail call i32 @bail(%struct.viewer* %0)
br label %16
16: ; preds = %7, %4
ret void
}