#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int file_size(int /*<<< orphan*/ *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
long ftell(int /*<<< orphan*/ *);
int check_remainder(FILE *infile) {
  int start_address;
  unsigned char byte;
  long offset;
  if (fread(&byte, 1, 1, infile) < 1)
    return 0;
  start_address = byte;
  if (fread(&byte, 1, 1, infile) < 1)
    return 0;
  start_address += byte * 256;
  offset = ftell(infile);
  if ((file_size(infile) + start_address - offset) > 65536)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_remainder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jge    1165 <check_remainder+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <check_remainder+0xb0>
movzbl -0x15(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jge    1195 <check_remainder+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <check_remainder+0xb0>
movzbl -0x15(%rbp),%eax
shl    $0x8,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <file_size@plt>
add    -0x14(%rbp),%eax
cltq
sub    -0x20(%rbp),%rax
cmp    $0x10000,%rax
jle    11d9 <check_remainder+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <check_remainder+0xb0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_remainder>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    11aa <check_remainder+0x7a>
movzbl 0xf(%rsp),%r14d
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11aa <check_remainder+0x7a>
movzbl 0xf(%rsp),%ebp
shl    $0x8,%ebp
or     %r14d,%ebp
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <file_size@plt>
add    %ebp,%eax
cltq
sub    %r14,%rax
xor    %ebp,%ebp
cmp    $0x10001,%rax
setl   %bpl
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_remainder(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i64
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %7)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %36
11: ; preds = %1
%12 = load i8, i8* %5
%13 = zext i8 %12 to i32
store i32 %13, i32* %4
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 0, i32* %2
br label %36
18: ; preds = %11
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = mul nsw i32 %20, 256
%22 = load i32, i32* %4
%23 = add nsw i32 %22, %21
store i32 %23, i32* %4
%24 = load i32*, i32** %3
%25 = call i64 @ftell(i32* %24)
store i64 %25, i64* %6
%26 = load i32*, i32** %3
%27 = call i32 @file_size(i32* %26)
%28 = load i32, i32* %4
%29 = add nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = load i64, i64* %6
%32 = sub nsw i64 %30, %31
%33 = icmp sgt i64 %32, 65536
br i1 %33, label %34, label %35
34: ; preds = %18
store i32 0, i32* %2
br label %36
35: ; preds = %18
store i32 1, i32* %2
br label %36
36: ; preds = %35, %34, %17, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @check_remainder(i32* %0) {
%2 = alloca i8
%3 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%4 = icmp slt i32 %3, 1
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = load i8, i8* %2
%7 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %0)
%8 = icmp slt i32 %7, 1
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = zext i8 %6 to i32
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
%13 = shl nuw nsw i32 %12, 8
%14 = or i32 %13, %10
%15 = tail call i64 @ftell(i32* %0)
%16 = tail call i32 @file_size(i32* %0)
%17 = add nsw i32 %14, %16
%18 = sext i32 %17 to i64
%19 = sub nsw i64 %18, %15
%20 = icmp slt i64 %19, 65537
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %9, %5, %1
%23 = phi i32 [ 0, %1 ], [ 0, %5 ], [ %21, %9 ]
ret i32 %23
}