#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 ccode_of_iso3(char const *);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ tc2text(int, int);
int tccontext(int);
int text2tc(const char *string, int optional_tc) {
  int ccode = optional_tc - 1;
  if (string == NULL)
    return -1;
  while (*string > 0 && *string <= 32)
    string++;
  if (ccode < 0 || strchr(string, '-') >= 0 || strlen(string) > 3) {
    ccode = ccode_of_iso3(string);
  } else {
    char tmp[12];
    int tc = tccontext(optional_tc);
    strcpy(tmp, tc2text(tc, 1));
    strcat(tmp, "-");
    strcat(tmp, string);
    ccode = ccode_of_iso3(tmp);
  }
  if (ccode < 0)
    return -1;
  else
    return ccode + 1;
}


x86 assembly (clang, -O0):
<text2tc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119f <text2tc+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a2 <text2tc+0x132>
jmp    11a4 <text2tc+0x34>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jle    11c9 <text2tc+0x59>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setle  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11d9 <text2tc+0x69>
jmp    11ea <text2tc+0x7a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a4 <text2tc+0x34>
cmpl   $0x0,-0x18(%rbp)
jl     121e <text2tc+0xae>
mov    -0x10(%rbp),%rdi
mov    $0x2d,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jge    121e <text2tc+0xae>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jle    122f <text2tc+0xbf>
mov    -0x10(%rbp),%rdi
call   1080 <ccode_of_iso3@plt>
mov    %eax,-0x18(%rbp)
jmp    1283 <text2tc+0x113>
mov    -0x14(%rbp),%edi
call   1040 <tccontext@plt>
mov    %eax,-0x28(%rbp)
lea    -0x24(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1050 <tc2text@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x24(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x24(%rbp),%rdi
call   1080 <ccode_of_iso3@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1299 <text2tc+0x129>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a2 <text2tc+0x132>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text2tc>:
test   %rdi,%rdi
je     11dd <text2tc+0x6d>
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
add    $0xff,%al
cmp    $0x20,%al
jb     1190 <text2tc+0x20>
test   %ebp,%ebp
jle    11c1 <text2tc+0x51>
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1070 <strchr@plt>
test   %rax,%rax
jns    11c1 <text2tc+0x51>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jl     11e3 <text2tc+0x73>
mov    %rbx,%rdi
call   1080 <ccode_of_iso3@plt>
lea    0x1(%rax),%ecx
test   %eax,%eax
mov    $0xffffffff,%eax
cmovns %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0xffffffff,%eax
ret
mov    %ebp,%edi
call   1040 <tccontext@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1050 <tc2text@plt>
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    0xdf4(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %rbp,%rdi
jmp    11c4 <text2tc+0x54>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define i32 @text2tc(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [12 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %6
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %65
14: ; preds = %2
br label %15
15: ; preds = %27, %14
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 32
br label %25
25: ; preds = %20, %15
%26 = phi i1 [ false, %15 ], [ %24, %20 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
br label %15
30: ; preds = %25
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = call i64 @strchr(i8* %34, i8 signext 45)
%36 = icmp sge i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i8*, i8** %4
%39 = call i32 @strlen(i8* %38)
%40 = icmp sgt i32 %39, 3
br i1 %40, label %41, label %44
41: ; preds = %37, %33, %30
%42 = load i8*, i8** %4
%43 = call i32 @ccode_of_iso3(i8* %42)
store i32 %43, i32* %6
br label %58
44: ; preds = %37
%45 = load i32, i32* %5
%46 = call i32 @tccontext(i32 %45)
store i32 %46, i32* %8
%47 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%48 = load i32, i32* %8
%49 = call i32 @tc2text(i32 %48, i32 1)
%50 = call i32 @strcpy(i8* %47, i32 %49)
%51 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%53 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%54 = load i8*, i8** %4
%55 = call i32 @strcat(i8* %53, i8* %54)
%56 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%57 = call i32 @ccode_of_iso3(i8* %56)
store i32 %57, i32* %6
br label %58
58: ; preds = %44, %41
%59 = load i32, i32* %6
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %58
store i32 -1, i32* %3
br label %65
62: ; preds = %58
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %65
65: ; preds = %62, %61, %13
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define i32 @text2tc(i8* %0, i32 %1) {
%3 = alloca [12 x i8]
%4 = icmp eq i8* %0, null
br i1 %4, label %34, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %10, %5 ], [ %0, %2 ]
%7 = load i8, i8* %6
%8 = add i8 %7, -1
%9 = icmp ult i8 %8, 32
%10 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %9, label %5, label %11
11: ; preds = %5
%12 = icmp slt i32 %1, 1
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = tail call i64 @strchr(i8* %6, i8 signext 45)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %6)
%18 = icmp sgt i32 %17, 3
br i1 %18, label %19, label %21
19: ; preds = %16, %13, %11
%20 = tail call i32 @ccode_of_iso3(i8* %6)
br label %29
21: ; preds = %16
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%23 = tail call i32 @tccontext(i32 %1)
%24 = tail call i32 @tc2text(i32 %23, i32 1)
%25 = call i32 @strcpy(i8* %22, i32 %24)
%26 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @strcat(i8* %22, i8* %6)
%28 = call i32 @ccode_of_iso3(i8* %22)
br label %29
29: ; preds = %21, %19
%30 = phi i32 [ %20, %19 ], [ %28, %21 ]
%31 = add nsw i32 %30, 1
%32 = icmp sgt i32 %30, -1
%33 = select i1 %32, i32 %31, i32 -1
br label %34
34: ; preds = %29, %2
%35 = phi i32 [ -1, %2 ], [ %33, %29 ]
ret i32 %35
}