#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*/ free(char *);
scalar_t__ isspace(char);
char *next_entry(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int find_country(FILE *mirror_list, char *country_code) {
  char *line = NULL;
  char *cc = NULL;
  char *tmp = NULL;
  rewind(mirror_list);
  if (!strcmp(country_code, "UK "))
    strncpy(country_code, "GB ", 4);
  while ((line = next_entry(mirror_list)) != NULL) {
    cc = strstr(line, country_code);
    if (cc == NULL) {
      free(line);
      continue;
    }
    tmp = line;
    while (isspace(*tmp))
      ++tmp;
    if (cc == tmp)
      break;
  }
  if (line == NULL)
    return 1;
  free(line);
  line = next_entry(mirror_list);
  if (!line) {
    return 1;
  }
  free(line);
  return 0;
}


x86 assembly (clang, -O0):
<find_country>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11cf <find_country+0x5f>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncpy@plt>
jmp    11d4 <find_country+0x64>
mov    -0x10(%rbp),%rdi
call   1080 <next_entry@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     125c <find_country+0xec>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1215 <find_country+0xa5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11d4 <find_country+0x64>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     1244 <find_country+0xd4>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    121d <find_country+0xad>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    1257 <find_country+0xe7>
jmp    125c <find_country+0xec>
jmp    11d4 <find_country+0x64>
cmpq   $0x0,-0x20(%rbp)
jne    1273 <find_country+0x103>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <find_country+0x140>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1080 <next_entry@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a0 <find_country+0x130>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <find_country+0x140>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_country>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1050 <rewind@plt>
lea    0xe73(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11ad <find_country+0x3d>
lea    0xe64(%rip),%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1080 <next_entry@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     1237 <find_country+0xc7>
mov    %rax,%rbp
jmp    11e8 <find_country+0x78>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1080 <next_entry@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1237 <find_country+0xc7>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11d0 <find_country+0x60>
mov    %rax,%r13
lea    -0x1(%rbp),%rbx
nop
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1060 <isspace@plt>
test   %rax,%rax
jne    1200 <find_country+0x90>
cmp    %r13,%rbx
jne    11d8 <find_country+0x68>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1080 <next_entry@plt>
test   %rax,%rax
je     1237 <find_country+0xc7>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"UK \00"
@.str.1 = [4 x i8] c"GB \00"
define i32 @find_country(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%9 = load i32*, i32** %4
%10 = call i32 @rewind(i32* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
br label %17
17: ; preds = %14, %2
br label %18
18: ; preds = %46, %28, %17
%19 = load i32*, i32** %4
%20 = call i8* @next_entry(i32* %19)
store i8* %20, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
br label %18
31: ; preds = %22
%32 = load i8*, i8** %6
store i8* %32, i8** %8
br label %33
33: ; preds = %38, %31
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = call i64 @isspace(i8 signext %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %8
br label %33
41: ; preds = %33
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = icmp eq i8* %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
br label %47
46: ; preds = %41
br label %18
47: ; preds = %45, %18
%48 = load i8*, i8** %6
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 1, i32* %3
br label %62
51: ; preds = %47
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
%54 = load i32*, i32** %4
%55 = call i8* @next_entry(i32* %54)
store i8* %55, i8** %6
%56 = load i8*, i8** %6
%57 = icmp ne i8* %56, null
br i1 %57, label %59, label %58
58: ; preds = %51
store i32 1, i32* %3
br label %62
59: ; preds = %51
%60 = load i8*, i8** %6
%61 = call i32 @free(i8* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %59, %58, %50
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str = [4 x i8] c"UK \00"
@.str.1 = [4 x i8] c"GB \00"
define i32 @find_country(i32* %0, i8* %1) {
%3 = tail call i32 @rewind(i32* %0)
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
br label %8
8: ; preds = %6, %2
%9 = tail call i8* @next_entry(i32* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %34, label %11
11: ; preds = %8, %17
%12 = phi i8* [ %18, %17 ], [ %9, %8 ]
%13 = tail call i8* @strstr(i8* %12, i8* dereferenceable(1) %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = tail call i32 @free(i8* %12)
br label %17
17: ; preds = %15, %26
%18 = tail call i8* @next_entry(i32* %0)
%19 = icmp eq i8* %18, null
br i1 %19, label %34, label %11
20: ; preds = %11, %20
%21 = phi i8* [ %25, %20 ], [ %12, %11 ]
%22 = load i8, i8* %21
%23 = tail call i64 @isspace(i8 signext %22)
%24 = icmp eq i64 %23, 0
%25 = getelementptr inbounds i8, i8* %21, i64 1
br i1 %24, label %26, label %20
26: ; preds = %20
%27 = icmp eq i8* %13, %21
br i1 %27, label %28, label %17
28: ; preds = %26
%29 = tail call i32 @free(i8* %12)
%30 = tail call i8* @next_entry(i32* %0)
%31 = icmp eq i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @free(i8* %30)
br label %34
34: ; preds = %17, %8, %28, %32
%35 = phi i32 [ 0, %32 ], [ 1, %28 ], [ 1, %8 ], [ 1, %17 ]
ret i32 %35
}