#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 io2w_read(unsigned char, unsigned char *);
int io2w_write(unsigned char, unsigned char *);
int /*<<< orphan*/ si475x_waitForCTS();
int si475x_command(unsigned char cmd_size, unsigned char *cmd,
                   unsigned char reply_size, unsigned char *reply) {
  int res = -1;
  si475x_waitForCTS();
  res = io2w_write(cmd_size, cmd);
  if (res < 0)
    return res;
  si475x_waitForCTS();
  if (reply_size) {
    res = io2w_read(reply_size, reply);
  }
  return res;
}


x86 assembly (clang, -O0):
<si475x_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %dil,%dl
mov    %dl,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    $0x0,%al
call   1030 <si475x_waitForCTS@plt>
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1040 <io2w_write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1180 <si475x_command+0x50>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <si475x_command+0x79>
mov    $0x0,%al
call   1030 <si475x_waitForCTS@plt>
cmpb   $0x0,-0x11(%rbp)
je     11a3 <si475x_command+0x73>
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1050 <io2w_read@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<si475x_command>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <si475x_waitForCTS@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <io2w_write@plt>
mov    %eax,%ebx
test   %eax,%eax
js     117b <si475x_command+0x4b>
xor    %eax,%eax
call   1030 <si475x_waitForCTS@plt>
test   %r15b,%r15b
je     117b <si475x_command+0x4b>
movzbl %r15b,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <io2w_read@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @si475x_command(i8 zeroext %0, i8* %1, i8 zeroext %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i8* %3, i8** %9
store i32 -1, i32* %10
%11 = call i32 (...) @si475x_waitForCTS()
%12 = load i8, i8* %6
%13 = load i8*, i8** %7
%14 = call i32 @io2w_write(i8 zeroext %12, i8* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %10
store i32 %18, i32* %5
br label %29
19: ; preds = %4
%20 = call i32 (...) @si475x_waitForCTS()
%21 = load i8, i8* %8
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i8, i8* %8
%25 = load i8*, i8** %9
%26 = call i32 @io2w_read(i8 zeroext %24, i8* %25)
store i32 %26, i32* %10
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %10
store i32 %28, i32* %5
br label %29
29: ; preds = %27, %17
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @si475x_command(i8 zeroext %0, i8* %1, i8 zeroext %2, i8* %3) {
%5 = tail call i32 (...) @si475x_waitForCTS()
%6 = tail call i32 @io2w_write(i8 zeroext %0, i8* %1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i32 (...) @si475x_waitForCTS()
%10 = icmp eq i8 %2, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @io2w_read(i8 zeroext %2, i8* %3)
br label %13
13: ; preds = %8, %11, %4
%14 = phi i32 [ %6, %4 ], [ %12, %11 ], [ %6, %8 ]
ret i32 %14
}