#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*/ lprintf(int, char *, char *, ...);
int /*<<< orphan*/ strncpy(char *, unsigned char *, int);
int decode_country(unsigned char *element, int element_len) {
  char country[3];
  char subdivision[4];
  strncpy(country, element, 2);
  country[2] = 0;
  if (element_len > 2) {
    strncpy(subdivision, element + 2, element_len - 2);
    subdivision[element_len - 2] = 0;
    lprintf(14, "Country Code %s-%s\r\n", country, subdivision);
  } else {
    lprintf(14, "Country Code %s\r\n", country);
  }
  return 0;
}


x86 assembly (clang, -O0):
<decode_country>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0xf(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0xd(%rbp)
cmpl   $0x2,-0xc(%rbp)
jle    1193 <decode_country+0x73>
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x2,%rsi
mov    -0xc(%rbp),%edx
sub    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x13(%rbp,%rax,1)
lea    -0xf(%rbp),%rdx
lea    -0x13(%rbp),%rcx
mov    $0xe,%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <lprintf@plt>
jmp    11aa <decode_country+0x8a>
lea    -0xf(%rbp),%rdx
mov    $0xe,%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <lprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_country>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x9(%rsp),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xb(%rsp)
cmp    $0x3,%ebx
jl     1185 <decode_country+0x65>
add    $0x2,%r14
add    $0xfffffffe,%ebx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xc(%rsp,%rbx,1)
lea    0xe91(%rip),%rsi
lea    0x9(%rsp),%rdx
mov    $0xe,%edi
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <lprintf@plt>
jmp    119d <decode_country+0x7d>
lea    0xe89(%rip),%rsi
lea    0x9(%rsp),%rdx
mov    $0xe,%edi
xor    %eax,%eax
call   1040 <lprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Country Code %s-%s\0D\0A\00"
@.str.1 = [18 x i8] c"Country Code %s\0D\0A\00"
define i32 @decode_country(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = alloca [4 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strncpy(i8* %7, i8* %8, i32 2)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %10
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 2
%19 = call i32 @strncpy(i8* %14, i8* %16, i32 %18)
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%26 = call i32 (i32, i8*, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25)
br label %30
27: ; preds = %2
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%29 = call i32 (i32, i8*, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Country Code %s-%s\0D\0A\00"
@.str.1 = [18 x i8] c"Country Code %s\0D\0A\00"
define i32 @decode_country(i8* %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = call i32 @strncpy(i8* %5, i8* %0, i32 2)
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %8
%9 = icmp sgt i32 %1, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = add nsw i32 %1, -2
%13 = call i32 @strncpy(i8* %6, i8* %11, i32 %12)
%14 = zext i32 %12 to i64
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 (i32, i8*, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %6)
br label %19
17: ; preds = %2
%18 = call i32 (i32, i8*, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %19
19: ; preds = %17, %10
ret i32 0
}