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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int send_cmd(int, int, int);
int spi_n(int, int *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ stderr;
int send_chunk(int fd, uint8_t *data, uint8_t len) {
  int ret, buffers;
  if ((ret = send_cmd(fd, 0x81, len)) < 0) {
    fprintf(stderr, "Error sending data command\n");
    return ret;
  }
  buffers = ret;
  if ((ret = spi_n(fd, data, NULL, len ? len : 441)) < 0) {
    fprintf(stderr, "Error sending data\n");
    return ret;
  }
  return buffers;
}


x86 assembly (clang, -O0):
<send_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x81,%esi
call   1050 <send_cmd@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    117e <send_chunk+0x4e>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <send_chunk+0xc9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a7 <send_chunk+0x77>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11b4 <send_chunk+0x84>
mov    $0x1b9,%eax
mov    %eax,-0x30(%rbp)
jmp    11b4 <send_chunk+0x84>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   1030 <spi_n@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11f3 <send_chunk+0xc3>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <send_chunk+0xc9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_chunk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x81,%esi
call   1050 <send_cmd@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1175 <send_chunk+0x45>
test   %ebx,%ebx
mov    $0x1b9,%ecx
cmovne %ebx,%ecx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <spi_n@plt>
test   %eax,%eax
jns    118a <send_chunk+0x5a>
lea    0xeac(%rip),%rsi
mov    %eax,%r15d
jmp    117c <send_chunk+0x4c>
lea    0xe84(%rip),%rsi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error sending data command\0A\00"
@.str.1 = [20 x i8] c"Error sending data\0A\00"
define i32 @send_chunk(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%10 = load i32, i32* %5
%11 = load i32, i32* %7
%12 = call i32 @send_cmd(i32 %10, i32 129, i32 %11)
store i32 %12, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %8
store i32 %17, i32* %4
br label %37
18: ; preds = %3
%19 = load i32, i32* %8
store i32 %19, i32* %9
%20 = load i32, i32* %5
%21 = load i32*, i32** %6
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* %7
br label %27
26: ; preds = %18
br label %27
27: ; preds = %26, %24
%28 = phi i32 [ %25, %24 ], [ 441, %26 ]
%29 = call i32 @spi_n(i32 %20, i32* %21, i32* null, i32 %28)
store i32 %29, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %8
store i32 %34, i32* %4
br label %37
35: ; preds = %27
%36 = load i32, i32* %9
store i32 %36, i32* %4
br label %37
37: ; preds = %35, %31, %14
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error sending data command\0A\00"
@.str.1 = [20 x i8] c"Error sending data\0A\00"
define i32 @send_chunk(i32 %0, i32* %1, i32 %2) {
%4 = tail call i32 @send_cmd(i32 %0, i32 129, i32 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = icmp eq i32 %2, 0
%8 = select i1 %7, i32 441, i32 %2
%9 = tail call i32 @spi_n(i32 %0, i32* %1, i32* null, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6, %3
%12 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %6 ]
%13 = phi i32 [ %4, %3 ], [ %9, %6 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* %12)
br label %16
16: ; preds = %11, %6
%17 = phi i32 [ %4, %6 ], [ %13, %11 ]
ret i32 %17
}