#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 */
scalar_t__ io_read(void *, int);
scalar_t__ io_write(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
int io_send_cmd(char *cmd, void *response, int response_len) {
  if (io_write(cmd, strlen(cmd)) < 0) {
    return -1;
  }
  usleep(2000);
  if (response_len == 0) {
    return 0;
  }
  if (io_read(response, response_len) < 0) {
    return -1;
  }
  usleep(2000);
  return 0;
}


x86 assembly (clang, -O0):
<io_send_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1030 <io_write@plt>
cmp    $0x0,%rax
jge    1185 <io_send_cmd+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <io_send_cmd+0x98>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11a5 <io_send_cmd+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <io_send_cmd+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <io_read@plt>
cmp    $0x0,%rax
jge    11c7 <io_send_cmd+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <io_send_cmd+0x98>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_send_cmd>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <io_write@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     118e <io_send_cmd+0x4e>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
test   %ebp,%ebp
je     118c <io_send_cmd+0x4c>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <io_read@plt>
test   %rax,%rax
js     118e <io_send_cmd+0x4e>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @io_send_cmd(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = call i64 @io_write(i8* %8, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %27
14: ; preds = %3
%15 = call i32 @usleep(i32 2000)
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 0, i32* %4
br label %27
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i64 @io_read(i8* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -1, i32* %4
br label %27
25: ; preds = %19
%26 = call i32 @usleep(i32 2000)
store i32 0, i32* %4
br label %27
27: ; preds = %25, %24, %18, %13
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
define i32 @io_send_cmd(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i64 @io_write(i8* %0, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = tail call i32 @usleep(i32 2000)
%9 = icmp eq i32 %2, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = tail call i64 @io_read(i8* %1, i32 %2)
%12 = icmp slt i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @usleep(i32 2000)
br label %15
15: ; preds = %10, %7, %3, %13
%16 = phi i32 [ 0, %13 ], [ -1, %3 ], [ 0, %7 ], [ -1, %10 ]
ret i32 %16
}