#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*/ tmp1;
typedef int /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ reply;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ delete_first_message(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ send_at(int);
int /*<<< orphan*/ send_at_cmgf(int, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
int write(int, char *, int);
int receive_zh_message(int fd) {
  char *msg;
  int nread, nwrite;
  char cmgf[] = "1";
  char buff[] = "AT+CMGR=1\r";
  char reply[2000];
  char tmp[2000], tmp1[2000];
  memset(tmp, 0, sizeof(tmp));
  send_at(fd);
  send_at_cmgf(fd, cmgf);
  nwrite = write(fd, buff, sizeof(buff));
  memset(buff, 0, sizeof(buff));
  sleep(1);
  nread = read(fd, reply, sizeof(reply));
  strcpy(tmp1, reply);
  if (strstr(reply, "ERROR"))
    return 0;
  printf("%s\n", reply);
  msg = strstr(reply, "+CMGR: ");
  if (msg != NULL) {
    msg = strstr(msg, "\r\n");
    strcat(tmp, msg + 2);
    memset(reply, 0, sizeof(reply));
  } else
    return 0;
  if (strstr(tmp, "83B753D65F53524D4F4D7F6E") != NULL) {
    memset(tmp, 0, sizeof(tmp));
    delete_first_message(fd);
    return 1;
  } else if (strstr(tmp1, "ERROR") == NULL) {
    memset(tmp1, 0, sizeof(tmp1));
    delete_first_message(fd);
    return 0;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<receive_zh_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17a0,%rsp
mov    %edi,-0x8(%rbp)
mov    0xe3b(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    0xe32(%rip),%rax
mov    %rax,-0x25(%rbp)
mov    0xe2f(%rip),%ax
mov    %ax,-0x1d(%rbp)
mov    0xe27(%rip),%al
mov    %al,-0x1b(%rbp)
lea    -0xfd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
call   1090 <send_at@plt>
mov    -0x8(%rbp),%edi
lea    -0x1a(%rbp),%rsi
call   1050 <send_at_cmgf@plt>
mov    -0x8(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
lea    -0x25(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    $0x7d0,%edx
call   1080 <read@plt>
mov    %eax,-0x14(%rbp)
lea    -0x17a0(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x800(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1290 <receive_zh_message+0xe0>
movl   $0x0,-0x4(%rbp)
jmp    13a0 <receive_zh_message+0x1f0>
lea    -0x800(%rbp),%rsi
lea    0xd75(%rip),%rdi
call   1060 <printf@plt>
lea    -0x800(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1305 <receive_zh_message+0x155>
mov    -0x10(%rbp),%rdi
lea    0xd4f(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x10(%rbp)
lea    -0xfd0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x2,%rsi
call   10b0 <strcat@plt>
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
jmp    1311 <receive_zh_message+0x161>
movl   $0x0,-0x4(%rbp)
jmp    13a0 <receive_zh_message+0x1f0>
lea    -0xfd0(%rbp),%rdi
lea    0xd03(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1355 <receive_zh_message+0x1a5>
lea    -0xfd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
call   10a0 <delete_first_message@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a0 <receive_zh_message+0x1f0>
lea    -0x17a0(%rbp),%rdi
lea    0xcaa(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
jne    1399 <receive_zh_message+0x1e9>
lea    -0x17a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
call   10a0 <delete_first_message@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a0 <receive_zh_message+0x1f0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x17a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_zh_message>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1790,%rsp
mov    %edi,%ebx
movw   $0x31,0xe(%rsp)
movabs $0x3d52474d432b5441,%rax
47 52 3d
mov    %rax,0x10(%rsp)
movl   $0xd313d,0x17(%rsp)
lea    0xfc0(%rsp),%r14
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
call   1090 <send_at@plt>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
call   1050 <send_at_cmgf@plt>
lea    0x10(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
lea    0x20(%rsp),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x7d0,%edx
call   1080 <read@plt>
lea    0x7f0(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0xda4(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
jne    131f <receive_zh_message+0x16f>
lea    0xd92(%rip),%rdi
lea    0x20(%rsp),%rbp
mov    %rbp,%rsi
call   1060 <printf@plt>
lea    0xd82(%rip),%rsi
mov    %rbp,%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     131f <receive_zh_message+0x16f>
lea    0xd76(%rip),%rsi
mov    %rax,%rdi
call   10d0 <strstr@plt>
lea    0x2(%rax),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0x20(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
lea    0xd4a(%rip),%rsi
mov    %r14,%rdi
call   10d0 <strstr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1303 <receive_zh_message+0x153>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1070 <memset@plt>
mov    %ebx,%edi
call   10a0 <delete_first_message@plt>
mov    %ebp,%r12d
jmp    131f <receive_zh_message+0x16f>
lea    0xd01(%rip),%rsi
mov    %r15,%rdi
call   10d0 <strstr@plt>
mov    %r15,%r14
mov    $0x0,%ebp
test   %rax,%rax
je     12e8 <receive_zh_message+0x138>
mov    %r12d,%eax
add    $0x1790,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.receive_zh_message.cmgf = [2 x i8] c"1\00"
@__const.receive_zh_message.buff = [11 x i8] c"AT+CMGR=1\0D\00"
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"+CMGR: \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [25 x i8] c"83B753D65F53524D4F4D7F6E\00"
define i32 @receive_zh_message(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8]
%8 = alloca [11 x i8]
%9 = alloca [2000 x i8]
%10 = alloca [2000 x i8]
%11 = alloca [2000 x i8]
store i32 %0, i32* %3
%12 = bitcast [2 x i8]* %7 to i8*
%13 = bitcast [11 x i8]* %8 to i8*
%14 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 2000)
%16 = load i32, i32* %3
%17 = call i32 @send_at(i32 %16)
%18 = load i32, i32* %3
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%20 = call i32 @send_at_cmgf(i32 %18, i8* %19)
%21 = load i32, i32* %3
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%23 = call i32 @write(i32 %21, i8* %22, i32 11)
store i32 %23, i32* %6
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 11)
%26 = call i32 @sleep(i32 1)
%27 = load i32, i32* %3
%28 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%29 = call i32 @read(i32 %27, i8* %28, i32 2000)
store i32 %29, i32* %5
%30 = getelementptr inbounds [2000 x i8], [2000 x i8]* %11, i64 0, i64 0
%31 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %1
store i32 0, i32* %2
br label %73
37: ; preds = %1
%38 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %41, i8** %4
%42 = load i8*, i8** %4
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %53
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = call i8* @strstr(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %46, i8** %4
%47 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 2
%50 = call i32 @strcat(i8* %47, i8* %49)
%51 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i32 0, i32 2000)
br label %54
53: ; preds = %37
store i32 0, i32* %2
br label %73
54: ; preds = %44
%55 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%56 = call i8* @strstr(i8* %55, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%60 = call i32 @memset(i8* %59, i32 0, i32 2000)
%61 = load i32, i32* %3
%62 = call i32 @delete_first_message(i32 %61)
store i32 1, i32* %2
br label %73
63: ; preds = %54
%64 = getelementptr inbounds [2000 x i8], [2000 x i8]* %11, i64 0, i64 0
%65 = call i8* @strstr(i8* %64, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = getelementptr inbounds [2000 x i8], [2000 x i8]* %11, i64 0, i64 0
%69 = call i32 @memset(i8* %68, i32 0, i32 2000)
%70 = load i32, i32* %3
%71 = call i32 @delete_first_message(i32 %70)
store i32 0, i32* %2
br label %73
72: ; preds = %63
store i32 0, i32* %2
br label %73
73: ; preds = %72, %67, %58, %53, %36
%74 = load i32, i32* %2
ret i32 %74
}

LLVM IR (-O2):
@__const.receive_zh_message.buff = [11 x i8] c"AT+CMGR=1\0D\00"
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [8 x i8] c"+CMGR: \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [25 x i8] c"83B753D65F53524D4F4D7F6E\00"
define i32 @receive_zh_message(i32 %0) {
%2 = alloca i16
%3 = alloca [11 x i8]
%4 = alloca [2000 x i8]
%5 = alloca [2000 x i8]
%6 = alloca [2000 x i8]
%7 = bitcast i16* %2 to i8*
store i16 49, i16* %2
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %10, i32 0, i32 2000)
%13 = call i32 @send_at(i32 %0)
%14 = call i32 @send_at_cmgf(i32 %0, i8* %7)
%15 = call i32 @write(i32 %0, i8* %8, i32 11)
%16 = call i32 @memset(i8* %8, i32 0, i32 11)
%17 = call i32 @sleep(i32 1)
%18 = call i32 @read(i32 %0, i8* %9, i32 2000)
%19 = call i32 @strcpy(i8* %11, i8* %9)
%20 = call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %41
22: ; preds = %1
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%24 = call i8* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %41, label %26
26: ; preds = %22
%27 = call i8* @strstr(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = call i32 @strcat(i8* %10, i8* %28)
%30 = call i32 @memset(i8* %9, i32 0, i32 2000)
%31 = call i8* @strstr(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i8* @strstr(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33, %26
%37 = phi i8* [ %10, %26 ], [ %11, %33 ]
%38 = phi i32 [ 1, %26 ], [ 0, %33 ]
%39 = call i32 @memset(i8* %37, i32 0, i32 2000)
%40 = call i32 @delete_first_message(i32 %0)
br label %41
41: ; preds = %36, %33, %22, %1
%42 = phi i32 [ 0, %1 ], [ 0, %22 ], [ 0, %33 ], [ %38, %36 ]
ret i32 %42
}