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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ swab(char **, int *, int);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int fd;
  char buf[4];
  int num2;
  fd = open("/dev/spidev0.0", O_RDWR);
  if (fd <= 1) {
    printf("error on device\n");
    exit(1);
  }
  write(fd, "\x20", 1);
  write(fd, "\x0C", 1);
  write(fd, "\x10", 1);
  write(fd, "\x04", 1);
  write(fd, "\x60", 1);
  write(fd, "\x18\x3a\x00", 3);
  write(fd, "\x70", 1);
  write(fd, "\x89\x78\xd7", 3);
  while (1) {
    write(fd, "\x08", 1);
    read(fd, buf, 1);
    printf("%d\n", buf[0]);
    if (buf[0] == 8) {
      num2 = 0;
      write(fd, "\x38", 1);
      read(fd, buf, 2);
      swab(&buf, &num2, 2);
      printf("%ld\n", (long)num2 - 0x17CC);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11a9 <main+0x49>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe6d(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe5b(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe49(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe37(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe25(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe26(%rip),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xdff(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xded(%rip),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xddd(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0xc(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0xc(%rbp),%eax
cmp    $0x8,%eax
jne    12e4 <main+0x184>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    0xd98(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <swab@plt>
movslq -0x10(%rbp),%rsi
sub    $0x17cc,%rsi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1249 <main+0xe9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1080 <open@plt>
cmp    $0x1,%eax
jle    12d7 <main+0x167>
mov    %eax,%ebx
lea    0xe6d(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe5c(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe4b(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe3a(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe29(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe3b(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1050 <write@plt>
lea    0xe05(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xdf4(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1050 <write@plt>
lea    0xde5(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xddb(%rip),%r12
mov    %rsp,%rbp
lea    0xdd7(%rip),%r13
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x4(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpb   $0x8,0x4(%rsp)
jne    1250 <main+0xe0>
movl   $0x0,(%rsp)
mov    %ebx,%edi
lea    0xd91(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1070 <read@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1030 <swab@plt>
movslq (%rsp),%rsi
add    $0xffffffffffffe834,%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1250 <main+0xe0>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/spidev0.0\00"
@O_RDWR = global i32 0
@.str.1 = [17 x i8] c"error on device\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0C\00"
@.str.4 = [2 x i8] c"\10\00"
@.str.5 = [2 x i8] c"\04\00"
@.str.6 = [2 x i8] c"`\00"
@.str.7 = [4 x i8] c"\18:\00\00"
@.str.8 = [2 x i8] c"p\00"
@.str.9 = [4 x i8] c"\89x\D7\00"
@.str.10 = [2 x i8] c"\08\00"
@.str.11 = [4 x i8] c"%d\0A\00"
@.str.12 = [2 x i8] c"8\00"
@.str.13 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i32, i32* %2
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%15 = load i32, i32* %2
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%17 = load i32, i32* %2
%18 = call i32 @write(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%19 = load i32, i32* %2
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%21 = load i32, i32* %2
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%23 = load i32, i32* %2
%24 = call i32 @write(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 3)
%25 = load i32, i32* %2
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
%27 = load i32, i32* %2
%28 = call i32 @write(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
br label %29
29: ; preds = %12, %55
%30 = load i32, i32* %2
%31 = call i32 @write(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%32 = load i32, i32* %2
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 1)
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 8
br i1 %42, label %43, label %55
43: ; preds = %29
store i32 0, i32* %4
%44 = load i32, i32* %2
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1)
%46 = load i32, i32* %2
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 2)
%49 = bitcast [4 x i8]* %3 to i8**
%50 = call i32 @swab(i8** %49, i32* %4, i32 2)
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = sub nsw i64 %52, 6092
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64 %53)
br label %55
55: ; preds = %43, %29
br label %29
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/spidev0.0\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0C\00"
@.str.4 = [2 x i8] c"\10\00"
@.str.5 = [2 x i8] c"\04\00"
@.str.6 = [2 x i8] c"`\00"
@.str.7 = [4 x i8] c"\18:\00\00"
@.str.8 = [2 x i8] c"p\00"
@.str.9 = [4 x i8] c"\89x\D7\00"
@.str.10 = [2 x i8] c"\08\00"
@.str.11 = [4 x i8] c"%d\0A\00"
@.str.12 = [2 x i8] c"8\00"
@.str.13 = [5 x i8] c"%ld\0A\00"
@str = [16 x i8] c"error on device\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%13 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%14 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%15 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%16 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%17 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 3)
%18 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
%19 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 3)
%20 = bitcast [4 x i8]* %1 to i8**
br label %21
21: ; preds = %37, %11
%22 = call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%23 = call i32 @read(i32 %6, i8* %3, i32 1)
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %25)
%27 = load i8, i8* %3
%28 = icmp eq i8 %27, 8
br i1 %28, label %29, label %37
29: ; preds = %21
store i32 0, i32* %2
%30 = call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1)
%31 = call i32 @read(i32 %6, i8* %3, i32 2)
%32 = call i32 @swab(i8** %20, i32* %2, i32 2)
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, -6092
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64 %35)
br label %37
37: ; preds = %29, %21
br label %21
}