#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*/ LC_CTYPE;
char *setlocale(int /*<<< orphan*/, char *);
char *strrchr(char *, char);
int /*<<< orphan*/ *strstr(char *, char *);
char *get_charset() {
  setlocale(LC_CTYPE, "");
  char *locale = setlocale(LC_CTYPE, NULL);
  if (strstr(locale, ".") != NULL) {
    return strrchr(locale, '.') + 1;
  }
  return locale;
}


x86 assembly (clang, -O0):
<get_charset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
call   1040 <setlocale@plt>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setlocale@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1198 <get_charset+0x68>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <get_charset+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_charset>:
push   %rbx
mov    0x2eb0(%rip),%rbx
mov    (%rbx),%edi
lea    0xebf(%rip),%rsi
call   1050 <setlocale@plt>
mov    (%rbx),%edi
xor    %esi,%esi
call   1050 <setlocale@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1178 <get_charset+0x48>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c".\00"
define i8* @get_charset() {
%1 = alloca i8*
%2 = alloca i8*
%3 = load i32, i32* @LC_CTYPE
%4 = call i8* @setlocale(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @LC_CTYPE
%6 = call i8* @setlocale(i32 %5, i8* null)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @strstr(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %13, i8** %1
br label %16
14: ; preds = %0
%15 = load i8*, i8** %2
store i8* %15, i8** %1
br label %16
16: ; preds = %14, %10
%17 = load i8*, i8** %1
ret i8* %17
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
define i8* @get_charset() {
%1 = load i32, i32* @LC_CTYPE
%2 = tail call i8* @setlocale(i32 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @LC_CTYPE
%4 = tail call i8* @setlocale(i32 %3, i8* null)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i32 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 46)
%9 = getelementptr inbounds i8, i8* %8, i64 1
br label %10
10: ; preds = %0, %7
%11 = phi i8* [ %9, %7 ], [ %4, %0 ]
ret i8* %11
}