#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 cmd_resp(int, char *, int *, int);
int send_cmd(int);
int /*<<< orphan*/ usleep(int);
int receive_buff(int cmd_index, char *buff, int *bufflenth, int time_out) {
  int ret;
  while (1) {
    ret = send_cmd(cmd_index);
    if (-1 == ret) {
      usleep(1000);
      return -1;
    }
    ret = cmd_resp(cmd_index, buff, bufflenth, time_out);
    if (5 == ret) {
      usleep(1000);
      continue;
    } else if (-1 == ret) {
      return -1;
    }
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<receive_buff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <send_cmd@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    1175 <receive_buff+0x45>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <receive_buff+0x9e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <cmd_resp@plt>
mov    %eax,-0x20(%rbp)
mov    $0x5,%eax
cmp    -0x20(%rbp),%eax
jne    11a8 <receive_buff+0x78>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
jmp    1146 <receive_buff+0x16>
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    11c2 <receive_buff+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <receive_buff+0x9e>
jmp    11c7 <receive_buff+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_buff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <send_cmd@plt>
cmp    $0xffffffff,%eax
je     117d <receive_buff+0x4d>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <cmd_resp@plt>
cmp    $0x5,%eax
jne    118e <receive_buff+0x5e>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
mov    %ebx,%edi
jmp    1150 <receive_buff+0x20>
mov    $0x3e8,%edi
call   1050 <usleep@plt>
mov    $0xffffffff,%eax
jmp    1195 <receive_buff+0x65>
cmp    $0xffffffff,%eax
je     1195 <receive_buff+0x65>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @receive_buff(i32 %0, i8* %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
br label %11
11: ; preds = %4, %26
%12 = load i32, i32* %6
%13 = call i32 @send_cmd(i32 %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @usleep(i32 1000)
store i32 -1, i32* %5
br label %34
18: ; preds = %11
%19 = load i32, i32* %6
%20 = load i8*, i8** %7
%21 = load i32*, i32** %8
%22 = load i32, i32* %9
%23 = call i32 @cmd_resp(i32 %19, i8* %20, i32* %21, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 5, %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @usleep(i32 1000)
br label %11
28: ; preds = %18
%29 = load i32, i32* %10
%30 = icmp eq i32 -1, %29
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 -1, i32* %5
br label %34
32: ; preds = %28
br label %33
33: ; preds = %32
store i32 0, i32* %5
br label %34
34: ; preds = %33, %31, %16
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @receive_buff(i32 %0, i8* %1, i32* %2, i32 %3) {
%5 = tail call i32 @send_cmd(i32 %0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %11, %4
%8 = tail call i32 @usleep(i32 1000)
br label %16
9: ; preds = %4, %11
%10 = tail call i32 @cmd_resp(i32 %0, i8* %1, i32* %2, i32 %3)
switch i32 %10, label %16 [
i32 5, label %11
i32 -1, label %15
]
11: ; preds = %9
%12 = tail call i32 @usleep(i32 1000)
%13 = tail call i32 @send_cmd(i32 %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %7, label %9
15: ; preds = %9
br label %16
16: ; preds = %9, %15, %7
%17 = phi i32 [ -1, %7 ], [ %10, %15 ], [ 0, %9 ]
ret i32 %17
}