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

/* Variables and functions */
int EncodeSMS(char *, char *, char *, int, unsigned char *, int);
scalar_t__ memcmp(unsigned char const *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_sms_encode() {
  const unsigned char expected_buffer[] = {
      0x07, 0x91, 0x72, 0x83, 0x01, 0x00, 0x10, 0xF5, 0x11, 0x00, 0x0B,
      0x91, 0x64, 0x07, 0x28, 0x15, 0x53, 0xF8, 0x00, 0x00, 0xB0, 0x0A,
      0xE8, 0x32, 0x9B, 0xFD, 0x46, 0x97, 0xD9, 0xEC, 0x37};
  unsigned char buffer[36];
  int buffer_length = EncodeSMS("27381000015", "46708251358", "hellohello", 10,
                                buffer, sizeof(buffer));
  printf("Encoded SMS: ");
  int i = 0;
  for (; i < buffer_length; ++i) {
    printf("%02X", buffer[i]);
  }
  printf("\n");
  if (buffer_length != sizeof(expected_buffer)) {
    printf("SMS encoding buffer size failed!\n");
    return -1;
  }
  if (memcmp(expected_buffer, buffer, buffer_length)) {
    printf("SMS encoding failed!\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_sms_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb9(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xeb3(%rip),%ax
mov    %ax,-0x14(%rbp)
mov    0xeab(%rip),%al
mov    %al,-0x12(%rbp)
lea    -0x60(%rbp),%r8
lea    0xe9e(%rip),%rdi
lea    0xea3(%rip),%rsi
lea    0xea8(%rip),%rdx
mov    $0xa,%ecx
mov    $0x24,%r9d
call   1030 <EncodeSMS@plt>
mov    %eax,-0x64(%rbp)
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11e8 <test_sms_encode+0xb8>
movslq -0x68(%rbp),%rax
movzbl -0x60(%rbp,%rax,1),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11b7 <test_sms_encode+0x87>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x64(%rbp),%rax
cmp    $0x1f,%rax
je     121e <test_sms_encode+0xee>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1259 <test_sms_encode+0x129>
lea    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     1252 <test_sms_encode+0x122>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1259 <test_sms_encode+0x129>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sms_encode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
movups 0xeae(%rip),%xmm0
movups %xmm0,0xf(%rsp)
movaps 0xe93(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xea7(%rip),%rdi
lea    0xeac(%rip),%rsi
lea    0xeb1(%rip),%rdx
lea    0x20(%rsp),%r8
mov    $0xa,%ecx
mov    $0x24,%r9d
call   1040 <EncodeSMS@plt>
mov    %eax,%r14d
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
jle    1208 <test_sms_encode+0xb8>
mov    %r14d,%ebp
lea    0xe95(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
movzbl 0x20(%rsp,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <test_sms_encode+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x1f,%r14d
jne    1212 <test_sms_encode+0xc2>
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
mov    $0x1f,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     122e <test_sms_encode+0xde>
lea    0xe4f(%rip),%rdi
jmp    1219 <test_sms_encode+0xc9>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe51(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1223 <test_sms_encode+0xd3>

LLVM IR (-O0):
@__const.test_sms_encode.expected_buffer = [31 x i8] c"\07\91r\83\01\00\10\F5\11\00\0B\91d\07(\15S\F8\00\00\B0\0A\E82\9B\FDF\97\D9\EC7"
@.str = [12 x i8] c"27381000015\00"
@.str.1 = [12 x i8] c"46708251358\00"
@.str.2 = [11 x i8] c"hellohello\00"
@.str.3 = [14 x i8] c"Encoded SMS: \00"
@.str.4 = [5 x i8] c"%02X\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [34 x i8] c"SMS encoding buffer size failed!\0A\00"
@.str.7 = [22 x i8] c"SMS encoding failed!\0A\00"
define i32 @test_sms_encode() {
%1 = alloca i32
%2 = alloca [31 x i8]
%3 = alloca [36 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [31 x i8]* %2 to i8*
%7 = getelementptr inbounds [36 x i8], [36 x i8]* %3, i64 0, i64 0
%8 = call i32 @EncodeSMS(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10, i8* %7, i32 36)
store i32 %8, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [36 x i8], [36 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %14
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %10
24: ; preds = %10
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = icmp ne i64 %27, 31
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %40
31: ; preds = %24
%32 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 0
%33 = getelementptr inbounds [36 x i8], [36 x i8]* %3, i64 0, i64 0
%34 = load i32, i32* %4
%35 = call i64 @memcmp(i8* %32, i8* %33, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %40
39: ; preds = %31
store i32 0, i32* %1
br label %40
40: ; preds = %39, %37, %29
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@__const.test_sms_encode.expected_buffer = [31 x i8] c"\07\91r\83\01\00\10\F5\11\00\0B\91d\07(\15S\F8\00\00\B0\0A\E82\9B\FDF\97\D9\EC7"
@.str = [12 x i8] c"27381000015\00"
@.str.1 = [12 x i8] c"46708251358\00"
@.str.2 = [11 x i8] c"hellohello\00"
@.str.3 = [14 x i8] c"Encoded SMS: \00"
@.str.4 = [5 x i8] c"%02X\00"
@str = [21 x i8] c"SMS encoding failed!\00"
@str.8 = [33 x i8] c"SMS encoding buffer size failed!\00"
define i32 @test_sms_encode() {
%1 = alloca [31 x i8]
%2 = alloca [36 x i8]
%3 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [36 x i8], [36 x i8]* %2, i64 0, i64 0
%5 = call i32 @EncodeSMS(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10, i8* %4, i32 36)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp sgt i32 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @putchar(i32 10)
br label %26
10: ; preds = %0
%11 = zext i32 %5 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %18, %12 ]
%14 = getelementptr inbounds [36 x i8], [36 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = call i32 @putchar(i32 10)
%22 = icmp eq i32 %5, 31
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i64 @memcmp(i8* %3, i8* %4, i32 31)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23, %20, %8
%27 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0), %8 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), %23 ]
%28 = call i32 @puts(i8* dereferenceable(1) %27)
br label %29
29: ; preds = %26, %23
%30 = phi i32 [ 0, %23 ], [ -1, %26 ]
ret i32 %30
}