#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*/ SEEK_SET;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/ *);
int find_country(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *get_mirrors(int /*<<< orphan*/ *);
scalar_t__ isspace(char);
char *ltrim(char *, char);
char *next_entry(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
char *realloc(char *, int);
char *rtrim(char *, char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ str_toupper(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
char *trim(char *, char);
int build_area_file(FILE *config_p, FILE *infile_p, FILE *mirror_list,
                    char *area) {
  char *line = NULL;
  char *tmp = NULL;
  char *inputline = NULL;
  char *country_code = NULL;
  int infilePos;
  char *dirs;
  char *aliasList;
  char *dst;
  char *mirrorData;
  char *token;
  str_toupper(area);
  while ((line = next_entry(config_p)) != NULL) {
    str_toupper(line);
    if ((tmp = strstr(line, area)) != NULL) {
      if ((strchr(tmp, ':')) == NULL) {
        free(line);
        continue;
      }
      break;
    }
    free(line);
    if (ferror(config_p) != 0)
      return 1;
  }
  if (line == NULL) {
    fprintf(stderr, "Could not find area named %s\n", area);
    return 1;
  }
  free(line);
  while ((line = next_entry(config_p)) != NULL) {
    if (ferror(config_p) != 0) {
      free(line);
      return 1;
    }
    country_code = line;
    while ((*country_code != '\n') && (isspace(*country_code) != 0))
      ++country_code;
    if ((*country_code == '\n') || (*country_code == '#')) {
      free(line);
      continue;
    }
    if ((strchr(line, ':')) != NULL) {
      free(line);
      return 0;
    }
    if (strlen(country_code) < 3) {
      line = realloc(line, strlen(line) + 4 - strlen(country_code));
      if (line == NULL) {
        perror("realloc");
        exit(1);
      }
    }
    *(country_code + 2) = ' ';
    *(country_code + 3) = '\0';
    if (find_country(mirror_list, country_code) == 1) {
      fprintf(stderr, "Couldn't find country %s. Skipping.\n", country_code);
      free(line);
      continue;
    }
    while ((inputline = get_mirrors(mirror_list)) != NULL) {
      if (strstr(inputline, "  (") == NULL) {
        infilePos = ftell(infile_p);
        fputs(inputline, infile_p);
        if ((ferror(infile_p)) != 0) {
          free(line);
          return 1;
        }
      } else {
        fseek(infile_p, infilePos, SEEK_SET);
        mirrorData = next_entry(infile_p);
        aliasList = trim(inputline, ' ');
        aliasList = ltrim(aliasList, '(');
        aliasList = rtrim(aliasList, ')');
        dirs = strstr(mirrorData, ":");
        token = strtok(aliasList, ", ");
        while (token != NULL) {
          dst = (char *)calloc(strlen(token) + strlen(mirrorData) + 1,
                               sizeof(char));
          strcpy(dst, token);
          strcat(dst, dirs);
          fputs(dst, infile_p);
          token = strtok(NULL, ", ");
          free(dst);
        }
      }
    }
    free(inputline);
    free(line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<build_area_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1160 <str_toupper@plt>
mov    -0x10(%rbp),%rdi
call   1130 <next_entry@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1357 <build_area_file+0xd7>
mov    -0x30(%rbp),%rdi
call   1160 <str_toupper@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   11a0 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     132a <build_area_file+0xaa>
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    1325 <build_area_file+0xa5>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12c4 <build_area_file+0x44>
jmp    1357 <build_area_file+0xd7>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1352 <build_area_file+0xd2>
movl   $0x1,-0x4(%rbp)
jmp    16ea <build_area_file+0x46a>
jmp    12c4 <build_area_file+0x44>
cmpq   $0x0,-0x30(%rbp)
jne    1387 <build_area_file+0x107>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xc8a(%rip),%rsi
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ea <build_area_file+0x46a>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1130 <next_entry@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     16e3 <build_area_file+0x463>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     13cf <build_area_file+0x14f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ea <build_area_file+0x46a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x79(%rbp)
je     1402 <build_area_file+0x182>
mov    -0x48(%rbp),%rax
movsbl (%rax),%edi
call   10b0 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    1412 <build_area_file+0x192>
jmp    1423 <build_area_file+0x1a3>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    13d7 <build_area_file+0x157>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1443 <build_area_file+0x1c3>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1451 <build_area_file+0x1d1>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1390 <build_area_file+0x110>
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
je     147e <build_area_file+0x1fe>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    16ea <build_area_file+0x46a>
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jge    14f4 <build_area_file+0x274>
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x4,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x8c(%rbp),%esi
mov    -0x88(%rbp),%rdi
sub    %eax,%esi
call   1120 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    14ef <build_area_file+0x26f>
lea    0xb3e(%rip),%rdi
call   1140 <perror@plt>
mov    $0x1,%edi
call   1180 <exit@plt>
jmp    14f4 <build_area_file+0x274>
mov    -0x48(%rbp),%rax
movb   $0x20,0x2(%rax)
mov    -0x48(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1190 <find_country@plt>
cmp    $0x1,%eax
jne    1541 <build_area_file+0x2c1>
mov    0x2abf(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
lea    0xaf8(%rip),%rsi
call   10e0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1390 <build_area_file+0x110>
jmp    1546 <build_area_file+0x2c6>
mov    -0x20(%rbp),%rdi
call   1090 <get_mirrors@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     16cc <build_area_file+0x44c>
mov    -0x40(%rbp),%rdi
lea    0xae3(%rip),%rsi
call   11a0 <strstr@plt>
cmp    $0x0,%rax
jne    15bd <build_area_file+0x33d>
mov    -0x18(%rbp),%rdi
call   10f0 <ftell@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     15b8 <build_area_file+0x338>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    16ea <build_area_file+0x46a>
jmp    16c7 <build_area_file+0x447>
mov    -0x18(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    0x2a0d(%rip),%rax
mov    (%rax),%edx
call   1110 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1130 <next_entry@plt>
mov    %rax,-0x70(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1080 <trim@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    $0x28,%esi
call   1100 <ltrim@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    $0x29,%esi
call   10d0 <rtrim@plt>
mov    %rax,-0x60(%rbp)
mov    -0x70(%rbp),%rdi
lea    0xa2f(%rip),%rsi
call   11a0 <strstr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xa1d(%rip),%rsi
call   1150 <strtok@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     16c2 <build_area_file+0x442>
mov    -0x78(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x90(%rbp)
mov    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x90(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10c0 <calloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1170 <strcat@plt>
mov    -0x68(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <fputs@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0x9a6(%rip),%rsi
call   1150 <strtok@plt>
mov    %rax,-0x78(%rbp)
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
jmp    163d <build_area_file+0x3bd>
jmp    16c7 <build_area_file+0x447>
jmp    1546 <build_area_file+0x2c6>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1390 <build_area_file+0x110>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_area_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
mov    %rcx,%rdi
call   1160 <str_toupper@plt>
mov    %r14,%rdi
call   1130 <next_entry@plt>
test   %rax,%rax
je     15da <build_area_file+0x35a>
mov    %rax,%rbx
jmp    12ed <build_area_file+0x6d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    15f2 <build_area_file+0x372>
mov    %r14,%rdi
call   1130 <next_entry@plt>
mov    %rax,%rbx
test   %rax,%rax
je     15da <build_area_file+0x35a>
mov    %rbx,%rdi
call   1160 <str_toupper@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   11a0 <strstr@plt>
test   %rax,%rax
je     12c0 <build_area_file+0x40>
mov    %rax,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     12d9 <build_area_file+0x59>
mov    %r14,%rdi
call   1130 <next_entry@plt>
test   %rax,%rax
je     1608 <build_area_file+0x388>
mov    %rax,%r12
mov    %r15,0x8(%rsp)
lea    0xd0d(%rip),%r13
mov    0x10(%rsp),%rbx
mov    0x2c92(%rip),%rbp
jmp    136f <build_area_file+0xef>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1130 <next_entry@plt>
mov    %rax,%r12
test   %rax,%rax
mov    %r15,%r13
je     1608 <build_area_file+0x388>
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    160c <build_area_file+0x38c>
mov    %r13,%r15
mov    (%r12),%al
mov    %r12,%r13
cmp    $0xa,%al
je     1350 <build_area_file+0xd0>
xchg   %ax,%ax
movsbl %al,%edi
call   10b0 <isspace@plt>
test   %rax,%rax
je     13b0 <build_area_file+0x130>
movzbl 0x1(%r13),%eax
add    $0x1,%r13
cmp    $0xa,%al
jne    1390 <build_area_file+0x110>
jmp    1350 <build_area_file+0xd0>
nopl   0x0(%rax)
mov    0x0(%r13),%al
cmp    $0x23,%al
je     1350 <build_area_file+0xd0>
cmp    $0xa,%al
je     1350 <build_area_file+0xd0>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
test   %rax,%rax
jne    1616 <build_area_file+0x396>
mov    %r13,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jg     1411 <build_area_file+0x191>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1060 <strlen@plt>
sub    %eax,%ebx
add    $0x4,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
mov    0x10(%rsp),%rbx
call   1120 <realloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     1622 <build_area_file+0x3a2>
movw   $0x20,0x2(%r13)
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1190 <find_country@plt>
cmp    $0x1,%eax
jne    1441 <build_area_file+0x1c1>
mov    0x0(%rbp),%edi
lea    0xbf2(%rip),%rsi
mov    %r13,%rdx
call   10e0 <fprintf@plt>
jmp    1350 <build_area_file+0xd0>
mov    0x8(%rsp),%rdi
call   1090 <get_mirrors@plt>
mov    %rax,%rbp
test   %rax,%rax
mov    %r15,%r13
jne    14ba <build_area_file+0x23a>
xor    %ebp,%ebp
xor    %edi,%edi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1130 <next_entry@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1347 <build_area_file+0xc7>
jmp    15f7 <build_area_file+0x377>
mov    %rbx,%rdi
call   10f0 <ftell@plt>
mov    %eax,0x1c(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <fputs@plt>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    160c <build_area_file+0x38c>
mov    0x8(%rsp),%rdi
call   1090 <get_mirrors@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1456 <build_area_file+0x1d6>
mov    %rbp,%rdi
lea    0xb87(%rip),%rsi
call   11a0 <strstr@plt>
test   %rax,%rax
je     1480 <build_area_file+0x200>
mov    0x2b03(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    0x1c(%rsp),%esi
call   1110 <fseek@plt>
mov    %rbx,%rdi
call   1130 <next_entry@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    $0x20,%esi
call   1080 <trim@plt>
mov    %rax,%rdi
mov    $0x28,%esi
call   1100 <ltrim@plt>
mov    %rax,%rdi
mov    $0x29,%esi
call   10d0 <rtrim@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
call   1150 <strtok@plt>
test   %rax,%rax
je     15d0 <build_area_file+0x350>
mov    %rax,%rbx
mov    %r15,0x20(%rsp)
mov    %rbp,%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    0x20(%rsp),%rdi
call   1060 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   10c0 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1170 <strcat@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
call   10a0 <fputs@plt>
xor    %edi,%edi
lea    0xaaa(%rip),%rsi
call   1150 <strtok@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
jne    1550 <build_area_file+0x2d0>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rbx
lea    0xa84(%rip),%r13
jmp    14ad <build_area_file+0x22d>
mov    0x10(%rsp),%rbx
jmp    14a8 <build_area_file+0x228>
mov    0x29ff(%rip),%rax
mov    (%rax),%edi
lea    0xa16(%rip),%rsi
mov    %r12,%rdx
call   10e0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    15f7 <build_area_file+0x377>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    15f2 <build_area_file+0x372>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
jmp    15f7 <build_area_file+0x377>
lea    0x9f5(%rip),%rdi
call   1140 <perror@plt>
mov    $0x1,%edi
call   1180 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Could not find area named %s\0A\00"
@.str.1 = [8 x i8] c"realloc\00"
@.str.2 = [37 x i8] c"Couldn't find country %s. Skipping.\0A\00"
@.str.3 = [4 x i8] c" (\00"
@SEEK_SET = global i32 0
@.str.4 = [2 x i8] c":\00"
@.str.5 = [3 x i8] c", \00"
define i32 @build_area_file(i32* %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i8* null, i8** %12
store i8* null, i8** %13
%20 = load i8*, i8** %9
%21 = call i32 @str_toupper(i8* %20)
br label %22
22: ; preds = %48, %37, %4
%23 = load i32*, i32** %6
%24 = call i8* @next_entry(i32* %23)
store i8* %24, i8** %10
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %49
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = call i32 @str_toupper(i8* %27)
%29 = load i8*, i8** %10
%30 = load i8*, i8** %9
%31 = call i8* @strstr(i8* %29, i8* %30)
store i8* %31, i8** %11
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = load i8*, i8** %11
%35 = call i32* @strchr(i8* %34, i8 signext 58)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8*, i8** %10
%39 = call i32 @free(i8* %38)
br label %22
40: ; preds = %33
br label %49
41: ; preds = %26
%42 = load i8*, i8** %10
%43 = call i32 @free(i8* %42)
%44 = load i32*, i32** %6
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %41
store i32 1, i32* %5
br label %212
48: ; preds = %41
br label %22
49: ; preds = %40, %22
%50 = load i8*, i8** %10
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %9
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %54)
store i32 1, i32* %5
br label %212
56: ; preds = %49
%57 = load i8*, i8** %10
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %206, %135, %97, %56
%60 = load i32*, i32** %6
%61 = call i8* @next_entry(i32* %60)
store i8* %61, i8** %10
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %211
63: ; preds = %59
%64 = load i32*, i32** %6
%65 = call i64 @ferror(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
store i32 1, i32* %5
br label %212
70: ; preds = %63
%71 = load i8*, i8** %10
store i8* %71, i8** %13
br label %72
72: ; preds = %84, %70
%73 = load i8*, i8** %13
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp ne i32 %75, 10
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = load i8*, i8** %13
%79 = load i8, i8* %78
%80 = call i64 @isspace(i8 signext %79)
%81 = icmp ne i64 %80, 0
br label %82
82: ; preds = %77, %72
%83 = phi i1 [ false, %72 ], [ %81, %77 ]
br i1 %83, label %84, label %87
84: ; preds = %82
%85 = load i8*, i8** %13
%86 = getelementptr inbounds i8, i8* %85, i32 1
store i8* %86, i8** %13
br label %72
87: ; preds = %82
%88 = load i8*, i8** %13
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 10
br i1 %91, label %97, label %92
92: ; preds = %87
%93 = load i8*, i8** %13
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 35
br i1 %96, label %97, label %100
97: ; preds = %92, %87
%98 = load i8*, i8** %10
%99 = call i32 @free(i8* %98)
br label %59
100: ; preds = %92
%101 = load i8*, i8** %10
%102 = call i32* @strchr(i8* %101, i8 signext 58)
%103 = icmp ne i32* %102, null
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i8*, i8** %10
%106 = call i32 @free(i8* %105)
store i32 0, i32* %5
br label %212
107: ; preds = %100
%108 = load i8*, i8** %13
%109 = call i32 @strlen(i8* %108)
%110 = icmp slt i32 %109, 3
br i1 %110, label %111, label %126
111: ; preds = %107
%112 = load i8*, i8** %10
%113 = load i8*, i8** %10
%114 = call i32 @strlen(i8* %113)
%115 = add nsw i32 %114, 4
%116 = load i8*, i8** %13
%117 = call i32 @strlen(i8* %116)
%118 = sub nsw i32 %115, %117
%119 = call i8* @realloc(i8* %112, i32 %118)
store i8* %119, i8** %10
%120 = load i8*, i8** %10
%121 = icmp eq i8* %120, null
br i1 %121, label %122, label %125
122: ; preds = %111
%123 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%124 = call i32 @exit(i32 1)
unreachable
125: ; preds = %111
br label %126
126: ; preds = %125, %107
%127 = load i8*, i8** %13
%128 = getelementptr inbounds i8, i8* %127, i64 2
store i8 32, i8* %128
%129 = load i8*, i8** %13
%130 = getelementptr inbounds i8, i8* %129, i64 3
store i8 0, i8* %130
%131 = load i32*, i32** %8
%132 = load i8*, i8** %13
%133 = call i32 @find_country(i32* %131, i8* %132)
%134 = icmp eq i32 %133, 1
br i1 %134, label %135, label %141
135: ; preds = %126
%136 = load i32, i32* @stderr
%137 = load i8*, i8** %13
%138 = call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %137)
%139 = load i8*, i8** %10
%140 = call i32 @free(i8* %139)
br label %59
141: ; preds = %126
br label %142
142: ; preds = %205, %141
%143 = load i32*, i32** %8
%144 = call i8* @get_mirrors(i32* %143)
store i8* %144, i8** %12
%145 = icmp ne i8* %144, null
br i1 %145, label %146, label %206
146: ; preds = %142
%147 = load i8*, i8** %12
%148 = call i8* @strstr(i8* %147, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%149 = icmp eq i8* %148, null
br i1 %149, label %150, label %163
150: ; preds = %146
%151 = load i32*, i32** %7
%152 = call i32 @ftell(i32* %151)
store i32 %152, i32* %14
%153 = load i8*, i8** %12
%154 = load i32*, i32** %7
%155 = call i32 @fputs(i8* %153, i32* %154)
%156 = load i32*, i32** %7
%157 = call i64 @ferror(i32* %156)
%158 = icmp ne i64 %157, 0
br i1 %158, label %159, label %162
159: ; preds = %150
%160 = load i8*, i8** %10
%161 = call i32 @free(i8* %160)
store i32 1, i32* %5
br label %212
162: ; preds = %150
br label %205
163: ; preds = %146
%164 = load i32*, i32** %7
%165 = load i32, i32* %14
%166 = load i32, i32* @SEEK_SET
%167 = call i32 @fseek(i32* %164, i32 %165, i32 %166)
%168 = load i32*, i32** %7
%169 = call i8* @next_entry(i32* %168)
store i8* %169, i8** %18
%170 = load i8*, i8** %12
%171 = call i8* @trim(i8* %170, i8 signext 32)
store i8* %171, i8** %16
%172 = load i8*, i8** %16
%173 = call i8* @ltrim(i8* %172, i8 signext 40)
store i8* %173, i8** %16
%174 = load i8*, i8** %16
%175 = call i8* @rtrim(i8* %174, i8 signext 41)
store i8* %175, i8** %16
%176 = load i8*, i8** %18
%177 = call i8* @strstr(i8* %176, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %177, i8** %15
%178 = load i8*, i8** %16
%179 = call i8* @strtok(i8* %178, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i8* %179, i8** %19
br label %180
180: ; preds = %183, %163
%181 = load i8*, i8** %19
%182 = icmp ne i8* %181, null
br i1 %182, label %183, label %204
183: ; preds = %180
%184 = load i8*, i8** %19
%185 = call i32 @strlen(i8* %184)
%186 = load i8*, i8** %18
%187 = call i32 @strlen(i8* %186)
%188 = add nsw i32 %185, %187
%189 = add nsw i32 %188, 1
%190 = call i64 @calloc(i32 %189, i32 1)
%191 = inttoptr i64 %190 to i8*
store i8* %191, i8** %17
%192 = load i8*, i8** %17
%193 = load i8*, i8** %19
%194 = call i32 @strcpy(i8* %192, i8* %193)
%195 = load i8*, i8** %17
%196 = load i8*, i8** %15
%197 = call i32 @strcat(i8* %195, i8* %196)
%198 = load i8*, i8** %17
%199 = load i32*, i32** %7
%200 = call i32 @fputs(i8* %198, i32* %199)
%201 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i8* %201, i8** %19
%202 = load i8*, i8** %17
%203 = call i32 @free(i8* %202)
br label %180
204: ; preds = %180
br label %205
205: ; preds = %204, %162
br label %142
206: ; preds = %142
%207 = load i8*, i8** %12
%208 = call i32 @free(i8* %207)
%209 = load i8*, i8** %10
%210 = call i32 @free(i8* %209)
br label %59
211: ; preds = %59
store i32 0, i32* %5
br label %212
212: ; preds = %211, %159, %104, %67, %52, %47
%213 = load i32, i32* %5
ret i32 %213
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Could not find area named %s\0A\00"
@.str.1 = [8 x i8] c"realloc\00"
@.str.2 = [37 x i8] c"Couldn't find country %s. Skipping.\0A\00"
@.str.3 = [4 x i8] c" (\00"
@SEEK_SET = global i32 0
@.str.5 = [3 x i8] c", \00"
define i32 @build_area_file(i32* %0, i32* %1, i32* %2, i8* %3) {
%5 = tail call i32 @str_toupper(i8* %3)
%6 = tail call i8* @next_entry(i32* %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %4, %17
%9 = phi i8* [ %18, %17 ], [ %6, %4 ]
%10 = tail call i32 @str_toupper(i8* %9)
%11 = tail call i8* @strstr(i8* %9, i8* dereferenceable(1) %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = tail call i32* @strchr(i8* %11, i8 signext 58)
%15 = icmp eq i32* %14, null
%16 = tail call i32 @free(i8* %9)
br i1 %15, label %17, label %27
17: ; preds = %13, %20
%18 = tail call i8* @next_entry(i32* %0)
%19 = icmp eq i8* %18, null
br i1 %19, label %24, label %8
20: ; preds = %8
%21 = tail call i32 @free(i8* %9)
%22 = tail call i64 @ferror(i32* %0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %17, label %135
24: ; preds = %17, %4
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %135
27: ; preds = %13
%28 = tail call i8* @next_entry(i32* %0)
%29 = icmp eq i8* %28, null
br i1 %29, label %135, label %30
30: ; preds = %27, %129
%31 = phi i8* [ %133, %129 ], [ %28, %27 ]
%32 = phi i32 [ %130, %129 ], [ undef, %27 ]
br label %33
33: ; preds = %30, %55
%34 = phi i8* [ %31, %30 ], [ %56, %55 ]
%35 = tail call i64 @ferror(i32* %0)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %34
%39 = icmp eq i8 %38, 10
br i1 %39, label %53, label %42
40: ; preds = %33
%41 = tail call i32 @free(i8* %34)
br label %135
42: ; preds = %37, %47
%43 = phi i8 [ %49, %47 ], [ %38, %37 ]
%44 = phi i8* [ %48, %47 ], [ %34, %37 ]
%45 = tail call i64 @isspace(i8 signext %43)
%46 = icmp eq i64 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = getelementptr inbounds i8, i8* %44, i64 1
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 10
br i1 %50, label %53, label %42
51: ; preds = %42
%52 = load i8, i8* %44
switch i8 %52, label %58 [
i8 10, label %53
i8 35, label %53
]
53: ; preds = %47, %37, %51, %51
%54 = tail call i32 @free(i8* %34)
br label %55
55: ; preds = %53, %85
%56 = tail call i8* @next_entry(i32* %0)
%57 = icmp eq i8* %56, null
br i1 %57, label %135, label %33
58: ; preds = %51
%59 = tail call i32* @strchr(i8* %34, i8 signext 58)
%60 = icmp eq i32* %59, null
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = tail call i32 @free(i8* %34)
br label %135
63: ; preds = %58
%64 = tail call i32 @strlen(i8* %44)
%65 = icmp slt i32 %64, 3
br i1 %65, label %66, label %76
66: ; preds = %63
%67 = tail call i32 @strlen(i8* %34)
%68 = add nsw i32 %67, 4
%69 = tail call i32 @strlen(i8* %44)
%70 = sub i32 %68, %69
%71 = tail call i8* @realloc(i8* %34, i32 %70)
%72 = icmp eq i8* %71, null
br i1 %72, label %73, label %76
73: ; preds = %66
%74 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%75 = tail call i32 @exit(i32 1)
unreachable
76: ; preds = %66, %63
%77 = phi i8* [ %71, %66 ], [ %34, %63 ]
%78 = getelementptr inbounds i8, i8* %44, i64 2
store i8 32, i8* %78
%79 = getelementptr inbounds i8, i8* %44, i64 3
store i8 0, i8* %79
%80 = tail call i32 @find_country(i32* %2, i8* %44)
%81 = icmp eq i32 %80, 1
br i1 %81, label %85, label %82
82: ; preds = %76
%83 = tail call i8* @get_mirrors(i32* %2)
%84 = icmp eq i8* %83, null
br i1 %84, label %129, label %89
85: ; preds = %76
%86 = load i32, i32* @stderr
%87 = tail call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%88 = tail call i32 @free(i8* %77)
br label %55
89: ; preds = %82, %125
%90 = phi i8* [ %127, %125 ], [ %83, %82 ]
%91 = phi i32 [ %126, %125 ], [ %32, %82 ]
%92 = tail call i8* @strstr(i8* %90, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%93 = icmp eq i8* %92, null
br i1 %93, label %94, label %101
94: ; preds = %89
%95 = tail call i32 @ftell(i32* %1)
%96 = tail call i32 @fputs(i8* %90, i32* %1)
%97 = tail call i64 @ferror(i32* %1)
%98 = icmp eq i64 %97, 0
br i1 %98, label %125, label %99
99: ; preds = %94
%100 = tail call i32 @free(i8* %77)
br label %135
101: ; preds = %89
%102 = load i32, i32* @SEEK_SET
%103 = tail call i32 @fseek(i32* %1, i32 %91, i32 %102)
%104 = tail call i8* @next_entry(i32* %1)
%105 = tail call i8* @trim(i8* %90, i8 signext 32)
%106 = tail call i8* @ltrim(i8* %105, i8 signext 40)
%107 = tail call i8* @rtrim(i8* %106, i8 signext 41)
%108 = tail call i8* bitcast (i32* (i8*, i8)* @strchr to i8* (i8*, i32)*)(i8* %104, i32 58)
%109 = tail call i8* @strtok(i8* %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%110 = icmp eq i8* %109, null
br i1 %110, label %125, label %111
111: ; preds = %101, %111
%112 = phi i8* [ %122, %111 ], [ %109, %101 ]
%113 = tail call i32 @strlen(i8* %112)
%114 = tail call i32 @strlen(i8* %104)
%115 = add i32 %113, 1
%116 = add i32 %115, %114
%117 = tail call i64 @calloc(i32 %116, i32 1)
%118 = inttoptr i64 %117 to i8*
%119 = tail call i32 @strcpy(i8* %118, i8* %112)
%120 = tail call i32 @strcat(i8* %118, i8* %108)
%121 = tail call i32 @fputs(i8* %118, i32* %1)
%122 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%123 = tail call i32 @free(i8* %118)
%124 = icmp eq i8* %122, null
br i1 %124, label %125, label %111
125: ; preds = %111, %101, %94
%126 = phi i32 [ %95, %94 ], [ %91, %101 ], [ %91, %111 ]
%127 = tail call i8* @get_mirrors(i32* %2)
%128 = icmp eq i8* %127, null
br i1 %128, label %129, label %89
129: ; preds = %125, %82
%130 = phi i32 [ %32, %82 ], [ %126, %125 ]
%131 = tail call i32 @free(i8* null)
%132 = tail call i32 @free(i8* %77)
%133 = tail call i8* @next_entry(i32* %0)
%134 = icmp eq i8* %133, null
br i1 %134, label %135, label %30
135: ; preds = %20, %129, %55, %27, %99, %61, %40, %24
%136 = phi i32 [ 1, %24 ], [ 1, %40 ], [ 0, %61 ], [ 1, %99 ], [ 0, %27 ], [ 0, %55 ], [ 0, %129 ], [ 1, %20 ]
ret i32 %136
}