#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 plm_recv(int, char, char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ xwrite_all(int, char *, int);
void plm_docmd(int fd, char *send, int sendlen, char *recv, int recvlen) {
  int nak;
  do {
    xwrite_all(fd, send, sendlen);
    nak = plm_recv(fd, send[1], recv, recvlen);
    if (!nak && recv[recvlen - 1] == 0x15)
      nak = 1;
    if (nak)
      usleep(1000 * 100);
  } while (nak);
}


x86 assembly (clang, -O0):
<plm_docmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <xwrite_all@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
movsbl %al,%esi
call   1040 <plm_recv@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    11a0 <plm_docmd+0x70>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x15,%eax
jne    11a0 <plm_docmd+0x70>
movl   $0x1,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11b4 <plm_docmd+0x84>
mov    $0x186a0,%edi
call   1050 <usleep@plt>
jmp    11b9 <plm_docmd+0x89>
cmpl   $0x0,-0x28(%rbp)
jne    114a <plm_docmd+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plm_docmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %edi,%ebx
movslq %r8d,%r13
jmp    115a <plm_docmd+0x2a>
xchg   %ax,%ax
mov    $0x186a0,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1030 <xwrite_all@plt>
movsbl 0x1(%rbp),%esi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1040 <plm_recv@plt>
test   %eax,%eax
jne    1150 <plm_docmd+0x20>
cmpb   $0x15,-0x1(%r12,%r13,1)
je     1150 <plm_docmd+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @plm_docmd(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
br label %12
12: ; preds = %42, %5
%13 = load i32, i32* %6
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @xwrite_all(i32 %13, i8* %14, i32 %15)
%17 = load i32, i32* %6
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = call i32 @plm_recv(i32 %17, i8 signext %20, i8* %21, i32 %22)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp ne i32 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %12
%27 = load i8*, i8** %9
%28 = load i32, i32* %10
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 21
br i1 %34, label %35, label %36
35: ; preds = %26
store i32 1, i32* %11
br label %36
36: ; preds = %35, %26, %12
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @usleep(i32 100000)
br label %41
41: ; preds = %39, %36
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = icmp ne i32 %43, 0
br i1 %44, label %12, label %45
45: ; preds = %42
ret void
}

LLVM IR (-O2):
define void @plm_docmd(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = add nsw i32 %4, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %3, i64 %7
%9 = getelementptr inbounds i8, i8* %1, i64 1
br label %10
10: ; preds = %18, %5
%11 = tail call i32 @xwrite_all(i32 %0, i8* %1, i32 %2)
%12 = load i8, i8* %9
%13 = tail call i32 @plm_recv(i32 %0, i8 signext %12, i8* %3, i32 %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8, i8* %8
%17 = icmp eq i8 %16, 21
br i1 %17, label %18, label %20
18: ; preds = %15, %10
%19 = tail call i32 @usleep(i32 100000)
br label %10
20: ; preds = %15
ret void
}