#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 */
struct programmer_t {
  int dummy;
};

/* Variables and functions */
int buspirate_expect_bin_byte(struct programmer_t *, int, int);
int /*<<< orphan*/ buspirate_recv_bin(struct programmer_t *, unsigned char *,
                                      int);
int /*<<< orphan*/ buspirate_send_bin(struct programmer_t *,
                                      unsigned char const *, int);
int buspirate_cmd_bin(struct programmer_t *pgm, const unsigned char *cmd,
                      unsigned char *res) {
  int rv = buspirate_expect_bin_byte(pgm, 0x13, 0x01);
  if (rv < 0)
    return -1;
  if (rv == 0)
    return -1;
  buspirate_send_bin(pgm, cmd, 4);
  buspirate_recv_bin(pgm, res, 4);
  return 0;
}


x86 assembly (clang, -O0):
<buspirate_cmd_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
call   1030 <buspirate_expect_bin_byte@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1170 <buspirate_cmd_bin+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <buspirate_cmd_bin+0x81>
cmpl   $0x0,-0x24(%rbp)
jne    1186 <buspirate_cmd_bin+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <buspirate_cmd_bin+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1040 <buspirate_send_bin@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1050 <buspirate_recv_bin@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buspirate_cmd_bin>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x13,%esi
mov    $0x1,%edx
call   1030 <buspirate_expect_bin_byte@plt>
test   %eax,%eax
jle    1175 <buspirate_cmd_bin+0x45>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <buspirate_send_bin@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <buspirate_recv_bin@plt>
xor    %eax,%eax
jmp    117a <buspirate_cmd_bin+0x4a>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.programmer_t = type { i32 }
define i32 @buspirate_cmd_bin(%struct.programmer_t* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.programmer_t*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store %struct.programmer_t* %0, %struct.programmer_t** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load %struct.programmer_t*, %struct.programmer_t** %5
%10 = call i32 @buspirate_expect_bin_byte(%struct.programmer_t* %9, i32 19, i32 1)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %25
14: ; preds = %3
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %4
br label %25
18: ; preds = %14
%19 = load %struct.programmer_t*, %struct.programmer_t** %5
%20 = load i8*, i8** %6
%21 = call i32 @buspirate_send_bin(%struct.programmer_t* %19, i8* %20, i32 4)
%22 = load %struct.programmer_t*, %struct.programmer_t** %5
%23 = load i8*, i8** %7
%24 = call i32 @buspirate_recv_bin(%struct.programmer_t* %22, i8* %23, i32 4)
store i32 0, i32* %4
br label %25
25: ; preds = %18, %17, %13
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.programmer_t = type { i32 }
define i32 @buspirate_cmd_bin(%struct.programmer_t* %0, i8* %1, i8* %2) {
%4 = tail call i32 @buspirate_expect_bin_byte(%struct.programmer_t* %0, i32 19, i32 1)
%5 = icmp slt i32 %4, 1
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @buspirate_send_bin(%struct.programmer_t* %0, i8* %1, i32 4)
%8 = tail call i32 @buspirate_recv_bin(%struct.programmer_t* %0, i8* %2, i32 4)
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ 0, %6 ], [ -1, %3 ]
ret i32 %10
}