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

/* Variables and functions */
scalar_t__ bseof(struct jelbs *);
int /*<<< orphan*/ readbits(struct jelbs *, int, int *);
int readbytes(struct jelbs *s, unsigned char *oct, int n) {
  int eof = 0;
  while (n--) {
    if (bseof(s))
      return -1;
    *oct++ = readbits(s, 8, &eof);
    if (eof)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<readbytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     11ad <readbytes+0x8d>
mov    -0x10(%rbp),%rdi
call   1040 <bseof@plt>
cmp    $0x0,%rax
je     116d <readbytes+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <readbytes+0x94>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    -0x20(%rbp),%rdx
call   1030 <readbits@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
cmpl   $0x0,-0x20(%rbp)
je     11a8 <readbytes+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <readbytes+0x94>
jmp    113a <readbytes+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readbytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
movl   $0x0,0x4(%rsp)
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0x4(%rsp),%r15
mov    $0xffffffff,%ebp
nopl   0x0(%rax,%rax,1)
cmp    %ebx,%r12d
je     1183 <readbytes+0x63>
mov    %r13,%rdi
call   1040 <bseof@plt>
test   %rax,%rax
jne    1185 <readbytes+0x65>
mov    %r13,%rdi
mov    $0x8,%esi
mov    %r15,%rdx
call   1030 <readbits@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmpl   $0x0,0x4(%rsp)
je     1150 <readbytes+0x30>
jmp    1185 <readbytes+0x65>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.jelbs = type { i32 }
define i32 @readbytes(%struct.jelbs* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.jelbs*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.jelbs* %0, %struct.jelbs** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %27, %3
%10 = load i32, i32* %7
%11 = add nsw i32 %10, -1
store i32 %11, i32* %7
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load %struct.jelbs*, %struct.jelbs** %5
%15 = call i64 @bseof(%struct.jelbs* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %4
br label %29
18: ; preds = %13
%19 = load %struct.jelbs*, %struct.jelbs** %5
%20 = call i32 @readbits(%struct.jelbs* %19, i32 8, i32* %8)
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
store i8 %21, i8* %22
%24 = load i32, i32* %8
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 -1, i32* %4
br label %29
27: ; preds = %18
br label %9
28: ; preds = %9
store i32 0, i32* %4
br label %29
29: ; preds = %28, %26, %17
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
%struct.jelbs = type { i32 }
define i32 @readbytes(%struct.jelbs* %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %14, %3
%7 = phi i8* [ %1, %3 ], [ %17, %14 ]
%8 = phi i32 [ %2, %3 ], [ %9, %14 ]
%9 = add nsw i32 %8, -1
%10 = icmp eq i32 %8, 0
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = call i64 @bseof(%struct.jelbs* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = call i32 @readbits(%struct.jelbs* %0, i32 8, i32* %4)
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %16, i8* %7
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %6, %14, %11
%21 = phi i32 [ -1, %11 ], [ -1, %14 ], [ 0, %6 ]
ret i32 %21
}