#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*/ errno;
int /*<<< orphan*/ errorMessage(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
scalar_t__ spiConfig(int, int, int, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int spiOpen(char *busDevice, int mode, int speed, int bitsPerWord,
            int lsbFirst) {
  int fd;
  int ret;
  if ((fd = open(busDevice, O_RDWR)) < 0) {
    errorMessage("open failed: %s", strerror(errno));
    return -1;
  }
  if (spiConfig(fd, mode, speed, bitsPerWord, lsbFirst) < 0) {
    errorMessage("open failed: %s", strerror(errno));
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<spiOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    119f <spiOpen+0x5f>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe72(%rip),%rdi
call   1040 <errorMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <spiOpen+0xac>
mov    -0x24(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1030 <spiConfig@plt>
cmp    $0x0,%rax
jge    11e6 <spiOpen+0xa6>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
lea    0xe2b(%rip),%rdi
call   1040 <errorMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <spiOpen+0xac>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spiOpen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebx
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     117e <spiOpen+0x3e>
mov    %eax,%ebp
mov    %eax,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <spiConfig@plt>
test   %rax,%rax
jns    119f <spiOpen+0x5f>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
call   1040 <errorMessage@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [16 x i8] c"open failed: %s\00"
@errno = global i32 0
define i32 @spiOpen(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load i8*, i8** %7
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %12
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @errorMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 -1, i32* %6
br label %36
22: ; preds = %5
%23 = load i32, i32* %12
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = call i64 @spiConfig(i32 %23, i32 %24, i32 %25, i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %22
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @errorMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 -1, i32* %6
br label %36
34: ; preds = %22
%35 = load i32, i32* %12
store i32 %35, i32* %6
br label %36
36: ; preds = %34, %30, %18
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [16 x i8] c"open failed: %s\00"
@errno = global i32 0
define i32 @spiOpen(i8* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i64 @spiConfig(i32 %7, i32 %1, i32 %2, i32 %3, i32 %4)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9, %5
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @errorMessage(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %7, %9 ], [ -1, %12 ]
ret i32 %17
}