#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 /*<<< orphan*/ spi_write_then_read(int, int *, int, int *, int);
int do_read_jedec(int fd) {
  uint8_t buf[1] = {0x9F};
  uint8_t id[3] = {0};
  int ret = 0;
  spi_write_then_read(fd, buf, 1, id, 3);
  ret = (id[2] << 16) | (id[1] << 8) | id[0];
  return ret;
}


x86 assembly (clang, -O0):
<do_read_jedec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rcx
mov    $0x1,%edx
mov    $0x3,%r8d
call   1040 <spi_write_then_read@plt>
mov    -0xc(%rbp),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_read_jedec>:
sub    $0x18,%rsp
movl   $0x9f,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%rcx
mov    $0x1,%edx
mov    $0x3,%r8d
call   1030 <spi_write_then_read@plt>
mov    0xc(%rsp),%eax
mov    0x10(%rsp),%ecx
shl    $0x10,%ecx
shl    $0x8,%eax
or     %ecx,%eax
or     0x8(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.do_read_jedec.buf = [1 x i32] [i32 159]
define i32 @do_read_jedec(i32 %0) {
%2 = alloca i32
%3 = alloca [1 x i32]
%4 = alloca [3 x i32]
%5 = alloca i32
store i32 %0, i32* %2
%6 = bitcast [1 x i32]* %3 to i8*
%7 = bitcast [3 x i32]* %4 to i8*
store i32 0, i32* %5
%8 = load i32, i32* %2
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%11 = call i32 @spi_write_then_read(i32 %8, i32* %9, i32 1, i32* %10, i32 3)
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 2
%13 = load i32, i32* %12
%14 = shl i32 %13, 16
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%16 = load i32, i32* %15
%17 = shl i32 %16, 8
%18 = or i32 %14, %17
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%20 = load i32, i32* %19
%21 = or i32 %18, %20
store i32 %21, i32* %5
%22 = load i32, i32* %5
ret i32 %22
}

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