#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*/ txbuf;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ spi_transfer_array(int, unsigned char *, unsigned char *,
                                      int);
void sensor_get_who_am_i(int fd, unsigned short *whoami) {
  unsigned char rxbuf[3];
  unsigned char txbuf[3] = {0x75 | 0x80, 0, 0};
  printf("==========get who am i value from sensor==========\n");
  spi_transfer_array(fd, txbuf, rxbuf, sizeof(txbuf));
  printf("==============end get who am i value ==============\n");
  *whoami = rxbuf[1] << 8 | rxbuf[2];
  return;
}


x86 assembly (clang, -O0):
<sensor_get_who_am_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeca(%rip),%ax
mov    %ax,-0x16(%rbp)
mov    0xec2(%rip),%al
mov    %al,-0x14(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
lea    -0x13(%rbp),%rdx
mov    $0x3,%ecx
call   1040 <spi_transfer_array@plt>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x12(%rbp),%eax
shl    $0x8,%eax
movzbl -0x11(%rbp),%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensor_get_who_am_i>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x0,0x4(%rsp)
movw   $0xf5,0x2(%rsp)
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0x2(%rsp),%rsi
lea    0x5(%rsp),%rdx
mov    %ebp,%edi
mov    $0x3,%ecx
call   1040 <spi_transfer_array@plt>
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
movzwl 0x6(%rsp),%eax
rol    $0x8,%ax
mov    %ax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.sensor_get_who_am_i.txbuf = [3 x i8] c"\F5\00\00"
@.str = [52 x i8] c"==========get who am i value from sensor==========\0A\00"
@.str.1 = [53 x i8] c"==============end get who am i value ==============\0A\00"
define void @sensor_get_who_am_i(i32 %0, i16* %1) {
%3 = alloca i32
%4 = alloca i16*
%5 = alloca [3 x i8]
%6 = alloca [3 x i8]
store i32 %0, i32* %3
store i16* %1, i16** %4
%7 = bitcast [3 x i8]* %6 to i8*
%8 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%12 = call i32 @spi_transfer_array(i32 %9, i8* %10, i8* %11, i32 3)
%13 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl i32 %16, 8
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = or i32 %17, %20
%22 = trunc i32 %21 to i16
%23 = load i16*, i16** %4
store i16 %22, i16* %23
ret void
}

LLVM IR (-O2):
@__const.sensor_get_who_am_i.txbuf = [3 x i8] c"\F5\00\00"
@str = [51 x i8] c"==========get who am i value from sensor==========\00"
@str.2 = [52 x i8] c"==============end get who am i value ==============\00"
define void @sensor_get_who_am_i(i32 %0, i16* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%8 = call i32 @spi_transfer_array(i32 %0, i8* %6, i8* %5, i32 3)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.2, i64 0, i64 0))
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i16
%13 = shl nuw i16 %12, 8
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i16
%17 = or i16 %13, %16
store i16 %17, i16* %1
ret void
}