#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SPI_IOC_WR_MODE;
char SPI_MODE_0;
int /*<<< orphan*/ close(int);
int encode_cmd(char *, size_t, char **, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
char *optarg;
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ usage(char *);
int write(int, char *, char);
int main(int argc, char *argv[]) {
  int fd;
  char *dev = "/dev/spidev0.0";
  ssize_t ret;
  size_t len;
  char cmd_len;
  char *incmd = NULL;
  char *cmd;
  int opt;
  int verbose = 0;
  char spi_mode;
  extern int optind;
  while ((opt = getopt(argc, argv, "d:vh")) != -1) {
    switch (opt) {
    case 'd':
      dev = optarg;
      break;
    case 'v':
      verbose = 1;
      break;
    case 'h':
    default:
      usage(argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (optind < argc) {
    incmd = argv[optind];
  } else {
    usage(argv[0]);
    exit(EXIT_FAILURE);
  }
  if (NULL == incmd) {
    usage(argv[0]);
    fprintf(stderr, "  A command (-c) must be specified.\n");
    exit(EXIT_FAILURE);
  }
  if (verbose) {
    printf("device = \"%s\"\n", dev);
  }
  fd = open(dev, O_WRONLY);
  if (-1 == fd) {
    fprintf(stderr, "Unable to open '%s': %s\n", dev, strerror(errno));
    return 1;
  }
  spi_mode = SPI_MODE_0;
  ioctl(fd, SPI_IOC_WR_MODE, &spi_mode);
  len = strlen(incmd);
  if (verbose) {
    printf("cmd = \"%s\" (%lu)\n", incmd, (long unsigned int)len);
  }
  ret = encode_cmd(incmd, len, &cmd, &cmd_len);
  if (ret < 0) {
    fprintf(stderr, "Command error, commands 0-8, max groups?\n");
    return 1;
  }
  ret = write(fd, cmd, cmd_len);
  if (ret == -1) {
    fprintf(stderr, "Unable to write '%s': %s\n", dev, strerror(errno));
    close(fd);
    return 1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0e(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0xffffffff,%eax
je     128b <main+0xcb>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    $0x64,%eax
je     1248 <main+0x88>
jmp    1226 <main+0x66>
mov    -0x58(%rbp),%eax
sub    $0x68,%eax
je     1267 <main+0xa7>
jmp    1237 <main+0x77>
mov    -0x58(%rbp),%eax
sub    $0x76,%eax
je     125b <main+0x9b>
jmp    126c <main+0xac>
mov    0x2da9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1286 <main+0xc6>
movl   $0x1,-0x50(%rbp)
jmp    1286 <main+0xc6>
jmp    126c <main+0xac>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    11f3 <main+0x33>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12b8 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    0x2d10(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
jmp    12d2 <main+0x112>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    130f <main+0x14f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x50(%rbp)
je     132b <main+0x16b>
mov    -0x20(%rbp),%rsi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c6a(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1394 <main+0x1d4>
mov    0x2c83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a1 <main+0x2e1>
mov    0x2c15(%rip),%rax
mov    (%rax),%al
mov    %al,-0x51(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c26(%rip),%rax
mov    (%rax),%esi
lea    -0x51(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     13e2 <main+0x222>
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xc86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x31(%rbp),%rcx
call   1080 <encode_cmd@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1427 <main+0x267>
mov    0x2bcd(%rip),%rax
mov    (%rax),%edi
lea    0xc5f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a1 <main+0x2e1>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
movsbl -0x31(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1492 <main+0x2d2>
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xc26(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a1 <main+0x2e1>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
xor    %ebp,%ebp
lea    0xe24(%rip),%r14
lea    0xe2c(%rip),%r15
mov    0x2e0e(%rip),%r13
mov    %ebp,%ecx
nopl   0x0(%rax)
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   10c0 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x76,%eax
je     11f0 <main+0x30>
cmp    $0xffffffff,%eax
je     121d <main+0x5d>
cmp    $0x64,%eax
jne    1384 <main+0x1c4>
mov    0x0(%r13),%r14
jmp    11ea <main+0x2a>
mov    0x2d94(%rip),%rax
movslq (%rax),%rax
cmp    %ebx,%eax
jge    1384 <main+0x1c4>
mov    (%r12,%rax,8),%rbx
test   %rbx,%rbx
je     139b <main+0x1db>
test   %ebp,%ebp
je     1251 <main+0x91>
lea    0xdf2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12f3 <main+0x133>
mov    %eax,%r15d
mov    0x2d3b(%rip),%rax
mov    (%rax),%al
mov    %al,0xe(%rsp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    0xe(%rsp),%rdx
mov    %r15d,%edi
call   1060 <ioctl@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
test   %ebp,%ebp
je     12b4 <main+0xf4>
lea    0xdba(%rip),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rdx
lea    0xf(%rsp),%rcx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <encode_cmd@plt>
test   %eax,%eax
js     1322 <main+0x162>
mov    0x10(%rsp),%rsi
movsbl 0xf(%rsp),%edx
mov    %r15d,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     133b <main+0x17b>
mov    %r15d,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    1375 <main+0x1b5>
mov    0x2cde(%rip),%rax
mov    (%rax),%ebx
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd37(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1370 <main+0x1b0>
mov    0x2c96(%rip),%rax
mov    (%rax),%ebx
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd44(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%rdi
call   10a0 <usage@plt>
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    (%r12),%rdi
call   10a0 <usage@plt>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xc60(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    138d <main+0x1cd>

LLVM IR (-O0):
@.str = [15 x i8] c"/dev/spidev0.0\00"
@.str.1 = [5 x i8] c"d:vh\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@optind = external global i32
@stderr = global i32 0
@.str.2 = [37 x i8] c" A command (-c) must be specified.\0A\00"
@.str.3 = [15 x i8] c"device = \22%s\22\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [25 x i8] c"Unable to open '%s': %s\0A\00"
@errno = global i32 0
@SPI_MODE_0 = global i8 0
@SPI_IOC_WR_MODE = global i32 0
@.str.5 = [18 x i8] c"cmd = \22%s\22 (%lu)\0A\00"
@.str.6 = [42 x i8] c"Command error, commands 0-8, max groups?\0A\00"
@.str.7 = [26 x i8] c"Unable to write '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* null, i8** %11
store i32 0, i32* %14
br label %16
16: ; preds = %34, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %13
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = load i32, i32* %13
switch i32 %22, label %27 [
i32 100, label %23
i32 118, label %25
i32 104, label %26
]
23: ; preds = %21
%24 = load i8*, i8** @optarg
store i8* %24, i8** %7
br label %34
25: ; preds = %21
store i32 1, i32* %14
br label %34
26: ; preds = %21
br label %27
27: ; preds = %21, %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @usage(i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %25, %23
br label %16
35: ; preds = %16
%36 = load i32, i32* @optind
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
store i8* %44, i8** %11
br label %52
45: ; preds = %35
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @usage(i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %39
%53 = load i8*, i8** %11
%54 = icmp eq i8* null, %53
br i1 %54, label %55, label %64
55: ; preds = %52
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @usage(i8* %58)
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %52
%65 = load i32, i32* %14
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i8*, i8** %7
%69 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %64
%71 = load i8*, i8** %7
%72 = load i32, i32* @O_WRONLY
%73 = call i32 @open(i8* %71, i32 %72)
store i32 %73, i32* %6
%74 = load i32, i32* %6
%75 = icmp eq i32 -1, %74
br i1 %75, label %76, label %82
76: ; preds = %70
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %7
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %78, i8* %80)
store i32 1, i32* %3
br label %122
82: ; preds = %70
%83 = load i8, i8* @SPI_MODE_0
store i8 %83, i8* %15
%84 = load i32, i32* %6
%85 = load i32, i32* @SPI_IOC_WR_MODE
%86 = call i32 @ioctl(i32 %84, i32 %85, i8* %15)
%87 = load i8*, i8** %11
%88 = call i64 @strlen(i8* %87)
store i64 %88, i64* %9
%89 = load i32, i32* %14
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %82
%92 = load i8*, i8** %11
%93 = load i64, i64* %9
%94 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %92, i64 %93)
br label %95
95: ; preds = %91, %82
%96 = load i8*, i8** %11
%97 = load i64, i64* %9
%98 = call i32 @encode_cmd(i8* %96, i64 %97, i8** %12, i8* %10)
store i32 %98, i32* %8
%99 = load i32, i32* %8
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %95
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %122
104: ; preds = %95
%105 = load i32, i32* %6
%106 = load i8*, i8** %12
%107 = load i8, i8* %10
%108 = call i32 @write(i32 %105, i8* %106, i8 signext %107)
store i32 %108, i32* %8
%109 = load i32, i32* %8
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %119
111: ; preds = %104
%112 = load i32, i32* @stderr
%113 = load i8*, i8** %7
%114 = load i32, i32* @errno
%115 = call i8* @strerror(i32 %114)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %113, i8* %115)
%117 = load i32, i32* %6
%118 = call i32 @close(i32 %117)
store i32 1, i32* %3
br label %122
119: ; preds = %104
%120 = load i32, i32* %6
%121 = call i32 @close(i32 %120)
store i32 0, i32* %3
br label %122
122: ; preds = %119, %111, %101, %76
%123 = load i32, i32* %3
ret i32 %123
}

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/spidev0.0\00"
@.str.1 = [5 x i8] c"d:vh\00"
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@optind = external global i32
@stderr = global i32 0
@.str.2 = [37 x i8] c" A command (-c) must be specified.\0A\00"
@.str.3 = [15 x i8] c"device = \22%s\22\0A\00"
@O_WRONLY = global i32 0
@.str.4 = [25 x i8] c"Unable to open '%s': %s\0A\00"
@errno = global i32 0
@SPI_MODE_0 = global i8 0
@SPI_IOC_WR_MODE = global i32 0
@.str.5 = [18 x i8] c"cmd = \22%s\22 (%lu)\0A\00"
@.str.6 = [42 x i8] c"Command error, commands 0-8, max groups?\0A\00"
@.str.7 = [26 x i8] c"Unable to write '%s': %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8
%6 = bitcast i8** %4 to i8*
br label %7
7: ; preds = %13, %2
%8 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = phi i32 [ %11, %13 ], [ 0, %2 ]
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 1, %10 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
switch i32 %12, label %15 [
i32 -1, label %20
i32 100, label %13
i32 118, label %10
]
13: ; preds = %10
%14 = load i8*, i8** @optarg
br label %7
15: ; preds = %10
%16 = load i8*, i8** %1
%17 = tail call i32 @usage(i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = load i32, i32* @optind
%22 = icmp slt i32 %21, %0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = sext i32 %21 to i64
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %33, label %40
28: ; preds = %20
%29 = load i8*, i8** %1
%30 = tail call i32 @usage(i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %23
%34 = load i8*, i8** %1
%35 = tail call i32 @usage(i8* %34)
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %23
%41 = icmp eq i32 %11, 0
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %8)
br label %44
44: ; preds = %42, %40
%45 = load i32, i32* @O_WRONLY
%46 = tail call i32 @open(i8* %8, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %8, i8* %51)
br label %79
53: ; preds = %44
%54 = load i8, i8* @SPI_MODE_0
store i8 %54, i8* %5
%55 = load i32, i32* @SPI_IOC_WR_MODE
%56 = call i32 @ioctl(i32 %46, i32 %55, i8* %5)
%57 = call i64 @strlen(i8* %26)
br i1 %41, label %60, label %58
58: ; preds = %53
%59 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %26, i64 %57)
br label %60
60: ; preds = %58, %53
%61 = call i32 @encode_cmd(i8* %26, i64 %57, i8** %4, i8* %3)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %79
66: ; preds = %60
%67 = load i8*, i8** %4
%68 = load i8, i8* %3
%69 = call i32 @write(i32 %46, i8* %67, i8 signext %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %74)
%76 = call i32 @close(i32 %46)
br label %79
77: ; preds = %66
%78 = call i32 @close(i32 %46)
br label %79
79: ; preds = %77, %71, %63, %48
%80 = phi i32 [ 1, %48 ], [ 1, %63 ], [ 1, %71 ], [ 0, %77 ]
ret i32 %80
}