#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  char line[2048], *pStr;
  int mcc;
  int bThreeDigit, mnc;
  int current_line = 0;
  if (argc < 2) {
    printf("Usage %s <ConnectionProfile.csv>\nGenerates mnc_list.h", argv[0]);
    exit(1);
  }
  in = fopen(argv[1], "r");
  out = fopen("mnc_list.h", "w");
  if (in == NULL || out == NULL) {
    printf("can't open files\n");
    exit(1);
  }
  fprintf(out, "typedef struct {\n    int mcc;\n    int bT;\n    int mnc;\n} "
               "MNC_LIST;\nMNC_LIST mnc_list[] = {\n");
  while (fgets(line, 2048, in) != NULL) {
    current_line++;
    if (*line == ';' || *line == ' ' || *line == '\r' || *line == '\n')
      continue;
    mcc = strtol(line, &pStr, 10);
    pStr++;
    if (*pStr != 'T' && *pStr != 'F') {
      printf("Error in file - field 2 line %d\n", current_line);
      exit(1);
    }
    if (*pStr == 'T')
      bThreeDigit = 1;
    else
      bThreeDigit = 0;
    pStr += 2;
    while (*pStr != ',') {
      if (*pStr == ';')
        pStr++;
      mnc = strtol(pStr, &pStr, 10);
      fprintf(out, "{%d,%d,%d},\n", mcc, bThreeDigit, mnc);
    }
  }
  fprintf(out, "{0, 0, 0}\n};\n");
  fclose(out);
  fclose(in);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x838(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1201 <main+0x91>
cmpq   $0x0,-0x20(%rbp)
jne    1219 <main+0xa9>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     13d5 <main+0x265>
mov    -0x838(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x838(%rbp)
movsbl -0x820(%rbp),%eax
cmp    $0x3b,%eax
je     1299 <main+0x129>
movsbl -0x820(%rbp),%eax
cmp    $0x20,%eax
je     1299 <main+0x129>
movsbl -0x820(%rbp),%eax
cmp    $0xd,%eax
je     1299 <main+0x129>
movsbl -0x820(%rbp),%eax
cmp    $0xa,%eax
jne    129e <main+0x12e>
jmp    122b <main+0xbb>
lea    -0x820(%rbp),%rdi
lea    -0x828(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x82c(%rbp)
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x54,%eax
je     1312 <main+0x1a2>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
je     1312 <main+0x1a2>
mov    -0x838(%rbp),%esi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x54,%eax
jne    1334 <main+0x1c4>
movl   $0x1,-0x830(%rbp)
jmp    133e <main+0x1ce>
movl   $0x0,-0x830(%rbp)
mov    -0x828(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     13d0 <main+0x260>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3b,%eax
jne    1388 <main+0x218>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rdi
lea    -0x828(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x834(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x82c(%rbp),%edx
mov    -0x830(%rbp),%ecx
mov    -0x834(%rbp),%r8d
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1350 <main+0x1e0>
jmp    122b <main+0xbb>
mov    -0x20(%rbp),%rdi
lea    0xcf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
cmp    $0x1,%edi
jle    1349 <main+0x1b9>
mov    0x8(%rsi),%rdi
lea    0xe81(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbp
lea    0xe67(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rbp,0x8(%rsp)
test   %rbp,%rbp
je     1364 <main+0x1d4>
mov    %rax,%rbx
test   %rax,%rax
je     1364 <main+0x1d4>
lea    0xe49(%rip),%rdi
mov    $0x5b,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
mov    0x8(%rsp),%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12ef <main+0x15f>
mov    %rsp,%r13
lea    0xe8d(%rip),%rbp
xor    %r12d,%r12d
jmp    124d <main+0xbd>
nop
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
mov    0x8(%rsp),%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12ef <main+0x15f>
add    $0x1,%r12d
movzbl 0x10(%rsp),%eax
cmp    $0x3b,%rax
ja     126c <main+0xdc>
movabs $0x800000100002400,%rcx
bt     %rax,%rcx
jb     1230 <main+0xa0>
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %eax,%r15d
mov    (%rsp),%rdi
mov    0x1(%rdi),%al
cmp    $0x46,%al
je     1294 <main+0x104>
cmp    $0x54,%al
jne    132e <main+0x19e>
xor    %r14d,%r14d
cmp    $0x54,%al
sete   %r14b
add    $0x3,%rdi
mov    %rdi,(%rsp)
jmp    12df <main+0x14f>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdi
mov    %rdi,(%rsp)
mov    %r13,%rsi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rsp),%rdi
movzbl (%rdi),%eax
cmp    $0x3b,%al
je     12b0 <main+0x120>
cmp    $0x2c,%al
jne    12b8 <main+0x128>
jmp    1230 <main+0xa0>
lea    0xdce(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd61(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    (%rsi),%rsi
lea    0xcad(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Usage %s <ConnectionProfile.csv>\0AGenerates mnc_list.h\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"mnc_list.h\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [18 x i8] c"can't open files\0A\00"
@.str.5 = [92 x i8] c"typedef struct {\0A int mcc;\0A int bT;\0A int mnc;\0A} MNC_LIST;\0AMNC_LIST mnc_list[] = {\0A\00"
@.str.6 = [33 x i8] c"Error in file - field 2 line %d\0A\00"
@.str.7 = [13 x i8] c"{%d,%d,%d},\0A\00"
@.str.8 = [14 x i8] c"{0, 0, 0}\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [2048 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %6
%29 = icmp eq i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i32*, i32** %7
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30, %22
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %30
%37 = load i32*, i32** %7
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %116, %66, %36
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%41 = load i32*, i32** %6
%42 = call i32* @fgets(i8* %40, i32 2048, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %117
44: ; preds = %39
%45 = load i32, i32* %13
%46 = add nsw i32 %45, 1
store i32 %46, i32* %13
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 59
br i1 %50, label %66, label %51
51: ; preds = %44
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 32
br i1 %55, label %66, label %56
56: ; preds = %51
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 13
br i1 %60, label %66, label %61
61: ; preds = %56
%62 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 10
br i1 %65, label %66, label %67
66: ; preds = %61, %56, %51, %44
br label %39
67: ; preds = %61
%68 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%69 = call i32 @strtol(i8* %68, i8** %9, i32 10)
store i32 %69, i32* %10
%70 = load i8*, i8** %9
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %9
%72 = load i8*, i8** %9
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 84
br i1 %75, label %76, label %85
76: ; preds = %67
%77 = load i8*, i8** %9
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 70
br i1 %80, label %81, label %85
81: ; preds = %76
%82 = load i32, i32* %13
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %82)
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %76, %67
%86 = load i8*, i8** %9
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 84
br i1 %89, label %90, label %91
90: ; preds = %85
store i32 1, i32* %11
br label %92
91: ; preds = %85
store i32 0, i32* %11
br label %92
92: ; preds = %91, %90
%93 = load i8*, i8** %9
%94 = getelementptr inbounds i8, i8* %93, i64 2
store i8* %94, i8** %9
br label %95
95: ; preds = %108, %92
%96 = load i8*, i8** %9
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp ne i32 %98, 44
br i1 %99, label %100, label %116
100: ; preds = %95
%101 = load i8*, i8** %9
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = icmp eq i32 %103, 59
br i1 %104, label %105, label %108
105: ; preds = %100
%106 = load i8*, i8** %9
%107 = getelementptr inbounds i8, i8* %106, i32 1
store i8* %107, i8** %9
br label %108
108: ; preds = %105, %100
%109 = load i8*, i8** %9
%110 = call i32 @strtol(i8* %109, i8** %9, i32 10)
store i32 %110, i32* %12
%111 = load i32*, i32** %7
%112 = load i32, i32* %10
%113 = load i32, i32* %11
%114 = load i32, i32* %12
%115 = call i32 (i32*, i8*, ...) @fprintf(i32* %111, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %112, i32 %113, i32 %114)
br label %95
116: ; preds = %95
br label %39
117: ; preds = %39
%118 = load i32*, i32** %7
%119 = call i32 (i32*, i8*, ...) @fprintf(i32* %118, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%120 = load i32*, i32** %7
%121 = call i32 @fclose(i32* %120)
%122 = load i32*, i32** %6
%123 = call i32 @fclose(i32* %122)
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
@.str = [54 x i8] c"Usage %s <ConnectionProfile.csv>\0AGenerates mnc_list.h\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"mnc_list.h\00"
@.str.3 = [2 x i8] c"w\00"
@.str.5 = [92 x i8] c"typedef struct {\0A int mcc;\0A int bT;\0A int mnc;\0A} MNC_LIST;\0AMNC_LIST mnc_list[] = {\0A\00"
@.str.6 = [33 x i8] c"Error in file - field 2 line %d\0A\00"
@.str.7 = [13 x i8] c"{%d,%d,%d},\0A\00"
@.str.8 = [14 x i8] c"{0, 0, 0}\0A};\0A\00"
@str = [17 x i8] c"can't open files\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %15, null
%18 = icmp eq i32* %16, null
%19 = or i1 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0), i64 91, i64 1, i32* %16)
%25 = call i32* @fgets(i8* %5, i32 2048, i32* %15)
%26 = icmp eq i32* %25, null
br i1 %26, label %56, label %27
27: ; preds = %23, %31
%28 = phi i32 [ %29, %31 ], [ 0, %23 ]
%29 = add nuw nsw i32 %28, 1
%30 = load i8, i8* %5
switch i8 %30, label %34 [
i8 59, label %31
i8 32, label %31
i8 13, label %31
i8 10, label %31
]
31: ; preds = %46, %27, %27, %27, %27
%32 = call i32* @fgets(i8* %5, i32 2048, i32* %15)
%33 = icmp eq i32* %32, null
br i1 %33, label %56, label %27
34: ; preds = %27
%35 = call i32 @strtol(i8* %5, i8** %4, i32 10)
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
switch i8 %38, label %39 [
i8 84, label %42
i8 70, label %42
]
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34, %34
%43 = icmp eq i8 %38, 84
%44 = zext i1 %43 to i32
%45 = getelementptr inbounds i8, i8* %36, i64 3
store i8* %45, i8** %4
br label %46
46: ; preds = %51, %42
%47 = phi i8* [ %55, %51 ], [ %45, %42 ]
%48 = load i8, i8* %47
switch i8 %48, label %51 [
i8 44, label %31
i8 59, label %49
]
49: ; preds = %46
%50 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %50, i8** %4
br label %51
51: ; preds = %46, %49
%52 = phi i8* [ %47, %46 ], [ %50, %49 ]
%53 = call i32 @strtol(i8* %52, i8** %4, i32 10)
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %44, i32 %53)
%55 = load i8*, i8** %4
br label %46
56: ; preds = %31, %23
%57 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %16)
%58 = call i32 @fclose(i32* %16)
%59 = call i32 @fclose(i32* %15)
ret i32 0
}