#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 */
struct spi_ioc_transfer {
  unsigned long tx_buf;
  unsigned long rx_buf;
  int len;
};

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_MESSAGE(int);
int ioctl(int, int /*<<< orphan*/, struct spi_ioc_transfer *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
void do_msg(int fd) {
  unsigned char tbuf[8];
  unsigned char rbuf[8];
  unsigned char *bp;
  struct spi_ioc_transfer xfer[2];
  int status;
  tbuf[0] = 1;
  tbuf[1] = 2;
  tbuf[2] = 3;
  tbuf[3] = 4;
  tbuf[4] = 1;
  xfer[0].tx_buf = (unsigned long)tbuf;
  xfer[0].rx_buf = (unsigned long)rbuf;
  xfer[0].len = 5;
  while (1) {
    status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer);
    printf("%d,write\n", status);
    if (status < 0) {
      printf("write wrong!\n");
      return;
    }
    usleep(10);
  }
}


x86 assembly (clang, -O0):
<do_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x1,-0xc(%rbp)
movb   $0x2,-0xb(%rbp)
movb   $0x3,-0xa(%rbp)
movb   $0x4,-0x9(%rbp)
movb   $0x1,-0x8(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x5,-0x40(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x1,%edi
call   1040 <SPI_IOC_MESSAGE@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x54(%rbp)
jge    11c6 <do_msg+0x86>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret
mov    $0xa,%edi
call   1060 <usleep@plt>
jmp    1176 <do_msg+0x36>

x86 assembly (clang, -O2):
<do_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
movl   $0x4030201,(%rsp)
movb   $0x1,0x4(%rsp)
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x5,0x20(%rsp)
mov    $0x1,%edi
call   1050 <SPI_IOC_MESSAGE@plt>
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
mov    %eax,%ebp
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
js     11f2 <do_msg+0xa2>
lea    0x10(%rsp),%r14
lea    0xe44(%rip),%r15
nopl   0x0(%rax)
mov    $0xa,%edi
call   1070 <usleep@plt>
mov    $0x1,%edi
call   1050 <SPI_IOC_MESSAGE@plt>
mov    %ebx,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1060 <ioctl@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jns    11c0 <do_msg+0x70>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spi_ioc_transfer = type { i64, i64, i32 }
@.str = [10 x i8] c"%d,write\0A\00"
@.str.1 = [14 x i8] c"write wrong!\0A\00"
define void @do_msg(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca [8 x i8]
%5 = alloca i8*
%6 = alloca [2 x %struct.spi_ioc_transfer]
%7 = alloca i32
store i32 %0, i32* %2
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
store i8 1, i8* %8
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
store i8 2, i8* %9
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
store i8 3, i8* %10
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
store i8 4, i8* %11
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 1, i8* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = ptrtoint i8* %13 to i64
%15 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0
%16 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %15, i32 0, i32 0
store i64 %14, i64* %16
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%18 = ptrtoint i8* %17 to i64
%19 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0
%20 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %19, i32 0, i32 1
store i64 %18, i64* %20
%21 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0
%22 = getelementptr inbounds %struct.spi_ioc_transfer, %struct.spi_ioc_transfer* %21, i32 0, i32 2
store i32 5, i32* %22
br label %23
23: ; preds = %1, %34
%24 = load i32, i32* %2
%25 = call i32 @SPI_IOC_MESSAGE(i32 1)
%26 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %6, i64 0, i64 0
%27 = call i32 @ioctl(i32 %24, i32 %25, %struct.spi_ioc_transfer* %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
ret void
34: ; preds = %23
%35 = call i32 @usleep(i32 10)
br label %23
}

LLVM IR (-O2):
%struct.spi_ioc_transfer = type { i64, i64, i32 }
@.str = [10 x i8] c"%d,write\0A\00"
@str = [13 x i8] c"write wrong!\00"
define void @do_msg(i32 %0) {
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = alloca [2 x %struct.spi_ioc_transfer]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%7 = bitcast [2 x %struct.spi_ioc_transfer]* %4 to i8*
store i8 1, i8* %5
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 2, i8* %8
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
store i8 3, i8* %9
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 4, i8* %10
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
store i8 1, i8* %11
%12 = ptrtoint [8 x i8]* %2 to i64
%13 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %4, i64 0, i64 0
%14 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %4, i64 0, i64 0, i32 0
store i64 %12, i64* %14
%15 = ptrtoint [8 x i8]* %3 to i64
%16 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %4, i64 0, i64 0, i32 1
store i64 %15, i64* %16
%17 = getelementptr inbounds [2 x %struct.spi_ioc_transfer], [2 x %struct.spi_ioc_transfer]* %4, i64 0, i64 0, i32 2
store i32 5, i32* %17
%18 = call i32 @SPI_IOC_MESSAGE(i32 1)
%19 = call i32 @ioctl(i32 %0, i32 %18, %struct.spi_ioc_transfer* %13)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = icmp slt i32 %19, 0
br i1 %21, label %22, label %24
22: ; preds = %24, %1
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret void
24: ; preds = %1, %24
%25 = call i32 @usleep(i32 10)
%26 = call i32 @SPI_IOC_MESSAGE(i32 1)
%27 = call i32 @ioctl(i32 %0, i32 %26, %struct.spi_ioc_transfer* %13)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = icmp slt i32 %27, 0
br i1 %29, label %22, label %24
}