#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 */
scalar_t__ Modem_SendCmd(int, char *, int);
scalar_t__ Modem_WaitResponse(int, char *, int);
int /*<<< orphan*/ logcat(char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ usleep(int);
int SMS_DelMessage(int fd, int index) {
  char cmd[256];
  int retry = 5;
  int i;
  logcat("SMS Start to Delet Message, index = %d\n", index);
  memset(cmd, 0, 256);
  sprintf(cmd, "AT+CMGD=%d\r", index);
  for (i = 0; i < retry; i++) {
    if (Modem_SendCmd(fd, cmd, 5) < 0)
      continue;
    usleep(500 * 1000);
    if (Modem_WaitResponse(fd, "OK", 3) == 0)
      break;
  }
  if (i == retry) {
    logcat("SMS Delet Message error.\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<SMS_DelMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x5,-0x114(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <logcat@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe78(%rip),%rsi
call   1070 <sprintf@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    123a <SMS_DelMessage+0xda>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
cmp    $0x0,%rax
jge    11f4 <SMS_DelMessage+0x94>
jmp    1226 <SMS_DelMessage+0xc6>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    0xe2c(%rip),%rsi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
cmp    $0x0,%rax
jne    1221 <SMS_DelMessage+0xc1>
jmp    123a <SMS_DelMessage+0xda>
jmp    1226 <SMS_DelMessage+0xc6>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    11bf <SMS_DelMessage+0x5f>
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jne    1266 <SMS_DelMessage+0x106>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <logcat@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126d <SMS_DelMessage+0x10d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SMS_DelMessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebx
mov    %edi,%r15d
lea    0xe87(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <logcat@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
lea    0xe8c(%rip),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
test   %rax,%rax
js     11e2 <SMS_DelMessage+0x82>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xe68(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
test   %rax,%rax
je     12de <SMS_DelMessage+0x17e>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
test   %rax,%rax
js     121e <SMS_DelMessage+0xbe>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xe2c(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
test   %rax,%rax
je     12de <SMS_DelMessage+0x17e>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
test   %rax,%rax
js     125a <SMS_DelMessage+0xfa>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xdf0(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
test   %rax,%rax
je     12de <SMS_DelMessage+0x17e>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
test   %rax,%rax
js     1292 <SMS_DelMessage+0x132>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xdb4(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
test   %rax,%rax
je     12de <SMS_DelMessage+0x17e>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x5,%edx
call   1050 <Modem_SendCmd@plt>
test   %rax,%rax
js     12ca <SMS_DelMessage+0x16a>
mov    $0x7a120,%edi
call   1080 <usleep@plt>
lea    0xd7c(%rip),%rsi
mov    %r15d,%edi
mov    $0x3,%edx
call   1060 <Modem_WaitResponse@plt>
test   %rax,%rax
je     12de <SMS_DelMessage+0x17e>
lea    0xd66(%rip),%rdi
xor    %eax,%eax
call   1040 <logcat@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"SMS Start to Delet Message, index = %d\0A\00"
@.str.1 = [12 x i8] c"AT+CMGD=%d\0D\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [26 x i8] c"SMS Delet Message error.\0A\00"
define i32 @SMS_DelMessage(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 5, i32* %7
%9 = load i32, i32* %5
%10 = call i32 (i8*, ...) @logcat(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 256)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* %5
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 0, i32* %8
br label %16
16: ; preds = %33, %2
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load i32, i32* %4
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = call i64 @Modem_SendCmd(i32 %21, i8* %22, i32 5)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %33
26: ; preds = %20
%27 = call i32 @usleep(i32 500000)
%28 = load i32, i32* %4
%29 = call i64 @Modem_WaitResponse(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %36
32: ; preds = %26
br label %33
33: ; preds = %32, %25
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %16
36: ; preds = %31, %16
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @logcat(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %43
42: ; preds = %36
store i32 0, i32* %3
br label %43
43: ; preds = %42, %40
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [40 x i8] c"SMS Start to Delet Message, index = %d\0A\00"
@.str.1 = [12 x i8] c"AT+CMGD=%d\0D\00"
@.str.2 = [3 x i8] c"OK\00"
@.str.3 = [26 x i8] c"SMS Delet Message error.\0A\00"
define i32 @SMS_DelMessage(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @logcat(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i32 @memset(i8* %4, i32 0, i32 256)
%7 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%8 = call i64 @Modem_SendCmd(i32 %0, i8* %4, i32 5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i32 @usleep(i32 500000)
%12 = call i64 @Modem_WaitResponse(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %44, label %14
14: ; preds = %10, %2
%15 = call i64 @Modem_SendCmd(i32 %0, i8* %4, i32 5)
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = call i32 @usleep(i32 500000)
%19 = call i64 @Modem_WaitResponse(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %44, label %21
21: ; preds = %17, %14
%22 = call i64 @Modem_SendCmd(i32 %0, i8* %4, i32 5)
%23 = icmp slt i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @usleep(i32 500000)
%26 = call i64 @Modem_WaitResponse(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %44, label %28
28: ; preds = %24, %21
%29 = call i64 @Modem_SendCmd(i32 %0, i8* %4, i32 5)
%30 = icmp slt i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = call i32 @usleep(i32 500000)
%33 = call i64 @Modem_WaitResponse(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %31, %28
%36 = call i64 @Modem_SendCmd(i32 %0, i8* %4, i32 5)
%37 = icmp slt i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = call i32 @usleep(i32 500000)
%40 = call i64 @Modem_WaitResponse(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 3)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %35, %38
%43 = call i32 (i8*, ...) @logcat(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %10, %17, %24, %31, %38, %42
%45 = phi i32 [ -1, %42 ], [ 0, %38 ], [ 0, %31 ], [ 0, %24 ], [ 0, %17 ], [ 0, %10 ]
ret i32 %45
}