#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ GprsM590eLock();
scalar_t__ GprsM590eReadWithoutDelay(unsigned char *, int);
int /*<<< orphan*/ GprsM590eUnLock();
int /*<<< orphan*/ GprsM590eWrite(unsigned char *, unsigned int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
unsigned int snprintf(char *, int, char *);
int /*<<< orphan*/ usleep(int);
int GprsGetTcpUdpLinkStatus(void) {
  int count = 0;
  int ret = 0;
  unsigned char buffer[2048] = {0};
  unsigned int index = 0;
  GprsM590eLock();
  index = snprintf((char *)buffer, sizeof(buffer), "AT+IPSTATUS=0\r");
  GprsM590eWrite(buffer, index);
  index = 0;
  memset(buffer, 0x0, sizeof(buffer));
  while (count < 400) {
    index += GprsM590eReadWithoutDelay(&buffer[index], 2048 - index);
    if ((index >= 2048)) {
      ret = 1;
      break;
    }
    usleep(5000);
    count++;
  };
  GprsM590eUnLock();
  return ret;
}


x86 assembly (clang, -O0):
<GprsGetTcpUdpLinkStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
movl   $0x0,-0x814(%rbp)
mov    $0x0,%al
call   1080 <GprsM590eLock@plt>
lea    -0x810(%rbp),%rdi
mov    $0x800,%esi
lea    0xe40(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x814(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x814(%rbp),%esi
call   1070 <GprsM590eWrite@plt>
movl   $0x0,-0x814(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
cmpl   $0x190,-0x4(%rbp)
jge    126d <GprsGetTcpUdpLinkStatus+0xfd>
mov    -0x814(%rbp),%eax
lea    -0x810(%rbp),%rdi
add    %rax,%rdi
mov    $0x800,%esi
sub    -0x814(%rbp),%esi
call   1030 <GprsM590eReadWithoutDelay@plt>
mov    %rax,%rcx
mov    -0x814(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x814(%rbp)
cmpl   $0x800,-0x814(%rbp)
jb     1255 <GprsGetTcpUdpLinkStatus+0xe5>
movl   $0x1,-0x8(%rbp)
jmp    126d <GprsGetTcpUdpLinkStatus+0xfd>
mov    $0x1388,%edi
call   1090 <usleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11fa <GprsGetTcpUdpLinkStatus+0x8a>
mov    $0x0,%al
call   1040 <GprsM590eUnLock@plt>
mov    -0x8(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GprsGetTcpUdpLinkStatus>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsp,%r14
xor    %ebx,%ebx
mov    $0x800,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
call   1080 <GprsM590eLock@plt>
lea    0xe63(%rip),%rdx
mov    %r14,%rdi
mov    $0x800,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1070 <GprsM590eWrite@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    $0x190,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r14d
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
mov    $0x800,%esi
sub    %ebx,%esi
call   1030 <GprsM590eReadWithoutDelay@plt>
mov    %rax,%rbx
add    %r14d,%ebx
cmp    $0x7ff,%ebx
ja     1206 <GprsGetTcpUdpLinkStatus+0x96>
mov    $0x1388,%edi
call   1090 <usleep@plt>
add    $0xffffffff,%ebp
jne    11d0 <GprsGetTcpUdpLinkStatus+0x60>
xor    %ebx,%ebx
jmp    120b <GprsGetTcpUdpLinkStatus+0x9b>
mov    $0x1,%ebx
xor    %eax,%eax
call   1040 <GprsM590eUnLock@plt>
mov    %ebx,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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