#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*/ makeiso(int, int);
int /*<<< orphan*/ master_encode(char *, int, long, long, int, int, int,
                                 int /*<<< orphan*/);
int resultlen(char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int mapcode_encode(char *result, long y, long x, const char *iso3,
                   char *isofound) {
  int cc = ccode_of_iso3(iso3);
  master_encode(result, cc, x, y, -1, 1, 1, 0);
  if (isofound) {
    *isofound = 0;
    if (*result)
      if (resultlen(result) == 10)
        strcpy(isofound, makeiso(540, 1));
      else
        strcpy(isofound, makeiso(cc, 1));
  }
  return *result;
}


x86 assembly (clang, -O0):
<mapcode_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ccode_of_iso3@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%r8d
mov    $0x1,%r9d
xor    %eax,%eax
movl   $0x1,(%rsp)
movl   $0x0,0x8(%rsp)
call   1060 <master_encode@plt>
cmpq   $0x0,-0x28(%rbp)
je     122b <mapcode_encode+0xdb>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1226 <mapcode_encode+0xd6>
mov    -0x8(%rbp),%rdi
call   1070 <resultlen@plt>
cmp    $0xa,%eax
jne    1201 <mapcode_encode+0xb1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x21c,%edi
mov    $0x1,%esi
call   1030 <makeiso@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
jmp    1221 <mapcode_encode+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x1,%esi
call   1030 <makeiso@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
jmp    1226 <mapcode_encode+0xd6>
jmp    122b <mapcode_encode+0xdb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapcode_encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rcx,%rdi
call   1050 <ccode_of_iso3@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    $0xffffffff,%r8d
mov    $0x1,%r9d
push   $0x0
push   $0x1
call   1060 <master_encode@plt>
add    $0x10,%rsp
test   %r14,%r14
je     11cd <mapcode_encode+0x7d>
movb   $0x0,(%r14)
cmpb   $0x0,(%r15)
je     11cd <mapcode_encode+0x7d>
mov    %r15,%rdi
call   1070 <resultlen@plt>
cmp    $0xa,%eax
mov    $0x21c,%eax
cmove  %eax,%r12d
mov    %r12d,%edi
mov    $0x1,%esi
call   1030 <makeiso@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
movsbl (%r15),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mapcode_encode(i8* %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i8*, i8** %9
%13 = call i32 @ccode_of_iso3(i8* %12)
store i32 %13, i32* %11
%14 = load i8*, i8** %6
%15 = load i32, i32* %11
%16 = load i64, i64* %8
%17 = load i64, i64* %7
%18 = call i32 @master_encode(i8* %14, i32 %15, i64 %16, i64 %17, i32 -1, i32 1, i32 1, i32 0)
%19 = load i8*, i8** %10
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %5
%22 = load i8*, i8** %10
store i8 0, i8* %22
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @resultlen(i8* %27)
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = call i32 @makeiso(i32 540, i32 1)
%33 = call i32 @strcpy(i8* %31, i32 %32)
br label %39
34: ; preds = %26
%35 = load i8*, i8** %10
%36 = load i32, i32* %11
%37 = call i32 @makeiso(i32 %36, i32 1)
%38 = call i32 @strcpy(i8* %35, i32 %37)
br label %39
39: ; preds = %34, %30
br label %40
40: ; preds = %39, %21
br label %41
41: ; preds = %40, %5
%42 = load i8*, i8** %6
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
ret i32 %44
}

LLVM IR (-O2):
define i32 @mapcode_encode(i8* %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = tail call i32 @ccode_of_iso3(i8* %3)
%7 = tail call i32 @master_encode(i8* %0, i32 %6, i64 %2, i64 %1, i32 -1, i32 1, i32 1, i32 0)
%8 = icmp eq i8* %4, null
br i1 %8, label %18, label %9
9: ; preds = %5
store i8 0, i8* %4
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i32 @resultlen(i8* %0)
%14 = icmp eq i32 %13, 10
%15 = select i1 %14, i32 540, i32 %6
%16 = tail call i32 @makeiso(i32 %15, i32 1)
%17 = tail call i32 @strcpy(i8* %4, i32 %16)
br label %18
18: ; preds = %12, %9, %5
%19 = load i8, i8* %0
%20 = sext i8 %19 to i32
ret i32 %20
}