#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*/ sscanf(char const *, char *, int *, char *);
int strlen(char *);
void *strtol(char const *, int /*<<< orphan*/ *, int);
void ExtractXSSIFromCNUM(const char *p_str, int *p_idx, int *p_mcc, int *p_mnc,
                         long *p_ssi) {
  char tmp_buff[32];
  const char *p_buff;
  sscanf(p_str, "%d,%s", p_idx, tmp_buff);
  if (strlen(tmp_buff) < 14) {
    *p_mcc = 0;
    *p_mnc = 0;
    *p_ssi = strtol(tmp_buff, NULL, 10);
  } else {
    p_buff = tmp_buff + 7;
    *p_ssi = strtol(p_buff, NULL, 10);
    tmp_buff[7] = '\0';
    p_buff = tmp_buff + 3;
    *p_mnc = strtol(p_buff, NULL, 10);
    tmp_buff[3] = '\0';
    p_buff = tmp_buff;
    *p_mcc = strtol(p_buff, NULL, 10);
  }
}


x86 assembly (clang, -O0):
<ExtractXSSIFromCNUM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    0xea1(%rip),%rsi
call   1050 <sscanf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xe,%eax
jge    11ab <ExtractXSSIFromCNUM+0x7b>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1223 <ExtractXSSIFromCNUM+0xf3>
lea    -0x50(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x0,-0x49(%rbp)
lea    -0x50(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movb   $0x0,-0x4d(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExtractXSSIFromCNUM>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rdx
lea    0xeb2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rcx
call   1050 <sscanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0xd,%eax
jg     1189 <ExtractXSSIFromCNUM+0x59>
movl   $0x0,(%r14)
movl   $0x0,(%r12)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,(%r15)
jmp    11ce <ExtractXSSIFromCNUM+0x9e>
lea    0x7(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,(%r15)
movb   $0x0,0x7(%rsp)
lea    0x3(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r12)
movb   $0x0,0x3(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d,%s\00"
define void @ExtractXSSIFromCNUM(i8* %0, i32* %1, i32* %2, i32* %3, i64* %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i64*
%11 = alloca [32 x i8]
%12 = alloca i8*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i64* %4, i64** %10
%13 = load i8*, i8** %6
%14 = load i32*, i32** %7
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%16 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %14, i8* %15)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %18, 14
br i1 %19, label %20, label %27
20: ; preds = %5
%21 = load i32*, i32** %8
store i32 0, i32* %21
%22 = load i32*, i32** %9
store i32 0, i32* %22
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%24 = call i8* @strtol(i8* %23, i32* null, i32 10)
%25 = ptrtoint i8* %24 to i64
%26 = load i64*, i64** %10
store i64 %25, i64* %26
br label %47
27: ; preds = %5
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%29 = getelementptr inbounds i8, i8* %28, i64 7
store i8* %29, i8** %12
%30 = load i8*, i8** %12
%31 = call i8* @strtol(i8* %30, i32* null, i32 10)
%32 = ptrtoint i8* %31 to i64
%33 = load i64*, i64** %10
store i64 %32, i64* %33
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 7
store i8 0, i8* %34
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 3
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = call i8* @strtol(i8* %37, i32* null, i32 10)
%39 = ptrtoint i8* %38 to i32
%40 = load i32*, i32** %9
store i32 %39, i32* %40
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 3
store i8 0, i8* %41
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
store i8* %42, i8** %12
%43 = load i8*, i8** %12
%44 = call i8* @strtol(i8* %43, i32* null, i32 10)
%45 = ptrtoint i8* %44 to i32
%46 = load i32*, i32** %8
store i32 %45, i32* %46
br label %47
47: ; preds = %27, %20
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d,%s\00"
define void @ExtractXSSIFromCNUM(i8* nocapture %0, i32* %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i64* nocapture writeonly %4) {
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%8 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i8* %7)
%9 = call i32 @strlen(i8* %7)
%10 = icmp slt i32 %9, 14
br i1 %10, label %11, label %14
11: ; preds = %5
store i32 0, i32* %2
store i32 0, i32* %3
%12 = call i8* @strtol(i8* nocapture %7, i32* null, i32 10)
%13 = ptrtoint i8* %12 to i64
store i64 %13, i64* %4
br label %25
14: ; preds = %5
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 7
%16 = call i8* @strtol(i8* nocapture %15, i32* null, i32 10)
%17 = ptrtoint i8* %16 to i64
store i64 %17, i64* %4
store i8 0, i8* %15
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 3
%19 = call i8* @strtol(i8* nocapture %18, i32* null, i32 10)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
store i8 0, i8* %18
%22 = call i8* @strtol(i8* nocapture %7, i32* null, i32 10)
%23 = ptrtoint i8* %22 to i64
%24 = trunc i64 %23 to i32
store i32 %24, i32* %2
br label %25
25: ; preds = %14, %11
ret void
}