#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 uint8_t;

/* Variables and functions */
int spi_write_then_read(int, int *, int, int *, int);
int do_read_data(int fd, int addr, uint8_t *buf, int len) {
  uint8_t wbuf[4] = {0x03, (addr & 0xff0000) >> 16, (addr & 0xff00) >> 8,
                     addr & 0xff};
  return spi_write_then_read(fd, wbuf, 4, buf, len);
}


x86 assembly (clang, -O0):
<do_read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x3,-0x30(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    $0x4,%edx
call   1030 <spi_write_then_read@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_read_data>:
sub    $0x18,%rsp
mov    %ecx,%r8d
mov    %rdx,%rcx
mov    %esi,%eax
movl   $0x3,(%rsp)
movzbl %ah,%edx
movzbl %al,%esi
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,0x4(%rsp)
mov    %edx,0x8(%rsp)
mov    %esi,0xc(%rsp)
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <spi_write_then_read@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @do_read_data(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [4 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
store i32 3, i32* %10
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %6
%13 = and i32 %12, 16711680
%14 = ashr i32 %13, 16
store i32 %14, i32* %11
%15 = getelementptr inbounds i32, i32* %11, i64 1
%16 = load i32, i32* %6
%17 = and i32 %16, 65280
%18 = ashr i32 %17, 8
store i32 %18, i32* %15
%19 = getelementptr inbounds i32, i32* %15, i64 1
%20 = load i32, i32* %6
%21 = and i32 %20, 255
store i32 %21, i32* %19
%22 = load i32, i32* %5
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%24 = load i32*, i32** %7
%25 = load i32, i32* %8
%26 = call i32 @spi_write_then_read(i32 %22, i32* %23, i32 4, i32* %24, i32 %25)
ret i32 %26
}

LLVM IR (-O2):
define i32 @do_read_data(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca [4 x i32]
%6 = bitcast [4 x i32]* %5 to i8*
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
store i32 3, i32* %7
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
%9 = lshr i32 %1, 16
%10 = and i32 %9, 255
store i32 %10, i32* %8
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
%12 = lshr i32 %1, 8
%13 = and i32 %12, 255
store i32 %13, i32* %11
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
%15 = and i32 %1, 255
store i32 %15, i32* %14
%16 = call i32 @spi_write_then_read(i32 %0, i32* %7, i32 4, i32* %2, i32 %3)
ret i32 %16
}