#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*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int 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);
  }
  buf[0] = 0x38;
  write(fd, buf, 1);
  int n = read(fd, buf, 2);
  swab(&buf, &num2, 2);
  printf("read %d\n", num2 - 0x8000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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>
movb   $0x38,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <swab@plt>
mov    -0x10(%rbp),%esi
sub    $0x8000,%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1080 <open@plt>
cmp    $0x1,%eax
jle    11e8 <main+0x78>
mov    %eax,%ebx
movb   $0x38,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1070 <read@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <swab@plt>
mov    $0xffff8000,%esi
add    (%rsp),%esi
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe29(%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 = [9 x i8] c"read %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
store i8 56, i8* %14
%15 = load i32, i32* %2
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%17 = call i32 @write(i32 %15, i8* %16, i32 1)
%18 = load i32, i32* %2
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%20 = call i32 @read(i32 %18, i8* %19, i32 2)
store i32 %20, i32* %5
%21 = bitcast [4 x i8]* %3 to i8**
%22 = call i32 @swab(i8** %21, i32* %4, i32 2)
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 32768
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/spidev0.0\00"
@O_RDWR = global i32 0
@.str.2 = [9 x i8] c"read %d\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
store i8 56, i8* %3
%12 = call i32 @write(i32 %6, i8* %3, i32 1)
%13 = call i32 @read(i32 %6, i8* %3, i32 2)
%14 = bitcast [4 x i8]* %1 to i8**
%15 = call i32 @swab(i8** %14, i32* %2, i32 2)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -32768
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %17)
ret i32 0
}