#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*/ time_t;
typedef int /*<<< orphan*/ sms_text;
typedef int /*<<< orphan*/ sms_phone;
typedef int /*<<< orphan*/ expected_sms_text;
typedef int /*<<< orphan*/ expected_sms_phone;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int DecodeSMS(unsigned char const *, int, int /*<<< orphan*/ *, char *, int,
              char *, int);
scalar_t__ memcmp(char const *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char const *);
int strlen(char const *);
int test_sms_decode() {
  const char expected_sms_phone[] = "27838890001";
  const char expected_sms_text[] = "hellohello";
  const unsigned char buffer[] = {
      0x07, 0x91, 0x72, 0x83, 0x01, 0x00, 0x10, 0xF5, 0x04, 0x0B, 0xC8, 0x72,
      0x38, 0x88, 0x09, 0x00, 0xF1, 0x00, 0x00, 0x99, 0x30, 0x92, 0x51, 0x61,
      0x95, 0x80, 0x0A, 0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37};
  time_t sms_time;
  char sms_phone[sizeof(expected_sms_phone)];
  char sms_text[sizeof(expected_sms_text)];
  int sms_text_length =
      DecodeSMS(buffer, sizeof(buffer), &sms_time, sms_phone, sizeof(sms_phone),
                sms_text, sizeof(sms_text));
  printf("Decoded SMS: \"%s\"\n", sms_text);
  if (sms_text_length != strlen(expected_sms_text)) {
    printf("SMS decoding buffer size failed!\n");
    return -1;
  }
  if (memcmp(expected_sms_text, sms_text, sms_text_length)) {
    printf("SMS decoding failed!\n");
    return -1;
  }
  if (strcmp(sms_phone, expected_sms_phone)) {
    printf("SMS decoding phone number failed!\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_sms_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xe89(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xe86(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe7e(%rip),%al
mov    %al,-0x11(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeea(%rip),%rsi
mov    $0x24,%edx
call   1080 <memcpy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rcx
lea    -0x5b(%rbp),%r9
mov    $0x24,%esi
lea    -0x44(%rbp),%rdx
mov    $0xc,%r8d
movl   $0xb,(%rsp)
call   1050 <DecodeSMS@plt>
mov    %eax,-0x60(%rbp)
lea    -0x5b(%rbp),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x1b(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cmp    %ecx,%eax
je     1222 <test_sms_decode+0xc2>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <test_sms_decode+0x12e>
lea    -0x1b(%rbp),%rdi
lea    -0x5b(%rbp),%rsi
mov    -0x60(%rbp),%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     1256 <test_sms_decode+0xf6>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <test_sms_decode+0x12e>
lea    -0x50(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1287 <test_sms_decode+0x127>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128e <test_sms_decode+0x12e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sms_decode>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movabs $0x3039383833383732,%rax
38 39 30
mov    %rax,0x18(%rsp)
movl   $0x313030,0x20(%rsp)
movabs $0x6c65686f6c6c6568,%rax
68 65 6c
mov    %rax,0x8(%rsp)
movl   $0x6f6c6c,0xf(%rsp)
movaps 0xf04(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee8(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movl   $0x37ecd997,0x60(%rsp)
37
movl   $0xb,(%rsp)
lea    0x40(%rsp),%rdi
lea    0x24(%rsp),%rdx
lea    0x34(%rsp),%rcx
lea    0x29(%rsp),%r14
mov    $0x24,%esi
mov    $0xc,%r8d
mov    %r14,%r9
call   1060 <DecodeSMS@plt>
mov    %eax,%ebx
lea    0xe2b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebx
jne    1223 <test_sms_decode+0xc3>
lea    0x8(%rsp),%rdi
lea    0x29(%rsp),%rsi
mov    %ebx,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     123c <test_sms_decode+0xdc>
lea    0xe2b(%rip),%rdi
jmp    122a <test_sms_decode+0xca>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0x34(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1259 <test_sms_decode+0xf9>
lea    0xdd3(%rip),%rdi
jmp    122a <test_sms_decode+0xca>
xor    %eax,%eax
jmp    1234 <test_sms_decode+0xd4>

LLVM IR (-O0):
@__const.test_sms_decode.expected_sms_phone = [12 x i8] c"27838890001\00"
@__const.test_sms_decode.expected_sms_text = [11 x i8] c"hellohello\00"
@__const.test_sms_decode.buffer = [36 x i8] c"\07\91r\83\01\00\10\F5\04\0B\C8r8\88\09\00\F1\00\00\990\92Qa\95\80\0A\E82\9B\FDF\97\D9\EC7"
@.str = [19 x i8] c"Decoded SMS: \22%s\22\0A\00"
@.str.1 = [34 x i8] c"SMS decoding buffer size failed!\0A\00"
@.str.2 = [22 x i8] c"SMS decoding failed!\0A\00"
@.str.3 = [35 x i8] c"SMS decoding phone number failed!\0A\00"
define i32 @test_sms_decode() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [11 x i8]
%4 = alloca [36 x i8]
%5 = alloca i32
%6 = alloca [12 x i8]
%7 = alloca [11 x i8]
%8 = alloca i32
%9 = bitcast [12 x i8]* %2 to i8*
%10 = bitcast [11 x i8]* %3 to i8*
%11 = bitcast [36 x i8]* %4 to i8*
%12 = getelementptr inbounds [36 x i8], [36 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%15 = call i32 @DecodeSMS(i8* %12, i32 36, i32* %5, i8* %13, i32 12, i8* %14, i32 11)
store i32 %15, i32* %8
%16 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %8
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %40
24: ; preds = %0
%25 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%26 = getelementptr inbounds [11 x i8], [11 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %8
%28 = call i64 @memcmp(i8* %25, i8* %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %40
32: ; preds = %24
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%34 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %40
39: ; preds = %32
store i32 0, i32* %1
br label %40
40: ; preds = %39, %37, %30, %22
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.test_sms_decode.expected_sms_phone = [12 x i8] c"27838890001\00"
@__const.test_sms_decode.expected_sms_text = [11 x i8] c"hellohello\00"
@__const.test_sms_decode.buffer = [36 x i8] c"\07\91r\83\01\00\10\F5\04\0B\C8r8\88\09\00\F1\00\00\990\92Qa\95\80\0A\E82\9B\FDF\97\D9\EC7"
@.str = [19 x i8] c"Decoded SMS: \22%s\22\0A\00"
@str = [34 x i8] c"SMS decoding phone number failed!\00"
@str.4 = [21 x i8] c"SMS decoding failed!\00"
@str.5 = [33 x i8] c"SMS decoding buffer size failed!\00"
define i32 @test_sms_decode() {
%1 = alloca [12 x i8]
%2 = alloca [11 x i8]
%3 = alloca [36 x i8]
%4 = alloca i32
%5 = alloca [12 x i8]
%6 = alloca [11 x i8]
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [36 x i8], [36 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
%13 = call i32 @DecodeSMS(i8* %9, i32 36, i32* %4, i8* %11, i32 12, i8* %12, i32 11)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%15 = call i32 @strlen(i8* %8)
%16 = icmp eq i32 %13, %15
br i1 %16, label %17, label %23
17: ; preds = %0
%18 = call i64 @memcmp(i8* %8, i8* %12, i32 %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i64 @strcmp(i8* %11, i8* %7)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20, %17, %0
%24 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0), %17 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0), %20 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
br label %26
26: ; preds = %23, %20
%27 = phi i32 [ 0, %20 ], [ -1, %23 ]
ret i32 %27
}