#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ wl_ioctl(char const *, int, char *, int);
int wl_get_country(const char *ifname, char *buf) {
  char ccode[4];
  if (!wl_ioctl(ifname, 83, ccode, 4)) {
    if (!strcmp(ccode, "IL0"))
      sprintf(buf, "00");
    else if (!strcmp(ccode, "YU"))
      sprintf(buf, "RS");
    else
      memcpy(buf, ccode, 2);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<wl_get_country>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rdx
mov    $0x53,%esi
mov    $0x4,%ecx
call   1050 <wl_ioctl@plt>
cmp    $0x0,%eax
jne    11ef <wl_get_country+0xaf>
lea    -0x1c(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    119e <wl_get_country+0x5e>
mov    -0x18(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11e3 <wl_get_country+0xa3>
lea    -0x1c(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11cc <wl_get_country+0x8c>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11de <wl_get_country+0x9e>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
jmp    11e3 <wl_get_country+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <wl_get_country+0xb6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wl_get_country>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rdx
mov    $0x53,%esi
mov    $0x4,%ecx
call   1040 <wl_ioctl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    118f <wl_get_country+0x6f>
cmpl   $0x304c49,0xc(%rsp)
je     1179 <wl_get_country+0x59>
movzwl 0xc(%rsp),%eax
xor    $0x5559,%eax
movzbl 0xe(%rsp),%ecx
or     %ax,%cx
je     1184 <wl_get_country+0x64>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <memcpy@plt>
jmp    118d <wl_get_country+0x6d>
movb   $0x0,0x2(%rbx)
movw   $0x3030,(%rbx)
jmp    118d <wl_get_country+0x6d>
movb   $0x0,0x2(%rbx)
movw   $0x5352,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"IL0\00"
@.str.1 = [3 x i8] c"00\00"
@.str.2 = [3 x i8] c"YU\00"
@.str.3 = [3 x i8] c"RS\00"
define i32 @wl_get_country(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%9 = call i32 @wl_ioctl(i8* %7, i32 83, i8* %8, i32 4)
%10 = icmp ne i32 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %2
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %30
18: ; preds = %11
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %29
25: ; preds = %18
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%28 = call i32 @memcpy(i8* %26, i8* %27, i32 2)
br label %29
29: ; preds = %25, %22
br label %30
30: ; preds = %29, %15
store i32 0, i32* %3
br label %32
31: ; preds = %2
store i32 -1, i32* %3
br label %32
32: ; preds = %31, %30
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [4 x i8] c"IL0\00"
@.str.1 = [3 x i8] c"00\00"
@.str.2 = [3 x i8] c"YU\00"
@.str.3 = [3 x i8] c"RS\00"
define i32 @wl_get_country(i8* %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i32 @wl_ioctl(i8* %0, i32 83, i8* %4, i32 4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = call i32 @bcmp(i8* dereferenceable(4) %4, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
br label %17
11: ; preds = %7
%12 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
br label %17
15: ; preds = %11
%16 = call i32 @memcpy(i8* %1, i8* %4, i32 2)
br label %17
17: ; preds = %2, %10, %15, %14
%18 = phi i32 [ 0, %14 ], [ 0, %15 ], [ 0, %10 ], [ -1, %2 ]
ret i32 %18
}