#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 atoi(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int mnc_get_length(const char *imsi) {
  int nspec_mcc[] = {302, 310, 311, 316, 334, 338, 342, 344, 346,
                     348, 365, 374, 376, 708, 722, 732, 0};
  char mcc[3 + 1];
  int i = 0, found = 0, ret;
  int nmcc;
  char mnc[3 + 1];
  strncpy(mcc, imsi, 3);
  mcc[3] = 0;
  nmcc = atoi(mcc);
  while (nspec_mcc[i] && !found) {
    if (nmcc == nspec_mcc[i]) {
      found = 1;
      break;
    }
    ++i;
  }
  if (!found) {
    ret = 2;
    goto exit;
  }
  switch (nmcc) {
  case 302:
    strncpy(mnc, imsi + 3, 3);
    mnc[3] = 0;
    ret = (atoi(mnc) == 656 ? 2 : 3);
    break;
  case 374:
    strncpy(mnc, imsi + 3, 3);
    mnc[3] = 0;
    ret = (atoi(mnc) == 12 ? 2 : 3);
    break;
  default:
    ret = 3;
  }
exit:
  return ret;
}


x86 assembly (clang, -O0):
<mnc_get_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xeb9(%rip),%rsi
mov    $0x44,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
lea    -0x54(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x51(%rbp)
lea    -0x54(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x64(%rbp)
movslq -0x58(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,-0x50(%rbp,%rcx,4)
mov    %al,-0x69(%rbp)
je     11a1 <mnc_get_length+0x71>
cmpl   $0x0,-0x5c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    11b1 <mnc_get_length+0x81>
jmp    11dc <mnc_get_length+0xac>
mov    -0x64(%rbp),%eax
movslq -0x58(%rbp),%rcx
cmp    -0x50(%rbp,%rcx,4),%eax
jne    11ce <mnc_get_length+0x9e>
movl   $0x1,-0x5c(%rbp)
jmp    11dc <mnc_get_length+0xac>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1181 <mnc_get_length+0x51>
cmpl   $0x0,-0x5c(%rbp)
jne    11f2 <mnc_get_length+0xc2>
movl   $0x2,-0x60(%rbp)
jmp    12a4 <mnc_get_length+0x174>
mov    -0x64(%rbp),%eax
mov    %eax,-0x70(%rbp)
sub    $0x12e,%eax
je     121b <mnc_get_length+0xeb>
jmp    1208 <mnc_get_length+0xd8>
mov    -0x70(%rbp),%eax
sub    $0x176,%eax
je     125b <mnc_get_length+0x12b>
jmp    1298 <mnc_get_length+0x168>
lea    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x65(%rbp)
lea    -0x68(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
mov    $0x3,%eax
mov    $0x2,%ecx
cmp    $0x290,%edx
cmove  %ecx,%eax
mov    %eax,-0x60(%rbp)
jmp    129f <mnc_get_length+0x16f>
lea    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x3,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x65(%rbp)
lea    -0x68(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
mov    $0x3,%eax
mov    $0x2,%ecx
cmp    $0xc,%edx
cmove  %ecx,%eax
mov    %eax,-0x60(%rbp)
jmp    129f <mnc_get_length+0x16f>
movl   $0x3,-0x60(%rbp)
jmp    12a4 <mnc_get_length+0x174>
mov    -0x60(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mnc_get_length>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    $0x2,%eax
lea    -0x12e(%rcx),%edx
cmp    $0x4a,%edx
ja     1178 <mnc_get_length+0x58>
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0xfffffd3c,%ecx
cmp    $0x18,%ecx
ja     1170 <mnc_get_length+0x50>
mov    $0x1004001,%edx
bt     %ecx,%edx
jb     116b <mnc_get_length+0x4b>
jmp    1170 <mnc_get_length+0x50>
add    $0x3,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x3(%rsp)
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x290,%ecx
jmp    11ea <mnc_get_length+0xca>
add    $0x3,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x3(%rsp)
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xc,%ecx
sete   %al
xor    $0x3,%eax
jmp    1170 <mnc_get_length+0x50>

LLVM IR (-O0):
@__const.mnc_get_length.nspec_mcc = [17 x i32] [i32 302, i32 310, i32 311, i32 316, i32 334, i32 338, i32 342, i32 344, i32 346, i32 348, i32 365, i32 374, i32 376, i32 708, i32 722, i32 732, i32 0]
define i32 @mnc_get_length(i8* %0) {
%2 = alloca i8*
%3 = alloca [17 x i32]
%4 = alloca [4 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8]
store i8* %0, i8** %2
%10 = bitcast [17 x i32]* %3 to i8*
store i32 0, i32* %5
store i32 0, i32* %6
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%12 = load i8*, i8** %2
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 3)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 0, i8* %14
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %8
br label %17
17: ; preds = %37, %1
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [17 x i32], [17 x i32]* %3, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br label %27
27: ; preds = %23, %17
%28 = phi i1 [ false, %17 ], [ %26, %23 ]
br i1 %28, label %29, label %40
29: ; preds = %27
%30 = load i32, i32* %8
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [17 x i32], [17 x i32]* %3, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %30, %34
br i1 %35, label %36, label %37
36: ; preds = %29
store i32 1, i32* %6
br label %40
37: ; preds = %29
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %17
40: ; preds = %36, %27
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %40
store i32 2, i32* %7
br label %70
44: ; preds = %40
%45 = load i32, i32* %8
switch i32 %45, label %68 [
i32 302, label %46
i32 374, label %57
]
46: ; preds = %44
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%48 = load i8*, i8** %2
%49 = getelementptr inbounds i8, i8* %48, i64 3
%50 = call i32 @strncpy(i8* %47, i8* %49, i32 3)
%51 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 0, i8* %51
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%53 = call i32 @atoi(i8* %52)
%54 = icmp eq i32 %53, 656
%55 = zext i1 %54 to i64
%56 = select i1 %54, i32 2, i32 3
store i32 %56, i32* %7
br label %69
57: ; preds = %44
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%59 = load i8*, i8** %2
%60 = getelementptr inbounds i8, i8* %59, i64 3
%61 = call i32 @strncpy(i8* %58, i8* %60, i32 3)
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 0, i8* %62
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%64 = call i32 @atoi(i8* %63)
%65 = icmp eq i32 %64, 12
%66 = zext i1 %65 to i64
%67 = select i1 %65, i32 2, i32 3
store i32 %67, i32* %7
br label %69
68: ; preds = %44
store i32 3, i32* %7
br label %69
69: ; preds = %68, %57, %46
br label %70
70: ; preds = %69, %43
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
define i32 @mnc_get_length(i8* %0) {
%2 = alloca [4 x i8]
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = call i32 @strncpy(i8* %4, i8* %0, i32 3)
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %7
%8 = call i32 @atoi(i8* %4)
switch i32 %8, label %24 [
i32 302, label %10
i32 310, label %9
i32 311, label %9
i32 316, label %9
i32 334, label %9
i32 338, label %9
i32 342, label %9
i32 344, label %9
i32 346, label %9
i32 348, label %9
i32 365, label %9
i32 374, label %17
i32 376, label %9
i32 708, label %9
i32 722, label %9
i32 732, label %9
]
9: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1, %1
br label %24
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = call i32 @strncpy(i8* %5, i8* %11, i32 3)
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %13
%14 = call i32 @atoi(i8* %5)
%15 = icmp eq i32 %14, 656
%16 = select i1 %15, i32 2, i32 3
br label %24
17: ; preds = %1
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = call i32 @strncpy(i8* %5, i8* %18, i32 3)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
store i8 0, i8* %20
%21 = call i32 @atoi(i8* %5)
%22 = icmp eq i32 %21, 12
%23 = select i1 %22, i32 2, i32 3
br label %24
24: ; preds = %1, %9, %10, %17
%25 = phi i32 [ %23, %17 ], [ %16, %10 ], [ 3, %9 ], [ 2, %1 ]
ret i32 %25
}