#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 __u8;
typedef int __u32;

/* Variables and functions */
int /*<<< orphan*/ SPI_IOC_RD_BITS_PER_WORD;
int /*<<< orphan*/ SPI_IOC_RD_LSB_FIRST;
int /*<<< orphan*/ SPI_IOC_RD_MAX_SPEED_HZ;
int /*<<< orphan*/ SPI_IOC_RD_MODE;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, char *, int);
void spi_dump_stat(int fd) {
  __u8 lsb = 0, bits = 0;
  __u32 mode = 0, speed = 0;
  if (ioctl(fd, SPI_IOC_RD_MODE, &mode) < 0) {
    perror("SPI rd_mode");
    return;
  }
  if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, &lsb) < 0) {
    perror("SPI rd_lsb_fist");
    return;
  }
  if (ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0) {
    perror("SPI bits_per_word");
    return;
  }
  if (ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0) {
    perror("SPI max_speed_hz");
    return;
  }
  printf("spi mode 0x%x, %d bits %sper word, %d Hz max\n", mode, bits,
         lsb ? "(lsb first) " : "", speed);
}


x86 assembly (clang, -O0):
<spi_dump_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1187 <spi_dump_stat+0x57>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
jmp    1245 <spi_dump_stat+0x115>
mov    -0x4(%rbp),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11b7 <spi_dump_stat+0x87>
lea    0xe5f(%rip),%rdi
call   1050 <perror@plt>
jmp    1245 <spi_dump_stat+0x115>
mov    -0x4(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11e7 <spi_dump_stat+0xb7>
lea    0xe3f(%rip),%rdi
call   1050 <perror@plt>
jmp    1245 <spi_dump_stat+0x115>
mov    -0x4(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1217 <spi_dump_stat+0xe7>
lea    0xe21(%rip),%rdi
call   1050 <perror@plt>
jmp    1245 <spi_dump_stat+0x115>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%edi
lea    0xe45(%rip),%rcx
lea    0xe3f(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
mov    -0x14(%rbp),%r8d
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spi_dump_stat>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     11f3 <spi_dump_stat+0xc3>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1201 <spi_dump_stat+0xd1>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     120f <spi_dump_stat+0xdf>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     121d <spi_dump_stat+0xed>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
cmpl   $0x0,0xc(%rsp)
lea    0xe9a(%rip),%rax
lea    0xe94(%rip),%rcx
cmove  %rax,%rcx
mov    (%rsp),%r8d
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe06(%rip),%rdi
call   1050 <perror@plt>
jmp    11ed <spi_dump_stat+0xbd>
lea    0xe04(%rip),%rdi
call   1050 <perror@plt>
jmp    11ed <spi_dump_stat+0xbd>
lea    0xe06(%rip),%rdi
call   1050 <perror@plt>
jmp    11ed <spi_dump_stat+0xbd>
lea    0xe0a(%rip),%rdi
call   1050 <perror@plt>
jmp    11ed <spi_dump_stat+0xbd>

LLVM IR (-O0):
@SPI_IOC_RD_MODE = global i32 0
@.str = [12 x i8] c"SPI rd_mode\00"
@SPI_IOC_RD_LSB_FIRST = global i32 0
@.str.1 = [16 x i8] c"SPI rd_lsb_fist\00"
@SPI_IOC_RD_BITS_PER_WORD = global i32 0
@.str.2 = [18 x i8] c"SPI bits_per_word\00"
@SPI_IOC_RD_MAX_SPEED_HZ = global i32 0
@.str.3 = [17 x i8] c"SPI max_speed_hz\00"
@.str.4 = [46 x i8] c"spi mode 0x%x, %d bits %sper word, %d Hz max\0A\00"
@.str.5 = [13 x i8] c"(lsb first) \00"
@.str.6 = [1 x i8] zeroinitializer
define void @spi_dump_stat(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %2
%8 = load i32, i32* @SPI_IOC_RD_MODE
%9 = call i64 @ioctl(i32 %7, i32 %8, i32* %5)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %43
13: ; preds = %1
%14 = load i32, i32* %2
%15 = load i32, i32* @SPI_IOC_RD_LSB_FIRST
%16 = call i64 @ioctl(i32 %14, i32 %15, i32* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %43
20: ; preds = %13
%21 = load i32, i32* %2
%22 = load i32, i32* @SPI_IOC_RD_BITS_PER_WORD
%23 = call i64 @ioctl(i32 %21, i32 %22, i32* %4)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %43
27: ; preds = %20
%28 = load i32, i32* %2
%29 = load i32, i32* @SPI_IOC_RD_MAX_SPEED_HZ
%30 = call i64 @ioctl(i32 %28, i32 %29, i32* %6)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %43
34: ; preds = %27
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = icmp ne i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0)
%41 = load i32, i32* %6
%42 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36, i8* %40, i32 %41)
br label %43
43: ; preds = %34, %32, %25, %18, %11
ret void
}

LLVM IR (-O2):
@SPI_IOC_RD_MODE = global i32 0
@.str = [12 x i8] c"SPI rd_mode\00"
@SPI_IOC_RD_LSB_FIRST = global i32 0
@.str.1 = [16 x i8] c"SPI rd_lsb_fist\00"
@SPI_IOC_RD_BITS_PER_WORD = global i32 0
@.str.2 = [18 x i8] c"SPI bits_per_word\00"
@SPI_IOC_RD_MAX_SPEED_HZ = global i32 0
@.str.3 = [17 x i8] c"SPI max_speed_hz\00"
@.str.4 = [46 x i8] c"spi mode 0x%x, %d bits %sper word, %d Hz max\0A\00"
@.str.5 = [13 x i8] c"(lsb first) \00"
@.str.6 = [1 x i8] zeroinitializer
define void @spi_dump_stat(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = load i32, i32* @SPI_IOC_RD_MODE
%11 = call i64 @ioctl(i32 %0, i32 %10, i32* %4)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %41
15: ; preds = %1
%16 = load i32, i32* @SPI_IOC_RD_LSB_FIRST
%17 = call i64 @ioctl(i32 %0, i32 %16, i32* %2)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %41
21: ; preds = %15
%22 = load i32, i32* @SPI_IOC_RD_BITS_PER_WORD
%23 = call i64 @ioctl(i32 %0, i32 %22, i32* %3)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %41
27: ; preds = %21
%28 = load i32, i32* @SPI_IOC_RD_MAX_SPEED_HZ
%29 = call i64 @ioctl(i32 %0, i32 %28, i32* %5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %41
33: ; preds = %27
%34 = load i32, i32* %4
%35 = load i32, i32* %3
%36 = load i32, i32* %2
%37 = icmp eq i32 %36, 0
%38 = select i1 %37, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0)
%39 = load i32, i32* %5
%40 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %34, i32 %35, i8* %38, i32 %39)
br label %41
41: ; preds = %33, %31, %25, %19, %13
ret void
}