#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 EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
size_t saybytesfromfile(FILE *f, long fromoffset, size_t numbytes, FILE *str) {
  int c;
  size_t len = 0;
  if (fseek(f, fromoffset, SEEK_SET) != 0) {
    return 0;
  }
  while (numbytes-- != 0) {
    if ((c = getc(f)) == EOF) {
      break;
    }
    ++len;
    if (c == '\0') {
      break;
    }
    fputc(c, str);
  }
  return len;
}


x86 assembly (clang, -O0):
<saybytesfromfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
je     117d <saybytesfromfile+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11ef <saybytesfromfile+0xbf>
jmp    1182 <saybytesfromfile+0x52>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     11e7 <saybytesfromfile+0xb7>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
jne    11bb <saybytesfromfile+0x8b>
jmp    11e7 <saybytesfromfile+0xb7>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11d6 <saybytesfromfile+0xa6>
jmp    11e7 <saybytesfromfile+0xb7>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <fputc@plt>
jmp    1182 <saybytesfromfile+0x52>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saybytesfromfile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1198 <saybytesfromfile+0x68>
test   %r15,%r15
je     1198 <saybytesfromfile+0x68>
xor    %ebx,%ebx
mov    0x2e83(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1050 <getc@plt>
cmp    0x0(%r13),%eax
je     1198 <saybytesfromfile+0x68>
add    $0x1,%rbx
test   %eax,%eax
je     1198 <saybytesfromfile+0x68>
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
cmp    %rbx,%r15
jne    1170 <saybytesfromfile+0x40>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@EOF = global i32 0
define i64 @saybytesfromfile(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32* %3, i32** %9
store i64 0, i64* %11
%12 = load i32*, i32** %6
%13 = load i64, i64* %7
%14 = load i32, i32* @SEEK_SET
%15 = call i64 @fseek(i32* %12, i64 %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i64 0, i64* %5
br label %41
18: ; preds = %4
br label %19
19: ; preds = %35, %18
%20 = load i64, i64* %8
%21 = add i64 %20, -1
store i64 %21, i64* %8
%22 = icmp ne i64 %20, 0
br i1 %22, label %23, label %39
23: ; preds = %19
%24 = load i32*, i32** %6
%25 = call i32 @getc(i32* %24)
store i32 %25, i32* %10
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23
br label %39
29: ; preds = %23
%30 = load i64, i64* %11
%31 = add i64 %30, 1
store i64 %31, i64* %11
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %39
35: ; preds = %29
%36 = load i32, i32* %10
%37 = load i32*, i32** %9
%38 = call i32 @fputc(i32 %36, i32* %37)
br label %19
39: ; preds = %34, %28, %19
%40 = load i64, i64* %11
store i64 %40, i64* %5
br label %41
41: ; preds = %39, %17
%42 = load i64, i64* %5
ret i64 %42
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@EOF = global i32 0
define i64 @saybytesfromfile(i32* nocapture %0, i64 %1, i64 %2, i32* nocapture %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @fseek(i32* %0, i64 %1, i32 %5)
%7 = icmp ne i64 %6, 0
%8 = icmp eq i64 %2, 0
%9 = or i1 %7, %8
br i1 %9, label %23, label %10
10: ; preds = %4, %20
%11 = phi i64 [ %13, %20 ], [ %2, %4 ]
%12 = phi i64 [ %18, %20 ], [ 0, %4 ]
%13 = add i64 %11, -1
%14 = tail call i32 @getc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = add nuw i64 %12, 1
%19 = icmp eq i32 %14, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @fputc(i32 %14, i32* %3)
%22 = icmp eq i64 %13, 0
br i1 %22, label %23, label %10
23: ; preds = %17, %10, %20, %4
%24 = phi i64 [ 0, %4 ], [ %18, %17 ], [ %12, %10 ], [ %2, %20 ]
ret i64 %24
}