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

/* Variables and functions */
int /*<<< orphan*/ usart_cs(int);
int /*<<< orphan*/ usart_in_byte();
int /*<<< orphan*/ usart_out_byte(int);
void read(uint32_t addr, uint8_t *bytes, uint16_t len) {
  usart_cs(0);
  usart_out_byte(0x03);
  usart_out_byte(addr >> 16);
  usart_out_byte(addr >> 8);
  usart_out_byte(addr);
  while (len-- > 0)
    *bytes++ = usart_in_byte();
  usart_cs(1);
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %edi,%edi
call   1050 <usart_cs@plt>
mov    $0x3,%edi
call   1040 <usart_out_byte@plt>
mov    -0x4(%rbp),%edi
sar    $0x10,%edi
call   1040 <usart_out_byte@plt>
mov    -0x4(%rbp),%edi
sar    $0x8,%edi
call   1040 <usart_out_byte@plt>
mov    -0x4(%rbp),%edi
call   1040 <usart_out_byte@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    11a4 <read+0x74>
mov    $0x0,%al
call   1030 <usart_in_byte@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
jmp    1171 <read+0x41>
mov    $0x1,%edi
call   1050 <usart_cs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %edi,%edi
call   1050 <usart_cs@plt>
mov    $0x3,%edi
call   1040 <usart_out_byte@plt>
mov    %ebp,%edi
sar    $0x10,%edi
call   1040 <usart_out_byte@plt>
mov    %ebp,%edi
sar    $0x8,%edi
call   1040 <usart_out_byte@plt>
mov    %ebp,%edi
call   1040 <usart_out_byte@plt>
test   %ebx,%ebx
jle    1186 <read+0x56>
add    $0x1,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <usart_in_byte@plt>
mov    %eax,(%r14)
add    $0x4,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <read+0x40>
mov    $0x1,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <usart_cs@plt>

LLVM IR (-O0):
define void @read(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = call i32 @usart_cs(i32 0)
%8 = call i32 @usart_out_byte(i32 3)
%9 = load i32, i32* %4
%10 = ashr i32 %9, 16
%11 = call i32 @usart_out_byte(i32 %10)
%12 = load i32, i32* %4
%13 = ashr i32 %12, 8
%14 = call i32 @usart_out_byte(i32 %13)
%15 = load i32, i32* %4
%16 = call i32 @usart_out_byte(i32 %15)
br label %17
17: ; preds = %21, %3
%18 = load i32, i32* %6
%19 = add nsw i32 %18, -1
store i32 %19, i32* %6
%20 = icmp sgt i32 %18, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 (...) @usart_in_byte()
%23 = load i32*, i32** %5
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %5
store i32 %22, i32* %23
br label %17
25: ; preds = %17
%26 = call i32 @usart_cs(i32 1)
ret void
}

LLVM IR (-O2):
define void @read(i32 %0, i32* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @usart_cs(i32 0)
%5 = tail call i32 @usart_out_byte(i32 3)
%6 = ashr i32 %0, 16
%7 = tail call i32 @usart_out_byte(i32 %6)
%8 = ashr i32 %0, 8
%9 = tail call i32 @usart_out_byte(i32 %8)
%10 = tail call i32 @usart_out_byte(i32 %0)
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %19
12: ; preds = %3, %12
%13 = phi i32 [ %15, %12 ], [ %2, %3 ]
%14 = phi i32* [ %17, %12 ], [ %1, %3 ]
%15 = add nsw i32 %13, -1
%16 = tail call i32 (...) @usart_in_byte()
%17 = getelementptr inbounds i32, i32* %14, i64 1
store i32 %16, i32* %14
%18 = icmp ugt i32 %13, 1
br i1 %18, label %12, label %19
19: ; preds = %12, %3
%20 = tail call i32 @usart_cs(i32 1)
ret void
}