#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;
struct cc_usb {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ao_printf(int, char *, ...);
int /*<<< orphan*/ cc_usb_getchar(struct cc_usb *);
int /*<<< orphan*/ cc_usb_printf(struct cc_usb *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ cc_usb_sync(struct cc_usb *);
void ao_self_block_read(struct cc_usb *cc, uint32_t address,
                        uint8_t block[256]) {
  int byte;
  cc_usb_sync(cc);
  cc_usb_printf(cc, "R %x\n", address);
  for (byte = 0; byte < 0x100; byte++) {
    block[byte] = cc_usb_getchar(cc);
  }
  ao_printf(2, "\nread %08x\n", address);
  for (byte = 0; byte < 0x100; byte++) {
    ao_printf(2, " %02x", block[byte]);
    if ((byte & 0xf) == 0xf)
      ao_printf(2, "\n");
  }
}


x86 assembly (clang, -O0):
<ao_self_block_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <cc_usb_sync@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe96(%rip),%rsi
call   1050 <cc_usb_printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    11a7 <ao_self_block_read+0x67>
mov    -0x8(%rbp),%rdi
call   1060 <cc_usb_getchar@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <ao_self_block_read+0x36>
mov    -0xc(%rbp),%edx
mov    $0x2,%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    1224 <ao_self_block_read+0xe4>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    $0x2,%edi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    1211 <ao_self_block_read+0xd1>
mov    $0x2,%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <ao_printf@plt>
jmp    1216 <ao_self_block_read+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c4 <ao_self_block_read+0x84>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ao_self_block_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <cc_usb_sync@plt>
lea    0xea3(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1050 <cc_usb_printf@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1060 <cc_usb_getchar@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1170 <ao_self_block_read+0x30>
lea    0xe76(%rip),%rsi
mov    $0x2,%edi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <ao_printf@plt>
lea    0xe6c(%rip),%r15
lea    0xe57(%rip),%r14
xor    %ebp,%ebp
jmp    11cd <ao_self_block_read+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    $0x100,%rbp
je     11f9 <ao_self_block_read+0xb9>
mov    (%r12,%rbp,4),%edx
mov    $0x2,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <ao_printf@plt>
mov    %ebp,%eax
not    %eax
test   $0xf,%al
jne    11c0 <ao_self_block_read+0x80>
mov    $0x2,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <ao_printf@plt>
jmp    11c0 <ao_self_block_read+0x80>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cc_usb = type { i32 }
@.str = [6 x i8] c"R %x\0A\00"
@.str.1 = [12 x i8] c"\0Aread %08x\0A\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @ao_self_block_read(%struct.cc_usb* %0, i32 %1, i32* %2) {
%4 = alloca %struct.cc_usb*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store %struct.cc_usb* %0, %struct.cc_usb** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load %struct.cc_usb*, %struct.cc_usb** %4
%9 = call i32 @cc_usb_sync(%struct.cc_usb* %8)
%10 = load %struct.cc_usb*, %struct.cc_usb** %4
%11 = load i32, i32* %5
%12 = call i32 @cc_usb_printf(%struct.cc_usb* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* %7
br label %13
13: ; preds = %23, %3
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 256
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load %struct.cc_usb*, %struct.cc_usb** %4
%18 = call i32 @cc_usb_getchar(%struct.cc_usb* %17)
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 %18, i32* %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %13
26: ; preds = %13
%27 = load i32, i32* %5
%28 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %27)
store i32 0, i32* %7
br label %29
29: ; preds = %45, %26
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 256
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = load i32*, i32** %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
%40 = and i32 %39, 15
%41 = icmp eq i32 %40, 15
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %32
br label %45
45: ; preds = %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %29
48: ; preds = %29
ret void
}

LLVM IR (-O2):
%struct.cc_usb = type { i32 }
@.str = [6 x i8] c"R %x\0A\00"
@.str.1 = [12 x i8] c"\0Aread %08x\0A\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @ao_self_block_read(%struct.cc_usb* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 @cc_usb_sync(%struct.cc_usb* %0)
%5 = tail call i32 @cc_usb_printf(%struct.cc_usb* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %6
6: ; preds = %3, %6
%7 = phi i64 [ 0, %3 ], [ %10, %6 ]
%8 = tail call i32 @cc_usb_getchar(%struct.cc_usb* %0)
%9 = getelementptr inbounds i32, i32* %2, i64 %7
store i32 %8, i32* %9
%10 = add nuw nsw i64 %7, 1
%11 = icmp eq i64 %10, 256
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %14
14: ; preds = %12, %23
%15 = phi i64 [ 0, %12 ], [ %24, %23 ]
%16 = getelementptr inbounds i32, i32* %2, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = and i64 %15, 15
%20 = icmp eq i64 %19, 15
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = tail call i32 (i32, i8*, ...) @ao_printf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %14, %21
%24 = add nuw nsw i64 %15, 1
%25 = icmp eq i64 %24, 256
br i1 %25, label %26, label %14
26: ; preds = %23
ret void
}