#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 ParentLetter(int);
char *get_entity_iso3(char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *getTerritoryIsoName(char *result, int territoryCode, int format) {
  if (territoryCode < 1 || territoryCode > 533) {
    *result = 0;
  } else {
    int p = ParentLetter(territoryCode - 1);
    char iso3[4];
    const char *ei = get_entity_iso3(iso3, territoryCode - 1);
    if (*ei >= '0' && *ei <= '9') {
      ei++;
    }
    if (format == 0 && p) {
      memcpy(result, &"US,IN,CA,AU,MX,BR,RU,CN,"[p * 3 - 3], 2);
      result[2] = '-';
      strcpy(result + 3, ei);
    } else {
      strcpy(result, ei);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<getTerritoryIsoName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     1169 <getTerritoryIsoName+0x29>
cmpl   $0x215,-0xc(%rbp)
jle    1175 <getTerritoryIsoName+0x35>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1227 <getTerritoryIsoName+0xe7>
mov    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1040 <ParentLetter@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1060 <get_entity_iso3@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11c2 <getTerritoryIsoName+0x82>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11c2 <getTerritoryIsoName+0x82>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1215 <getTerritoryIsoName+0xd5>
cmpl   $0x0,-0x14(%rbp)
je     1215 <getTerritoryIsoName+0xd5>
mov    -0x8(%rbp),%rdi
imul   $0x3,-0x14(%rbp),%eax
sub    $0x3,%eax
cltq
lea    0xe16(%rip),%rsi
add    %rax,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x2d,0x2(%rax)
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1222 <getTerritoryIsoName+0xe2>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1227 <getTerritoryIsoName+0xe7>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTerritoryIsoName>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    -0x216(%rbx),%eax
cmp    $0xfffffdea,%eax
ja     115f <getTerritoryIsoName+0x1f>
movb   $0x0,(%r14)
jmp    11c8 <getTerritoryIsoName+0x88>
mov    %edx,%ebp
add    $0xffffffff,%ebx
mov    %ebx,%edi
call   1040 <ParentLetter@plt>
mov    %eax,%r15d
lea    0x4(%rsp),%rdi
mov    %ebx,%esi
call   1060 <get_entity_iso3@plt>
mov    %rax,%rbx
mov    (%rax),%al
add    $0xd0,%al
cmp    $0xa,%al
adc    $0x0,%rbx
test   %ebp,%ebp
jne    11bd <getTerritoryIsoName+0x7d>
test   %r15d,%r15d
je     11bd <getTerritoryIsoName+0x7d>
lea    (%r15,%r15,2),%eax
cltq
lea    0xe63(%rip),%rcx
lea    (%rax,%rcx,1),%rsi
add    $0xfffffffffffffffd,%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1050 <memcpy@plt>
movb   $0x2d,0x2(%r14)
lea    0x3(%r14),%rdi
jmp    11c0 <getTerritoryIsoName+0x80>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"US,IN,CA,AU,MX,BR,RU,CN,\00"
define i8* @getTerritoryIsoName(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 533
br i1 %14, label %15, label %17
15: ; preds = %12, %3
%16 = load i8*, i8** %4
store i8 0, i8* %16
br label %62
17: ; preds = %12
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = call i32 @ParentLetter(i32 %19)
store i32 %20, i32* %7
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = call i8* @get_entity_iso3(i8* %21, i32 %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %37
29: ; preds = %17
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sle i32 %32, 57
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %9
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %9
br label %37
37: ; preds = %34, %29, %17
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %57
43: ; preds = %40
%44 = load i8*, i8** %4
%45 = load i32, i32* %7
%46 = mul nsw i32 %45, 3
%47 = sub nsw i32 %46, 3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [25 x i8], [25 x i8]* @.str, i64 0, i64 %48
%50 = call i32 @memcpy(i8* %44, i8* %49, i32 2)
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 2
store i8 45, i8* %52
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i64 3
%55 = load i8*, i8** %9
%56 = call i32 @strcpy(i8* %54, i8* %55)
br label %61
57: ; preds = %40, %37
%58 = load i8*, i8** %4
%59 = load i8*, i8** %9
%60 = call i32 @strcpy(i8* %58, i8* %59)
br label %61
61: ; preds = %57, %43
br label %62
62: ; preds = %61, %15
%63 = load i8*, i8** %4
ret i8* %63
}

LLVM IR (-O2):
@.str = [25 x i8] c"US,IN,CA,AU,MX,BR,RU,CN,\00"
define i8* @getTerritoryIsoName(i8* returned %0, i32 %1, i32 %2) {
%4 = alloca [4 x i8]
%5 = add i32 %1, -534
%6 = icmp ult i32 %5, -533
br i1 %6, label %7, label %8
7: ; preds = %3
store i8 0, i8* %0
br label %33
8: ; preds = %3
%9 = add nsw i32 %1, -1
%10 = tail call i32 @ParentLetter(i32 %9)
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%12 = call i8* @get_entity_iso3(i8* %11, i32 %9)
%13 = load i8, i8* %12
%14 = add i8 %13, -48
%15 = icmp ult i8 %14, 10
%16 = zext i1 %15 to i64
%17 = getelementptr i8, i8* %12, i64 %16
%18 = icmp eq i32 %2, 0
%19 = icmp ne i32 %10, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %30
21: ; preds = %8
%22 = mul nsw i32 %10, 3
%23 = add nsw i32 %22, -3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [25 x i8], [25 x i8]* @.str, i64 0, i64 %24
%26 = call i32 @memcpy(i8* %0, i8* %25, i32 2)
%27 = getelementptr inbounds i8, i8* %0, i64 2
store i8 45, i8* %27
%28 = getelementptr inbounds i8, i8* %0, i64 3
%29 = call i32 @strcpy(i8* %28, i8* %17)
br label %32
30: ; preds = %8
%31 = call i32 @strcpy(i8* %0, i8* %17)
br label %32
32: ; preds = %30, %21
br label %33
33: ; preds = %32, %7
ret i8* %0
}