#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*/ CODESET;
int /*<<< orphan*/ ichardef(char *);
scalar_t__ icharset(char *, int);
int /*<<< orphan*/ ilocale();
char *lgetenv(char *);
char *nl_langinfo(int /*<<< orphan*/);
void set_charset(void) {
  char *s;
  s = lgetenv("LESSCHARSET");
  if (icharset(s, 0))
    return;
  s = lgetenv("LESSCHARDEF");
  if (s != NULL && *s != '\0') {
    ichardef(s);
    return;
  }
  s = nl_langinfo(CODESET);
  if (icharset(s, 1))
    return;
  ilocale();
}


x86 assembly (clang, -O0):
<set_charset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1070 <lgetenv@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1040 <icharset@plt>
cmp    $0x0,%rax
je     1182 <set_charset+0x32>
jmp    11f1 <set_charset+0xa1>
lea    0xe83(%rip),%rdi
call   1070 <lgetenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11bb <set_charset+0x6b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bb <set_charset+0x6b>
mov    -0x8(%rbp),%rdi
call   1030 <ichardef@plt>
jmp    11f1 <set_charset+0xa1>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1040 <icharset@plt>
cmp    $0x0,%rax
je     11ea <set_charset+0x9a>
jmp    11f1 <set_charset+0xa1>
mov    $0x0,%al
call   1060 <ilocale@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_charset>:
push   %rax
lea    0xea8(%rip),%rdi
call   1070 <lgetenv@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <icharset@plt>
test   %rax,%rax
je     116e <set_charset+0x1e>
pop    %rax
ret
lea    0xe97(%rip),%rdi
call   1070 <lgetenv@plt>
test   %rax,%rax
je     118d <set_charset+0x3d>
cmpb   $0x0,(%rax)
je     118d <set_charset+0x3d>
mov    %rax,%rdi
pop    %rax
jmp    1030 <ichardef@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <nl_langinfo@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1040 <icharset@plt>
test   %rax,%rax
jne    116c <set_charset+0x1c>
xor    %eax,%eax
pop    %rcx
jmp    1060 <ilocale@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"LESSCHARSET\00"
@.str.1 = [12 x i8] c"LESSCHARDEF\00"
@CODESET = global i32 0
define void @set_charset() {
%1 = alloca i8*
%2 = call i8* @lgetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = call i64 @icharset(i8* %3, i32 0)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
br label %28
7: ; preds = %0
%8 = call i8* @lgetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i8*, i8** %1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %1
%18 = call i32 @ichardef(i8* %17)
br label %28
19: ; preds = %11, %7
%20 = load i32, i32* @CODESET
%21 = call i8* @nl_langinfo(i32 %20)
store i8* %21, i8** %1
%22 = load i8*, i8** %1
%23 = call i64 @icharset(i8* %22, i32 1)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %28
26: ; preds = %19
%27 = call i32 (...) @ilocale()
br label %28
28: ; preds = %26, %25, %16, %6
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"LESSCHARSET\00"
@.str.1 = [12 x i8] c"LESSCHARDEF\00"
@CODESET = global i32 0
define void @set_charset() {
%1 = tail call i8* @lgetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @icharset(i8* %1, i32 0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %19
4: ; preds = %0
%5 = tail call i8* @lgetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @ichardef(i8* %5)
br label %19
12: ; preds = %7, %4
%13 = load i32, i32* @CODESET
%14 = tail call i8* @nl_langinfo(i32 %13)
%15 = tail call i64 @icharset(i8* %14, i32 1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 (...) @ilocale()
br label %19
19: ; preds = %12, %0, %17, %10
ret void
}