#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 /*<<< orphan*/ iso3166_alpha2(char const *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const *);
int iso3166alpha2(const unsigned char *data, int data_len, int offset, int min,
                  int max, int *p_err_no, int *p_err_posn, char err_msg[50],
                  const int length_only) {
  (void)max;
  data_len -= offset;
  if (data_len < min || (data_len && data_len < 2)) {
    return 0;
  }
  if (!length_only && data_len) {
    if (!iso3166_alpha2((const char *)(data + offset))) {
      *p_err_no = 3;
      *p_err_posn = offset + 1;
      sprintf(err_msg, "Unknown country code '%.2s'", data + offset);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<iso3166alpha2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1173 <iso3166alpha2+0x53>
cmpl   $0x0,-0x14(%rbp)
je     117f <iso3166alpha2+0x5f>
cmpl   $0x2,-0x14(%rbp)
jge    117f <iso3166alpha2+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <iso3166alpha2+0xd5>
cmpl   $0x0,0x20(%rbp)
jne    11ee <iso3166alpha2+0xce>
cmpl   $0x0,-0x14(%rbp)
je     11ee <iso3166alpha2+0xce>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1030 <iso3166_alpha2@plt>
cmp    $0x0,%eax
jne    11e9 <iso3166alpha2+0xc9>
mov    -0x28(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x18(%rbp),%rax
add    %rax,%rdx
lea    0xe28(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <iso3166alpha2+0xd5>
jmp    11ee <iso3166alpha2+0xce>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso3166alpha2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
sub    %edx,%esi
xor    %ebp,%ebp
cmp    %ecx,%esi
jl     1189 <iso3166alpha2+0x69>
mov    %r9,%r15
mov    %edx,%ebx
mov    %rdi,%r14
test   %esi,%esi
je     1140 <iso3166alpha2+0x20>
cmp    $0x2,%esi
jl     1189 <iso3166alpha2+0x69>
cmpl   $0x0,0x40(%rsp)
mov    $0x1,%ebp
jne    1189 <iso3166alpha2+0x69>
test   %esi,%esi
je     1189 <iso3166alpha2+0x69>
movslq %ebx,%rax
add    %rax,%r14
mov    %r14,%rdi
call   1030 <iso3166_alpha2@plt>
test   %eax,%eax
jne    1189 <iso3166alpha2+0x69>
mov    0x38(%rsp),%rdi
mov    0x30(%rsp),%rax
movl   $0x3,(%r15)
add    $0x1,%ebx
mov    %ebx,(%rax)
lea    0xe81(%rip),%rsi
mov    %r14,%rdx
call   1040 <sprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Unknown country code '%.2s'\00"
define i32 @iso3166alpha2(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5, i32* %6, i8* %7, i32 %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i32
store i8* %0, i8** %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32* %5, i32** %16
store i32* %6, i32** %17
store i8* %7, i8** %18
store i32 %8, i32* %19
%20 = load i32, i32* %15
%21 = load i32, i32* %13
%22 = load i32, i32* %12
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = load i32, i32* %14
%26 = icmp slt i32 %24, %25
br i1 %26, label %33, label %27
27: ; preds = %9
%28 = load i32, i32* %12
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %12
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %34
33: ; preds = %30, %9
store i32 0, i32* %10
br label %60
34: ; preds = %30, %27
%35 = load i32, i32* %19
%36 = icmp ne i32 %35, 0
br i1 %36, label %59, label %37
37: ; preds = %34
%38 = load i32, i32* %12
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %59
40: ; preds = %37
%41 = load i8*, i8** %11
%42 = load i32, i32* %13
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = call i32 @iso3166_alpha2(i8* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %58, label %47
47: ; preds = %40
%48 = load i32*, i32** %16
store i32 3, i32* %48
%49 = load i32, i32* %13
%50 = add nsw i32 %49, 1
%51 = load i32*, i32** %17
store i32 %50, i32* %51
%52 = load i8*, i8** %18
%53 = load i8*, i8** %11
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %56)
store i32 0, i32* %10
br label %60
58: ; preds = %40
br label %59
59: ; preds = %58, %37, %34
store i32 1, i32* %10
br label %60
60: ; preds = %59, %47, %33
%61 = load i32, i32* %10
ret i32 %61
}

LLVM IR (-O2):
@.str = [28 x i8] c"Unknown country code '%.2s'\00"
define i32 @iso3166alpha2(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* nocapture writeonly %5, i32* nocapture writeonly %6, i8* nocapture writeonly %7, i32 %8) {
%10 = sub nsw i32 %1, %2
%11 = icmp slt i32 %10, %3
br i1 %11, label %27, label %12
12: ; preds = %9
%13 = icmp ne i32 %10, 0
%14 = icmp slt i32 %10, 2
%15 = and i1 %13, %14
br i1 %15, label %27, label %16
16: ; preds = %12
%17 = icmp eq i32 %8, 0
%18 = select i1 %17, i1 %13, i1 false
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = sext i32 %2 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = tail call i32 @iso3166_alpha2(i8* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
store i32 3, i32* %5
%25 = add nsw i32 %2, 1
store i32 %25, i32* %6
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %27
27: ; preds = %16, %19, %9, %12, %24
%28 = phi i32 [ 0, %24 ], [ 0, %12 ], [ 0, %9 ], [ 1, %19 ], [ 1, %16 ]
ret i32 %28
}