#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 unsigned int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, unsigned int);
unsigned int read(int, unsigned char *, unsigned int);
int /*<<< orphan*/ stdout;
int testBlockR(int fd, unsigned int nbytes) {
  int status = 0;
  unsigned int i = 0U;
  unsigned char *bytesR = malloc(nbytes);
  (void)memset(bytesR, 0, nbytes);
  ssize_t rlen = read(fd, bytesR, nbytes);
  while (i < rlen) {
    fprintf(stdout, "0x%02x ", (unsigned char)bytesR[i]);
  }
  free(bytesR);
  return status;
}


x86 assembly (clang, -O0):
<testBlockR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11c9 <testBlockR+0x79>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
lea    0xe45(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1060 <fprintf@plt>
jmp    1198 <testBlockR+0x48>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testBlockR>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    %esi,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11b0 <testBlockR+0x60>
mov    0x2e59(%rip),%rbp
mov    0x0(%rbp),%edi
movzbl (%rbx),%edx
lea    0xe6c(%rip),%r14
mov    %r14,%rsi
call   1060 <fprintf@plt>
nopl   0x0(%rax)
mov    0x0(%rbp),%edi
movzbl (%rbx),%edx
mov    %r14,%rsi
call   1060 <fprintf@plt>
jmp    11a0 <testBlockR+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [8 x i8] c"0x%02x \00"
define i32 @testBlockR(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32, i32* %4
%13 = call i32 @memset(i8* %11, i32 0, i32 %12)
%14 = load i32, i32* %3
%15 = load i8*, i8** %7
%16 = load i32, i32* %4
%17 = call i32 @read(i32 %14, i8* %15, i32 %16)
store i32 %17, i32* %8
br label %18
18: ; preds = %22, %2
%19 = load i32, i32* %6
%20 = load i32, i32* %8
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = load i8*, i8** %7
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %28)
br label %18
30: ; preds = %18
%31 = load i8*, i8** %7
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"0x%02x \00"
define i32 @testBlockR(i32 %0, i32 %1) {
%3 = tail call i8* @malloc(i32 %1)
%4 = tail call i32 @memset(i8* %3, i32 0, i32 %1)
%5 = tail call i32 @read(i32 %0, i8* %3, i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = load i8, i8* %3
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
br label %11
11: ; preds = %11, %7
%12 = load i32, i32* @stdout
%13 = load i8, i8* %3
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
br label %11
15: ; preds = %2
%16 = tail call i32 @free(i8* %3)
ret i32 0
}