#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 AT_EXP_READY(unsigned char *);
int /*<<< orphan*/ GprsM590eLock();
scalar_t__ GprsM590eReadWithoutDelay(unsigned char *, int);
int /*<<< orphan*/ GprsM590eUnLock();
int /*<<< orphan*/ GprsM590eWrite(unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
int GprsSendAT(void) {
  int count = 0;
  int timeout = 400;
  unsigned char buffer[128] = {0};
  unsigned int index = 0;
  int ret = 0;
  GprsM590eLock();
  GprsM590eWrite((unsigned char *)"AT\r", strlen("AT\r"));
  for (count = 0; count < timeout; count++) {
    index += GprsM590eReadWithoutDelay(&buffer[index], 128 - index);
    if ((AT_EXP_READY(buffer) == 1) || (index >= 128)) {
      ret = 1;
      break;
    }
    usleep(5000);
  };
  GprsM590eUnLock();
  return ret;
}


x86 assembly (clang, -O0):
<GprsSendAT>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x190,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    $0x0,%al
call   1090 <GprsM590eLock@plt>
lea    0xe32(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xe24(%rip),%rdi
call   1080 <GprsM590eWrite@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1272 <GprsSendAT+0xf2>
mov    -0x94(%rbp),%eax
lea    -0x90(%rbp),%rdi
add    %rax,%rdi
mov    $0x80,%esi
sub    -0x94(%rbp),%esi
call   1030 <GprsM590eReadWithoutDelay@plt>
mov    %rax,%rcx
mov    -0x94(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
call   1070 <AT_EXP_READY@plt>
cmp    $0x1,%eax
je     124b <GprsSendAT+0xcb>
cmpl   $0x80,-0x94(%rbp)
jb     125a <GprsSendAT+0xda>
movl   $0x1,-0x98(%rbp)
jmp    1272 <GprsSendAT+0xf2>
mov    $0x1388,%edi
call   10a0 <usleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <GprsSendAT+0x68>
mov    $0x0,%al
call   1050 <GprsM590eUnLock@plt>
mov    -0x98(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GprsSendAT>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <GprsM590eLock@plt>
lea    0xe47(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <GprsM590eWrite@plt>
mov    $0x190,%r12d
mov    %rsp,%r14
mov    $0x1,%r15d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x80,%esi
sub    %ebp,%esi
call   1030 <GprsM590eReadWithoutDelay@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <AT_EXP_READY@plt>
cmp    $0x1,%eax
je     121c <GprsSendAT+0xac>
add    %ebx,%ebp
cmp    $0x7f,%ebp
ja     121c <GprsSendAT+0xac>
mov    $0x1388,%edi
call   1090 <usleep@plt>
add    $0xffffffff,%r12d
jne    11e0 <GprsSendAT+0x70>
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <GprsM590eUnLock@plt>
mov    %r15d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"AT\0D\00"
define i32 @GprsSendAT() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 400, i32* %2
%6 = bitcast [128 x i8]* %3 to i8*
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32 (...) @GprsM590eLock()
%8 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @GprsM590eWrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %1
br label %10
10: ; preds = %34, %0
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %10
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %16
%18 = load i32, i32* %4
%19 = sub i32 128, %18
%20 = call i64 @GprsM590eReadWithoutDelay(i8* %17, i32 %19)
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* %4
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%26 = call i32 @AT_EXP_READY(i8* %25)
%27 = icmp eq i32 %26, 1
br i1 %27, label %31, label %28
28: ; preds = %14
%29 = load i32, i32* %4
%30 = icmp uge i32 %29, 128
br i1 %30, label %31, label %32
31: ; preds = %28, %14
store i32 1, i32* %5
br label %37
32: ; preds = %28
%33 = call i32 @usleep(i32 5000)
br label %34
34: ; preds = %32
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 1
store i32 %36, i32* %1
br label %10
37: ; preds = %31, %10
%38 = call i32 (...) @GprsM590eUnLock()
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
@.str = [4 x i8] c"AT\0D\00"
define i32 @GprsSendAT() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @GprsM590eLock()
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @GprsM590eWrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %6
6: ; preds = %0, %19
%7 = phi i32 [ 0, %0 ], [ %14, %19 ]
%8 = phi i32 [ 0, %0 ], [ %21, %19 ]
%9 = zext i32 %7 to i64
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %9
%11 = sub i32 128, %7
%12 = call i64 @GprsM590eReadWithoutDelay(i8* %10, i32 %11)
%13 = trunc i64 %12 to i32
%14 = add i32 %7, %13
%15 = call i32 @AT_EXP_READY(i8* %2)
%16 = icmp eq i32 %15, 1
%17 = icmp ugt i32 %14, 127
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %23, label %19
19: ; preds = %6
%20 = call i32 @usleep(i32 5000)
%21 = add nuw nsw i32 %8, 1
%22 = icmp eq i32 %21, 400
br i1 %22, label %23, label %6
23: ; preds = %6, %19
%24 = phi i32 [ 0, %19 ], [ 1, %6 ]
%25 = call i32 (...) @GprsM590eUnLock()
ret i32 %24
}