#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 /*<<< orphan*/ gsm_dso2string(char *, char *);
int gsm_hex2int(char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *pdu_get_send_number(const char *pdu, char *number, int len) {
  const char *p;
  int number_len;
  char tmp[512];
  p = pdu;
  number_len = gsm_hex2int(p, 2);
  if (0 == number_len) {
    p += 2 + 2 + 2;
  } else {
    p += 2 + 2 + number_len * 2 + 2 + 2;
  }
  number_len = gsm_hex2int(p, 2);
  if (number_len & 1)
    number_len += 1;
  strncpy(tmp, p + 2 + 2, number_len);
  tmp[number_len] = '\0';
  gsm_dso2string(number, tmp);
  return number;
}


x86 assembly (clang, -O0):
<pdu_get_send_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1050 <gsm_hex2int@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jne    117b <pdu_get_send_number+0x4b>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
jmp    1198 <pdu_get_send_number+0x68>
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    $0x4,%ecx
add    $0x2,%ecx
add    $0x2,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1050 <gsm_hex2int@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11c1 <pdu_get_send_number+0x91>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x2,%rsi
add    $0x2,%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   1040 <gsm_dso2string@plt>
mov    -0x10(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdu_get_send_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2,%esi
call   1050 <gsm_hex2int@plt>
test   %eax,%eax
lea    0x8(%rax,%rax,1),%eax
mov    $0x6,%ecx
cmovne %eax,%ecx
movslq %ecx,%rbx
lea    (%r15,%rbx,1),%rdi
mov    $0x2,%esi
call   1050 <gsm_hex2int@plt>
mov    %eax,%ebp
and    $0x1,%ebp
add    %eax,%ebp
lea    (%r15,%rbx,1),%rsi
add    $0x4,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <gsm_dso2string@plt>
mov    %r14,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @pdu_get_send_number(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @gsm_hex2int(i8* %11, i32 2)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 0, %13
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 6
store i8* %17, i8** %7
br label %27
18: ; preds = %3
%19 = load i32, i32* %8
%20 = mul nsw i32 %19, 2
%21 = add nsw i32 4, %20
%22 = add nsw i32 %21, 2
%23 = add nsw i32 %22, 2
%24 = load i8*, i8** %7
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %7
br label %27
27: ; preds = %18, %15
%28 = load i8*, i8** %7
%29 = call i32 @gsm_hex2int(i8* %28, i32 2)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = and i32 %30, 1
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %33, %27
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = load i32, i32* %8
%42 = call i32 @strncpy(i8* %37, i8* %40, i32 %41)
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i8*, i8** %5
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%48 = call i32 @gsm_dso2string(i8* %46, i8* %47)
%49 = load i8*, i8** %5
ret i8* %49
}

LLVM IR (-O2):
define i8* @pdu_get_send_number(i8* %0, i8* returned %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @gsm_hex2int(i8* %0, i32 2)
%7 = icmp eq i32 %6, 0
%8 = shl nsw i32 %6, 1
%9 = add nsw i32 %8, 8
%10 = select i1 %7, i32 6, i32 %9
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @gsm_hex2int(i8* %12, i32 2)
%14 = and i32 %13, 1
%15 = add nsw i32 %14, %13
%16 = getelementptr inbounds i8, i8* %12, i64 4
%17 = call i32 @strncpy(i8* %5, i8* %16, i32 %15)
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @gsm_dso2string(i8* %1, i8* %5)
ret i8* %1
}