#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 File_AppendRecord(char *, char *, int);
int File_GetNumberOfRecords(char *, int);
int File_GetRecordByIndex(char *, char *, int, int);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int SMS_AddPhone(char *phone) {
  int num = 0;
  int i;
  char buf[16] = {0};
  num = File_GetNumberOfRecords("/CMD_Data/.sms_phone.txt", 16);
  for (i = 0; i < num; i++) {
    memset(buf, 0, 16);
    if (File_GetRecordByIndex("/CMD_Data/.sms_phone.txt", buf, 16, i) == 16) {
      if (strcmp(buf, phone) == 0)
        return 0;
    }
  }
  memset(buf, 0, 16);
  memcpy(buf, phone, strlen(phone));
  return File_AppendRecord("/CMD_Data/.sms_phone.txt", buf, 16);
}


x86 assembly (clang, -O0):
<SMS_AddPhone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe66(%rip),%rdi
mov    $0x10,%esi
call   1030 <File_GetNumberOfRecords@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1226 <SMS_AddPhone+0xb6>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%ecx
lea    0xe28(%rip),%rdi
mov    $0x10,%edx
call   1090 <File_GetRecordByIndex@plt>
cmp    $0x10,%eax
jne    1213 <SMS_AddPhone+0xa3>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    120e <SMS_AddPhone+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    1276 <SMS_AddPhone+0x106>
jmp    1213 <SMS_AddPhone+0xa3>
jmp    1218 <SMS_AddPhone+0xa8>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ae <SMS_AddPhone+0x3e>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xd97(%rip),%rdi
mov    $0x10,%edx
call   1050 <File_AppendRecord@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SMS_AddPhone>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe73(%rip),%rdi
mov    $0x10,%esi
call   1030 <File_GetNumberOfRecords@plt>
test   %eax,%eax
jle    11f2 <SMS_AddPhone+0x82>
mov    %eax,%r15d
xor    %ebx,%ebx
mov    %rsp,%rbp
lea    0xe56(%rip),%r12
jmp    11b8 <SMS_AddPhone+0x48>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%r15d
je     11f2 <SMS_AddPhone+0x82>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
mov    %ebx,%ecx
call   1090 <File_GetRecordByIndex@plt>
cmp    $0x10,%eax
jne    11b0 <SMS_AddPhone+0x40>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11b0 <SMS_AddPhone+0x40>
xor    %eax,%eax
jmp    122d <SMS_AddPhone+0xbd>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
lea    0xde0(%rip),%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <File_AppendRecord@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/CMD_Data/.sms_phone.txt\00"
define i32 @SMS_AddPhone(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
%7 = bitcast [16 x i8]* %6 to i8*
%8 = call i32 @File_GetNumberOfRecords(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 16)
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %28, %1
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 16)
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @File_GetRecordByIndex(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16, i32 16, i32 %17)
%19 = icmp eq i32 %18, 16
br i1 %19, label %20, label %27
20: ; preds = %13
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %2
br label %41
26: ; preds = %20
br label %27
27: ; preds = %26, %13
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %9
31: ; preds = %9
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 16)
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = load i8*, i8** %3
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @memcpy(i8* %34, i8* %35, i32 %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%40 = call i32 @File_AppendRecord(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %39, i32 16)
store i32 %40, i32* %2
br label %41
41: ; preds = %31, %25
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [25 x i8] c"/CMD_Data/.sms_phone.txt\00"
define i32 @SMS_AddPhone(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @File_GetNumberOfRecords(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 16)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1, %14
%7 = phi i32 [ %15, %14 ], [ 0, %1 ]
%8 = call i32 @memset(i8* %3, i32 0, i32 16)
%9 = call i32 @File_GetRecordByIndex(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %3, i32 16, i32 %7)
%10 = icmp eq i32 %9, 16
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = call i64 @strcmp(i8* %3, i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %6, %11
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, %4
br i1 %16, label %17, label %6
17: ; preds = %14, %1
%18 = call i32 @memset(i8* %3, i32 0, i32 16)
%19 = call i32 @strlen(i8* %0)
%20 = call i32 @memcpy(i8* %3, i8* %0, i32 %19)
%21 = call i32 @File_AppendRecord(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %3, i32 16)
br label %22
22: ; preds = %11, %17
%23 = phi i32 [ %21, %17 ], [ 0, %11 ]
ret i32 %23
}