#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*/ disambiguate(int);
int /*<<< orphan*/ makeup(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *strstr(char const *, char *);
int disambiguate_str(const char *s, int len) {
  int res;
  const char *p = (len == 2 ? "US,IN,CA,AU,MX,BR,RU,CN,"
                            : "USA,IND,CAN,AUS,MEX,BRA,RUS,CHN,");
  const char *f;
  char country[4];
  if (s[0] == 0 || s[1] == 0)
    return -27;
  if (len != 2 && len != 3)
    return -923;
  memcpy(country, s, len);
  country[len] = 0;
  makeup(country);
  f = strstr(p, country);
  if (f == NULL)
    return -23;
  res = 1 + ((f - p) / (len + 1));
  disambiguate(res);
  return res;
}


x86 assembly (clang, -O0):
<disambiguate_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edx
lea    0xec0(%rip),%rax
lea    0xea0(%rip),%rcx
cmp    $0x2,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118c <disambiguate_str+0x4c>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1198 <disambiguate_str+0x58>
movl   $0xffffffe5,-0x4(%rbp)
jmp    1230 <disambiguate_str+0xf0>
cmpl   $0x2,-0x14(%rbp)
je     11b8 <disambiguate_str+0x78>
cmpl   $0x3,-0x14(%rbp)
je     11b8 <disambiguate_str+0x78>
movl   $0xfffffc65,-0x4(%rbp)
jmp    1230 <disambiguate_str+0xf0>
lea    -0x2c(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x2c(%rbp,%rax,1)
lea    -0x2c(%rbp),%rdi
call   1040 <makeup@plt>
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1202 <disambiguate_str+0xc2>
movl   $0xffffffe9,-0x4(%rbp)
jmp    1230 <disambiguate_str+0xf0>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cqto
idiv   %rcx
add    $0x1,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <disambiguate@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disambiguate_str>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%esi
lea    0xead(%rip),%rax
lea    0xebf(%rip),%rbx
cmove  %rax,%rbx
mov    $0xffffffe5,%r15d
cmpb   $0x0,(%rdi)
je     11f0 <disambiguate_str+0xb0>
mov    %esi,%r14d
mov    %rdi,%rsi
cmpb   $0x0,0x1(%rdi)
je     11f0 <disambiguate_str+0xb0>
mov    %r14d,%eax
and    $0xfffffffe,%eax
mov    $0xfffffc65,%r15d
cmp    $0x2,%eax
jne    11f0 <disambiguate_str+0xb0>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
mov    %r14d,%edx
call   1050 <memcpy@plt>
mov    %r14d,%eax
movb   $0x0,0xc(%rsp,%rax,1)
mov    %r15,%rdi
call   1040 <makeup@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11d4 <disambiguate_str+0x94>
sub    %rbx,%rax
add    $0x1,%r14d
mov    %rax,%rcx
shr    $0x20,%rcx
je     11dc <disambiguate_str+0x9c>
cqto
idiv   %r14
mov    %rax,%r15
jmp    11e4 <disambiguate_str+0xa4>
mov    $0xffffffe9,%r15d
jmp    11f0 <disambiguate_str+0xb0>
xor    %edx,%edx
div    %r14d
mov    %eax,%r15d
add    $0x1,%r15d
mov    %r15d,%edi
call   1030 <disambiguate@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"US,IN,CA,AU,MX,BR,RU,CN,\00"
@.str.1 = [33 x i8] c"USA,IND,CAN,AUS,MEX,BRA,RUS,CHN,\00"
define i32 @disambiguate_str(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 2
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0)
store i8* %13, i8** %7
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19, %2
store i32 -27, i32* %3
br label %64
26: ; preds = %19
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 3
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 -923, i32* %3
br label %64
33: ; preds = %29, %26
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = call i32 @memcpy(i8* %34, i8* %35, i32 %36)
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%42 = call i32 @makeup(i8* %41)
%43 = load i8*, i8** %7
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%45 = call i8* @strstr(i8* %43, i8* %44)
store i8* %45, i8** %8
%46 = load i8*, i8** %8
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %49
48: ; preds = %33
store i32 -23, i32* %3
br label %64
49: ; preds = %33
%50 = load i8*, i8** %8
%51 = load i8*, i8** %7
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = sdiv i64 %54, %57
%59 = add nsw i64 1, %58
%60 = trunc i64 %59 to i32
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = call i32 @disambiguate(i32 %61)
%63 = load i32, i32* %6
store i32 %63, i32* %3
br label %64
64: ; preds = %49, %48, %32, %25
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [25 x i8] c"US,IN,CA,AU,MX,BR,RU,CN,\00"
@.str.1 = [33 x i8] c"USA,IND,CAN,AUS,MEX,BRA,RUS,CHN,\00"
define i32 @disambiguate_str(i8* %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = icmp eq i32 %1, 2
%5 = select i1 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0)
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %33, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %9
%14 = and i32 %1, -2
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = call i32 @memcpy(i8* %6, i8* %0, i32 %1)
%18 = zext i32 %1 to i64
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @makeup(i8* %6)
%21 = call i8* @strstr(i8* dereferenceable(1) %5, i8* %6)
%22 = icmp eq i8* %21, null
br i1 %22, label %33, label %23
23: ; preds = %16
%24 = ptrtoint i8* %21 to i64
%25 = ptrtoint i8* %5 to i64
%26 = sub i64 %24, %25
%27 = add nuw nsw i32 %1, 1
%28 = zext i32 %27 to i64
%29 = sdiv i64 %26, %28
%30 = trunc i64 %29 to i32
%31 = add i32 %30, 1
%32 = call i32 @disambiguate(i32 %31)
br label %33
33: ; preds = %16, %13, %2, %9, %23
%34 = phi i32 [ %31, %23 ], [ -27, %9 ], [ -27, %2 ], [ -923, %13 ], [ -23, %16 ]
ret i32 %34
}