#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_MODE32;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *, int, int, char *, int);
void dumpstat(const char *name, int fd) {
  __u8 lsb, bits;
  __u32 mode, speed;
  if (ioctl(fd, SPI_IOC_RD_MODE32, &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("%s: spi mode 0x%x, %d bits %sper word, %d Hz max\n", name, mode, bits,
         lsb ? "(lsb first) " : "", speed);
}


x86 assembly (clang, -O0):
<dumpstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    116f <dumpstat+0x3f>
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
jmp    1231 <dumpstat+0x101>
mov    -0xc(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    119f <dumpstat+0x6f>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
jmp    1231 <dumpstat+0x101>
mov    -0xc(%rbp),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11cf <dumpstat+0x9f>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
jmp    1231 <dumpstat+0x101>
mov    -0xc(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11ff <dumpstat+0xcf>
lea    0xe39(%rip),%rdi
call   1050 <perror@plt>
jmp    1231 <dumpstat+0x101>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%edi
lea    0xe5d(%rip),%r8
lea    0xe57(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
mov    -0x1c(%rbp),%r9d
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpstat>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11e1 <dumpstat+0xb1>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0x14(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11ef <dumpstat+0xbf>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     11fd <dumpstat+0xcd>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     120b <dumpstat+0xdb>
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
cmpl   $0x0,0x14(%rsp)
lea    0xeb5(%rip),%rax
lea    0xeaf(%rip),%r8
cmove  %rax,%r8
mov    0x8(%rsp),%r9d
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe18(%rip),%rdi
call   1050 <perror@plt>
jmp    11da <dumpstat+0xaa>
lea    0xe16(%rip),%rdi
call   1050 <perror@plt>
jmp    11da <dumpstat+0xaa>
lea    0xe18(%rip),%rdi
call   1050 <perror@plt>
jmp    11da <dumpstat+0xaa>
lea    0xe1c(%rip),%rdi
call   1050 <perror@plt>
jmp    11da <dumpstat+0xaa>

LLVM IR (-O0):
@SPI_IOC_RD_MODE32 = 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 = [50 x i8] c"%s: 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 @dumpstat(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = load i32, i32* @SPI_IOC_RD_MODE32
%11 = call i64 @ioctl(i32 %9, i32 %10, i32* %7)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %46
15: ; preds = %2
%16 = load i32, i32* %4
%17 = load i32, i32* @SPI_IOC_RD_LSB_FIRST
%18 = call i64 @ioctl(i32 %16, i32 %17, i32* %5)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %46
22: ; preds = %15
%23 = load i32, i32* %4
%24 = load i32, i32* @SPI_IOC_RD_BITS_PER_WORD
%25 = call i64 @ioctl(i32 %23, i32 %24, i32* %6)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %46
29: ; preds = %22
%30 = load i32, i32* %4
%31 = load i32, i32* @SPI_IOC_RD_MAX_SPEED_HZ
%32 = call i64 @ioctl(i32 %30, i32 %31, i32* %8)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %46
36: ; preds = %29
%37 = load i8*, i8** %3
%38 = load i32, i32* %7
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, 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)
%44 = load i32, i32* %8
%45 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %37, i32 %38, i32 %39, i8* %43, i32 %44)
br label %46
46: ; preds = %36, %34, %27, %20, %13
ret void
}

LLVM IR (-O2):
@SPI_IOC_RD_MODE32 = 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 = [50 x i8] c"%s: 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 @dumpstat(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = load i32, i32* @SPI_IOC_RD_MODE32
%12 = call i64 @ioctl(i32 %1, i32 %11, i32* %5)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %42
16: ; preds = %2
%17 = load i32, i32* @SPI_IOC_RD_LSB_FIRST
%18 = call i64 @ioctl(i32 %1, i32 %17, i32* %3)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %42
22: ; preds = %16
%23 = load i32, i32* @SPI_IOC_RD_BITS_PER_WORD
%24 = call i64 @ioctl(i32 %1, i32 %23, i32* %4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %42
28: ; preds = %22
%29 = load i32, i32* @SPI_IOC_RD_MAX_SPEED_HZ
%30 = call i64 @ioctl(i32 %1, i32 %29, i32* %6)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %42
34: ; preds = %28
%35 = load i32, i32* %5
%36 = load i32, i32* %4
%37 = load i32, i32* %3
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, 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)
%40 = load i32, i32* %6
%41 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %35, i32 %36, i8* %39, i32 %40)
br label %42
42: ; preds = %34, %32, %26, %20, %14
ret void
}