#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 */
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
void checklang(void) {
  char *langsuff = NULL;
  char *lang = getenv("LANG");
  if (lang != NULL) {
    if (strlen(lang) > 5) {
      langsuff = &lang[strlen(lang) - 5];
    }
  }
  if (langsuff == NULL) {
    printf("Could not determine language suffix for your system. Please check "
           "your setup!\n");
  } else if (strcmp(langsuff, "UTF-8")) {
    printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n",
           lang);
    printf(
        "If you want to have support for diacritics and Unicode characters,\n");
    printf("please switch your locale to an UTF-8 locale, e.g. "
           "\"en_US.UTF-8\".\n");
  }
}


x86 assembly (clang, -O0):
<checklang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a6 <checklang+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x5,%eax
jle    11a1 <checklang+0x61>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x5,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <checklang+0x66>
cmpq   $0x0,-0x8(%rbp)
jne    11c4 <checklang+0x84>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1211 <checklang+0xd1>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     120c <checklang+0xcc>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1211 <checklang+0xd1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checklang>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
lea    0xf69(%rip),%r14
test   %rax,%rax
je     11c3 <checklang+0x73>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     11c3 <checklang+0x73>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe70(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d2 <checklang+0x82>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xecb(%rip),%r14
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"LANG\00"
@.str.1 = [79 x i8] c"Could not determine language suffix for your system. Please check your setup!\0A\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [64 x i8] c"Your system does not appear to have UTF-8 enabled ($LANG=\22%s\22)\0A\00"
@.str.4 = [68 x i8] c"If you want to have support for diacritics and Unicode characters,\0A\00"
@.str.5 = [67 x i8] c"please switch your locale to an UTF-8 locale, e.g. \22en_US.UTF-8\22.\0A\00"
define void @checklang() {
%1 = alloca i8*
%2 = alloca i8*
store i8* null, i8** %1
%3 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp sgt i32 %8, 5
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
store i8* %16, i8** %1
br label %17
17: ; preds = %10, %6
br label %18
18: ; preds = %17, %0
%19 = load i8*, i8** %1
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0))
br label %33
23: ; preds = %18
%24 = load i8*, i8** %1
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %27, %23
br label %33
33: ; preds = %32, %21
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"LANG\00"
@.str.2 = [6 x i8] c"UTF-8\00"
@.str.3 = [64 x i8] c"Your system does not appear to have UTF-8 enabled ($LANG=\22%s\22)\0A\00"
@str = [67 x i8] c"If you want to have support for diacritics and Unicode characters,\00"
@str.6 = [66 x i8] c"please switch your locale to an UTF-8 locale, e.g. \22en_US.UTF-8\22.\00"
@str.7 = [78 x i8] c"Could not determine language suffix for your system. Please check your setup!\00"
define void @checklang() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, 5
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, -5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %6
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %3, %0, %13
%17 = phi i8* [ getelementptr inbounds ([66 x i8], [66 x i8]* @str.6, i64 0, i64 0), %13 ], [ getelementptr inbounds ([78 x i8], [78 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([78 x i8], [78 x i8]* @str.7, i64 0, i64 0), %3 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) %17)
br label %19
19: ; preds = %16, %6
ret void
}